CrossWorks AVR 2.0 - ATmega2560 - Timer0 does not work in simulator
Hey µC Friends, I was trying to port my Amega2560 code (in AVR Studio) to CrossWorks 2.0 AVR. But I already failed setting up Timer0.
I tested this code with the Avr Studio compiler and simulator, and I saw the TCNT0 counting:
TCNT0 = 0;
OCR0A = 249;
TIMSK0 = 0x02;
TCCR0A = 0x02;
TCCR0B= 0x01;
SREG |= 0x01;
But if I add that code to the initial CTL code of Crossworks 2.0 AVR (see below) and run the compilation in the simulator, I can NOT see that TCNT0 is counting
#include <string.h>
#include <ctl_api.h>
#include <ATmega2560.h>
CTL_TASK_t main_task, new_task;
#define CALLSTACKSIZE 16 // this is only required for AVR builds
#define STACKSIZE 64
unsigned new_task_stack[1+STACKSIZE+1];
void
new_task_code(void *p)
{
unsigned int v=0;
while (1)
{
// task logic goes here
v++;
}
}
void
ctl_handle_error(CTL_ERROR_CODE_t e)
{
while (1);
}
int main(void)
{
unsigned int v=0;
TCNT0 = 0;
OCR0A = 249;
TIMSK0 = 0x02;
TCCR0A = 0x02;
TCCR0B= 0x01;
SREG |= 0x01;
ctl_task_init(&main_task, 255, "main"); // create subsequent tasks whilst running at the highest priority.
ctl_start_timer(ctl_increment_tick_from_isr); // start the timer
memset(new_task_stack, 0xcd, sizeof(new_task_stack)); // write known values into the stack
new_task_stack[0]=new_task_stack[1+STACKSIZE]=0xfacefeed; // put marker values at the words before/after the stack
ctl_task_run(&new_task, 1, new_task_code, 0, "new_task", STACKSIZE, new_task_stack+1, CALLSTACKSIZE);
//ctl_task_set_priority(&main_task, 0); // drop to lowest priority to start created tasks running.
while (1)
{
// power down can go here if supported
v++;
}
return 0;
}
I really don't know what's wrong and would be glad if someone has a solution/hint for that.
Thank you!
Peter
Please sign in to leave a comment.
Comments
2 comments