Hi everyone I am using Due's timer interrupt to call a routine periodically, the code fragment is bellow. I use "ticks" variable to calculate timer's period to call a routine. The code is working very well, the problem is that it isn't very precise. For example if I set period to 200 milliseconds, I get 193.7, it is worse for smallest periods, if I set 10 milliseconds I get only 5.6. I need microseconds precision in my code. I tried all the timers divisors, currently I am using 128, and all the nine timers and the problem persist. Anyone can say why this is so imprecise and how to improve it? Thanks in advance.
pmc_set_writeprotect(false); // disable write protection for pmc registers pmc_enable_periph_clk(ID_TC7); // enable peripheral clock TC7 TC_Configure(TC2,1, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4); //Division by 128 TC_SetRC(TC2, 1, ticks); //ticks = (84MHz/128) * period TC_Start(TC2, 1); // enable timer interrupts on the timer TC2->TC_CHANNEL.TC_IER=TC_IER_CPCS; // IER = interrupt enable register TC2->TC_CHANNEL.TC_IDR=~TC_IER_CPCS; // IDR = interrupt disable register /* Enable the interrupt in the nested vector interrupt controller */ NVIC_EnableIRQ(TC7_IRQn);;