I’m working with the ATMega128 which is based on the ATMEGA323. I’ve found some items that need to be tweaked to get the demo to run. Here are the changes I had to make. Some of these are already documented but I’m including them here for completeness. Also, I’m using WinAVR. I am running my serial at 115200 baud without issue now.
Richard, it’s generic. I can’t say I’ve tested it on anything other than the 128, but I got it from Pascal Stang’s AVRLib library and he says his code can be used on:
# MCU = at90s8515
# MCU = atmega163
# MCU = atmega323
# MCU = atmega161
# MCU = atmega128
gives you a rounded off (int) number of clock ticks based on the configTICK_RATE_HZ value in the config file. In my case, I wanted to specify the Hz my task would need to run at (i.e. 50Hz, 20Hz).
#define motorPIDFrequency ( ( portTickType ) 50 / configTICK_RATE_HZ ) // 50hz or 20ms
…
vTaskDelayUntil( &xLastWakeTime, motorPIDFrequency ); // wait for the next cycle
So that instead of thinking in ms for my vTaskDelayUntil, I can use the required Hz. Either way, the system converts to an (int) so there will be some "error" depending on you choice of configTICK_RATE_HZ. You want simple, chose 1000 or 1 tick every 1ms … but per the API, this is excessive for most applications.
/* Setup compare match value for compare match A. Interrupts are disabled
before this is called so we need not worry here. */
ucLowByte = ( unsigned portCHAR ) ( ulCompareMatch & ( unsigned portLONG ) 0xff );
ulCompareMatch >>= 8;
ucHighByte = ( unsigned portCHAR ) ( ulCompareMatch & ( unsigned portLONG ) 0xff );
/* Setup clock source and compare match behaviour. */
ucLowByte = portCLEAR_COUNTER_ON_MATCH | portPRESCALE_64;
TCCR1B = ucLowByte;
/* Enable the interrupt - this is okay as interrupt are currently globally
disabled. */
ucLowByte = TIMSK;
ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE;
TIMSK2 = ucLowByte;
/*#endif(__AVR_ATmegaXXX__)*/ #elif defined (__AVR_AT90CAN128__) #define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( unsigned portCHAR ) 0x02 )
OCR1AH = ucHighByte;
OCR1AL = ucLowByte;
/* Setup clock source and compare match behaviour. */
ucLowByte = portCLEAR_COUNTER_ON_MATCH | portPRESCALE_64;
TCCR1B = ucLowByte;
/* Enable the interrupt - this is okay as interrupt are currently globally
disabled. */
ucLowByte = TIMSK1;
ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE;
TIMSK1 = ucLowByte; #else
# if !defined(__COMPILING_AVR_LIBC__)
# warning "device type not defined"
# endif #endif
}