I have been working on making at least 1us Timer interval(expect faster than 1MHz) using interrupt.
To do this we need to set the prescaler of Timer to 4, since formula of making Timer Tick is TimerTick = 16MHz / 2^prescaler.
or set the cc to 16 and precaler to 0 on the Timer, since 1 tick time of 16Mhz is (1/16)us.
I thought it should be simple to implement. However the generated clock speed was not exact what I expected. The maximum interrupt interval I got was less than 200kHz
In addition, I tried on slow interval rate (such as 125kHz or slower). However the interrupt time was not exact time I expected. The interrupt time was delayed as follows of I added more source code.
void TIMER0_IRQHandler()
{
if (NRF_TIMER0->EVENTS_COMPARE[0] != 0)
{
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
NRF_TIMER0->TASKS_CLEAR = 1;
nrf_gpio_pin_toggle(GPIO_TOGGLE_PIN);
}
}
void timer0_config(void)
{
// Start 32 MHz crystal oscillator
NRF_TIMER0->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER0->PRESCALER = 0U;
NRF_TIMER0->BITMODE = TIMER_BITMODE_BITMODE_16Bit; // 16 bit mode.
NRF_TIMER0->TASKS_CLEAR = 1; // clear the task first to be usable for later.
NRF_TIMER0->CC[0] = 16;
NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Enabled
<< TIMER_INTENSET_COMPARE0_Pos;
NVIC_EnableIRQ(TIMER0_IRQn); // Enable Interrupt for the Timer in the core.
}
I don't get which part of modification to generate high frequency interrupt.