Hello,
at the moment I am trying to implement a counter that increments every 1ms. I wrote the following code for this:
uint32_t counter = 0;
void init_sync_timer(void)
{
NRF_TIMER3->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER3->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
NRF_TIMER3->PRESCALER = 4;
NRF_TIMER3->CC[0] = 1000;
NRF_TIMER3->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
NVIC_EnableIRQ(TIMER3_IRQn);
NRF_TIMER3->TASKS_START = 1;
}
void TIMER3_IRQHandler(void)
{
if(NRF_TIMER3->EVENTS_COMPARE[0])
{
counter++;
NRF_TIMER3->EVENTS_COMPARE[0] = 0;
NRF_TIMER3->CC[0] += 1000;
}
}
int main(void)
{
...
init_sync_timer();
...
}
Regarding to the documentation (https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftimer.html) this should increment my variable "counter" every 1ms.
Unfortunately this is not the case. My variable "counter" increases every ~8.3ms.
So here are my questions:
1. Do I miss something here?
2. Can anybody tell me, how to fix this issue?
Thank you very much in advance.