This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Timer 1 has no Different resolution

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

Parents
  • Sorry this is posting on an old post and I'm aware its probably not applicable for you anymore, but for reference ...

    I have had similar issues with the documentation seeming vague with regards to this. As is kind of mentioned in RK's answer, the Reference Manual gives all the options for the device range, whereas the specifics of the exact chip you have are in the Product Specification document for your exact device.

    In my case for the nrf51822, the reference manual (nRF51_RM_v3.0.pdf) says all the stuff about the timers being 8/16/32 bit. However the Product Specification (nRF51822_PS_v3.1.pdf) then says TIMER1/2 are 8/16 bit only (section 4.2).

Reply
  • Sorry this is posting on an old post and I'm aware its probably not applicable for you anymore, but for reference ...

    I have had similar issues with the documentation seeming vague with regards to this. As is kind of mentioned in RK's answer, the Reference Manual gives all the options for the device range, whereas the specifics of the exact chip you have are in the Product Specification document for your exact device.

    In my case for the nrf51822, the reference manual (nRF51_RM_v3.0.pdf) says all the stuff about the timers being 8/16/32 bit. However the Product Specification (nRF51822_PS_v3.1.pdf) then says TIMER1/2 are 8/16 bit only (section 4.2).

Children
No Data
Related