[En-Nut-Discussion] ethernut 1.3 pwm channels / ethernet conflict

Alex Joni alex.joni at robcon.ro
Thu Aug 17 08:47:50 CEST 2006


I suspect you have the same problem I had.
You are using the PE5 pin which is also INT5.
INT5 is the interrupt from the network controller, so you can't use 
them both at once.

Regards,
Alex

----- Original Message ----- 
From: "Raul Valle" <rvl180 at hotmail.com>
To: <en-nut-discussion at egnite.de>
Sent: Wednesday, August 16, 2006 4:49 AM
Subject: [En-Nut-Discussion] ethernut 1.3 pwm channels / ethernet 
conflict


hi can someone tell me why is it that after programming my card with 
all the pwm channels available  they only work while the card is 
receiving data from the computer????....... Only when the green light 
in the board is on the pwms work , but meanwhile the green led is off 
it does not do anything ...
code:
====================================

#include <cfg/os.h>
#include <string.h>
#include <stdio.h>
#include <io.h>

#include <dev/board.h>

#include <sys/version.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/socket.h>

#include <arpa/inet.h>
#include <pro/dhcp.h>

#ifdef NUTDEBUG
#include <sys/osdebug.h>
#include <net/netdebug.h>
#endif

#include <sys/confnet.h>

static char buff[128];
//==========================================================================
#include <ctype.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
//#include <avr/signal.h>

#include <sys/confnet.h>


#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define SERVO1   OCR3A
#define SERVO2   OCR3B
#define SERVO3   OCR3C
#define SERVO4   OCR1A
#define SERVO5   OCR1B
#define SERVO6   OCR1C

#define SERVO_MIN 2000
#define SERVO_MID 3000
#define SERVO_MAX 4000

#define SERVO_CLIP(x) (x<SERVO_MIN ? SERVO_MIN : (x>SERVO_MAX ? 
SERVO_MAX : x))

#define OFFSET(x) (SERVO_CLIP(SERVO_MID + x))
static u_char mac[]= {0x00,0x06,0x98,0x01,0x01,0x43};
static char buff[128];


/* SIG_OVERFLOW3 - this interrupt handler starts the pulse for servos
 * 1, 2, & 3; the timer 3 output compare function automatically ends
 * the pulse precisely as specified by the OCR3x register which
 * represents the servo position */
SIGNAL(SIG_OVERFLOW3)
{
  TCNT3   = 0;

  /* configure to set outputs on compare match so we can turn on the
   * pulse in the next statement */
  TCCR3A |= 
_BV(COM3A1)|_BV(COM3A0)|_BV(COM3B1)|_BV(COM3B0)|_BV(COM3C1)|_BV(COM3C0);

  /* force compare match to set outputs */
  TCCR3C |= _BV(FOC3A)|_BV(FOC3B)|_BV(FOC3C);

  /* configure to clear outputs on compare match so that the output
   * compare function ends the pulse */
  TCCR3A &= ~(_BV(COM3A0)|_BV(COM3B0)|_BV(COM3C0));
}


/* SIG_OVERFLOW1 - this interrupt handler starts the pulse for servos
 * 4, 5, & 6; the timer 1 output compare function automatically ends
 * the pulse precisely as specified by the OCR1x register which
 * represents the servo position */
SIGNAL(SIG_OVERFLOW1)
{
  TCNT1 = 0;

  /* configure to set outputs on compare match so we can turn on the
   * pulse in the next statement */
  TCCR1A |= 
_BV(COM1A1)|_BV(COM1A0)|_BV(COM1B1)|_BV(COM1B0)|_BV(COM1C1)|_BV(COM1C0);

  /* force compare match to set outputs */
  TCCR1C |= _BV(FOC1A)|_BV(FOC1B)|_BV(FOC1C);

  /* configure to clear outputs on compare match so that the output
   * compare function ends the pulse */
  TCCR1A &= ~(_BV(COM1A0)|_BV(COM1B0)|_BV(COM1C0));
}


void servo(int16_t s1, int16_t s2, int16_t s3, int16_t s4, int16_t s5, 
int16_t s6)
{
  SERVO1 = OFFSET(s1);
  SERVO2 = OFFSET(s2);
  SERVO3 = OFFSET(s3);
  SERVO4 = OFFSET(s4);
  SERVO5 = OFFSET(s5);
  SERVO6 = OFFSET(s6);
}


void init_servos(void)
{
  /* Use Timers 1 and 3 to generate the pulses for 6 R/C servos; each
   * timer can do up to 3 servos. */

  /*
   * configure OC3A for mode 0: normal, top=0xffff prescale=8 (f~=30):
   *
   * WGM33=0, WGM23=0, WGM13=0, WGM03=0, CS32=0, CS31=1, CS30=0
   */
  DDRE   |= _BV(PORTE3) | _BV(PORTE4) | _BV(PORTE5);
  TCCR3A &= ~(_BV(WGM31) | _BV(WGM30) | _BV(COM3A1) | _BV(COM3B1) | 
_BV(COM3C1));
  TCCR3A |= _BV(COM3A0) | _BV(COM3B0) | _BV(COM3C0);
  TCCR3B &= ~(_BV(WGM33) | _BV(WGM32) | _BV(CS32) | _BV(CS30));
  TCCR3B |= _BV(CS31);
  TCNT3   = 0;
  TCCR3C |= _BV(FOC3A) | _BV(FOC3B) | _BV(FOC3C);
  ETIMSK |= _BV(TOIE3);

  /*
   * configure OC1A for mode 0: normal, top=0xffff prescale=8 (f~=30):
   *
   * WGM33=0, WGM23=0, WGM13=0, WGM03=0, CS32=0, CS31=1, CS30=0
   */
  DDRB   |= _BV(PORTB5) | _BV(PORTB6) | _BV(PORTB7);
  TCCR1A &= ~(_BV(WGM11) | _BV(WGM10) | _BV(COM1A1) | _BV(COM1B1) | 
_BV(COM1C1));
  TCCR1A |= _BV(COM1A0) | _BV(COM1B0) | _BV(COM1C0);
  TCCR1B &= ~(_BV(WGM13) | _BV(WGM12) | _BV(CS12) | _BV(CS10));
  TCCR1B |= _BV(CS11);
  TCNT1   = 0;
  TCCR1C |= _BV(FOC1A) | _BV(FOC1B) | _BV(FOC1C);
  TIMSK  |= _BV(TOIE1);

  /* set all servos to their center positions */
  SERVO1 = 2000;
  SERVO2 = 4000;
  SERVO3 = 1000;
  SERVO4 = SERVO_MID;
  SERVO5 = SERVO_MID;
  SERVO6 = SERVO_MID;
}

//====================================================================================





/*
 * To save RAM, we store large strings in program space. With AVRGCC 
we
 * would be able to use the PSTR() macro and put the text directly in
 * the statement that uses it. But ICCAVR doesn't support anything 
like
 * this. Sigh.
 */
#if defined(__IMAGECRAFT__)
#define CC_STRING   "ICCAVR"
#elif defined(__GNUC__)
#define CC_STRING   "AVRGCC"
#else
#define CC_STRING   "Compiler unknown"
#endif

prog_char vbanner_P[] = "\n\nTCP Server Sample - Nut/OS %s - " 
CC_STRING "\n";
prog_char banner_P[] = "200 Welcome to tcps. Type help to get 
help.\r\n";


/*
 * Process client requests.
 */
void ProcessRequests(FILE * stream)
{
    int val;
    int got;
    char *cp;

    /*
     * Send a welcome banner.
     */
    fputs_P(banner_P, stream);
    fputs("Online", stream);
    for (;;) {

        /*
         * Flush output and read a line.
         */
        fflush(stream);
        if (fgets(buff, 2, stream) == 0)
            break;

        /*
         * Chop off EOL.
         */
        if ((cp = strchr(buff, '\r')) != 0)
            *cp = 0;
        if ((cp = strchr(buff, '\n')) != 0)
            *cp = 0;

        /*
         * Ignore blank lines.
         */
        got = strlen(buff);
        if (got == 0)
            continue;

        /*
         * Manual Mode
         */
        if (strncmp(strchr(buff,'M'),"M",1)==0) {
           fputs("Manual",stream);


            continue;
        }

        /*
         * Auto Mode
         */
        if (strncmp(strchr(buff,'A'),"A",1)==0) {
           fputs("Auto",stream);
            continue;
        }

        /*
         * List timers.
         */
        if (strncmp("timers", buff, got) == 0) {

            continue;
        }

        /*
         * Quit connection.
         */
        if (strncmp("quit", buff, got) == 0) {
            break;
        }

    }
}

/*
 * Main application routine.
 *
 * Nut/OS automatically calls this entry after initialization.
 */
int main(void)
{
    TCPSOCKET *sock;
    FILE *stream;
    u_char mac[6] = { 0x00, 0x06, 0x98, 0x01, 0x01, 0x43 };

init_servos();


    /*
     * Register all devices used in our application.
     */
    NutRegisterDevice(&DEV_DEBUG, 0, 0);
    NutRegisterDevice(&DEV_ETHER, 0x8300, 5);

    /*
     * Assign stdout to the UART device.
     */

#ifdef NUTDEBUG
    NutTraceTcp(stdout, 1);
    NutTraceOs(stdout, 0);
    NutTraceHeap(stdout, 0);
    NutTracePPP(stdout, 0);
#endif

    NutNetLoadConfig(DEV_ETHER_NAME);
    memcpy(confnet.cdn_mac, mac, 6);
    NutNetSaveConfig();


            u_long ip_addr = inet_addr("192.168.171.1");
            u_long ip_mask = inet_addr("255.255.255.0");
            NutNetIfConfig("eth0", mac, ip_addr, ip_mask);


    for (;;) {
        /*
         * Create a socket.
         */
        if ((sock = NutTcpCreateSocket()) != 0) {
            /*
             * Listen on port 23. If we return, we got a client.
             */
            if (NutTcpAccept(sock, 23) == 0) {

                /*
                 * Open a stream and associate it with the socket, so
                 * we can use standard I/O. Note, that socket streams
                 * currently do support text mode.
                 */
                if ((stream = _fdopen((int) sock, "r+b")) != 0) {
                    /*
                     * Process client requests.
                     */
                    ProcessRequests(stream);

                    /*
                     * Close the stream.
                     */
                    fclose(stream);
                } else;

            } else;

            /*
             * Close our socket.
             */
            NutTcpCloseSocket(sock);
        }
    }
}
================
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion




-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.10.10/419 - Release Date: 
15.8.2006




More information about the En-Nut-Discussion mailing list