I'm using an ATSAM4E16C microcontroller and i need to get a 1 millisecond tick. I want to implement this using the timer counter module to trigger an interrupt. The clock frequency is 96 MHz, so using a prescaler of 128 and a compare of 750 i should get 1 millisecond. Problem is if i try to activate the interrupt, when the program reaches the delay_ms function if freezes (i think), and the debugger stops working (still connected)
void timer_init(void)
{
sysclk_enable_peripheral_clock(ID_TC0);
//init TC0 channel 0 with a prescaler of 128 and WAVEFORM
tc_init(TC0, 0, TC_CMR_TCCLKS_TIMER_CLOCK4
|TC_CMR_WAVE
|TC_CMR_WAVSEL_UP_RC);
tc_write_rc(TC0, 0, 750);
// trigger interrupt on RA compare
tc_enable_interrupt(TC0, 0, TC_IER_CPCS);
}
int main (void)
{
wdt_disable(WDT);
sysclk_init();
board_init();
irq_initialize_vectors();
cpu_irq_enable();
NVIC_DisableIRQ(TC0_IRQn);
NVIC_ClearPendingIRQ(TC0_IRQn);
NVIC_SetPriority(TC0_IRQn, 0);
NVIC_EnableIRQ(TC0_IRQn);
timer_init();
tc_start(TC0, 0);
delay_ms(10);
thermocouple_init(&thermocouple);
delay_ms(300);
thermocouple_read(&thermocouple);
set_led(true);
}
I've tried also with different interrupt priorities but still the same result. Any ideas as to why this doesn't work? Thanks