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

"Best method" for avoiding overflow of app_timer

I will use the functions in app_timer to set a timer to fire every 3 seconds. I want this to occur "forever" (e.g.until a restart of the nRF51).

To avoid a timer overflow, is it a better practice to set the PRESCALAR to 0 and clear the timer after each interrupt, or set the PRESCALAR to a higher value and check within the interrupt for a near overflow and clear the timer at that point? If one is better than the other - why is that so?

(thank you)

Parents
  • With prescaler 0, app_timer can have best counter resolution and can count upto 512 seconds(before it overflows). So if your application can keep PRESCALER 0 and clear the timer with the hardware SHORT when it reaches the value in CC (as this has no dependency on interrupt priority or softdevice or anythings else, this is guarenteed to happen with a predictable maximum of one tick latency), then it is the best solution. Ofcourse the second best is to clear the timer when the CC interrupt occurs (which depends on interrupt priority and softdevice state. The latency here is unpredictable).

    EDIT

    [deleted content]

Reply
  • With prescaler 0, app_timer can have best counter resolution and can count upto 512 seconds(before it overflows). So if your application can keep PRESCALER 0 and clear the timer with the hardware SHORT when it reaches the value in CC (as this has no dependency on interrupt priority or softdevice or anythings else, this is guarenteed to happen with a predictable maximum of one tick latency), then it is the best solution. Ofcourse the second best is to clear the timer when the CC interrupt occurs (which depends on interrupt priority and softdevice state. The latency here is unpredictable).

    EDIT

    [deleted content]

Children
Related