We're currently running into a lot of bugs using timer1(and 2) especially with the softdevice enabled. Every so often it glitches, and after further inspection of the code, we notice that regardless of NRF_TIMER1->BITMODE = x; the bitmode doesn't change.
we use the following code.
void TIMER1_IRQHandler(){
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
NRF_TIMER1->CC[0] += 125; ///add an additional 125, so that it interrupts on the next 125 ticks
NRF_TIMER1->CC[0] = 75125;
if (NRF_TIMER1->CC[0] > 0xffff)
{
while(1);
}
///it should also roll over after reaching the 4billion mark in 9 hours
main_interrupt();
}
It will NEVER reach the infinite whileloop. and we initialize it like so
NRF_TIMER1->POWER = 1;
/// we want this function to be called every 1 ms
NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer << TIMER_MODE_MODE_Pos;
///8 bit timer
NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_08Bit << TIMER_BITMODE_BITMODE_Pos;
///16Mhz / 2 ^ 7 = 125000,
NRF_TIMER1->PRESCALER = 7;
///so to generate a 1Khz interrupt, we set compare register to 125
NRF_TIMER1->CC[0] = 125;
NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
///set as the highest priority
NVIC_SetPriority(TIMER1_IRQn, 0);
NVIC_EnableIRQ(TIMER1_IRQn);
nrf_delay_us(100);
If you notice that we even tried setting the bitmode to 8bit, and it still will count up to 16bit value before rolling over. We NEED a 32bit timer. Our current hardware is the nrf51822 QFAC A1