Hi,
I am using pca10040 board. i need to toggle a led in 5sec once. I tried to change the prescale value. But im not able to get that much time delay.
Can any one help me on this?
Have you tried using app_timer? It uses the RTC which will give you overflow at 512 seconds with prescaler 0. The RTC is also much more power efficient than using TIMER. See here for a tutorial on how to use it. You can also use the RTC directly, but be aware that RTC0 is used by SoftDevice and RTC1 is used by app_timer.
Hi Ole Bauck,
If i set prescale value 9 and bitmode is 32 means. The counting will be start in 0 to 4,294,967,296. For 5 second delay i set cc[0]=156250. For my requirement i need continuously toggle a led for 5 mins. At very first time its coming in 5 second [0 - 156250] but after that its taking more time [156270 - 4,294,967,296] I dont kw how to do that..
can u guide me on thz.. below is my function:
void start_timer(void)
{
NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER2->TASKS_CLEAR = 1;
NRF_TIMER2->PRESCALER = 9;
NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
NRF_TIMER2->CC[0] = 156250;
NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos) ;
NVIC_EnableIRQ(TIMER2_IRQn);
NRF_TIMER2->TASKS_START = 1;
}
void TIMER2_IRQHandler(void)
{
if ((NRF_TIMER2->EVENTS_COMPARE[0] != 0))
{
NRF_TIMER2->EVENTS_COMPARE[0] = 0;
NRF_TIMER2->CC[0] += 156250;
nrf_gpio_pin_toggle(GPIO_TOGGLE_PIN);
}
}
You can use shorts:
NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
This will clear the timer counter value on CC[0] compare. If not doing this the timer will count to the maximum value before it overflows.