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

app_timer tick problem

I use sdk 12.3.0 / nrf51822 / SD_130. I use app_timer library.

  1. I want to know how to calculate the maximum allowed tick count when setting APP_TIMER_PRESCALER = 15 or other value.

#define WAKEUP_INTERVAL APP_TIMER_TICKS(???, APP_TIMER_PRESCALER)

  1. What happens when an interval that exceeds above allowable value is input to a timer ? I saw the system behave strangely.

thanks.

Parents
  • Hi air!

    The Real Time Counter (RTC) uses the low-frequency clock source (LFCLK, 32KHz). That means less resolution (~30us) and lower power consumption. The RTC features a 24 bit Counter and a 12 bit prescaler.

    The maximum tick count will be the same regarding what value you set the prescaler to. Because the RTC is a 24 bit counter, the max. tick count will be (2^24) = 16 777 216. And the max. prescaler value will be 4095.

    With the prescaler set to 15 you will accieve a period that is ~488us, and the RTC overflows after 136,5 min.

    Max value in miliseconds is something like:

    (2^24) * (APP_TIMER_PRESCALER+1) * 1000 / 32768 = 8 192 000ms = ~136,5 minutes.
    

    Period:

    8 192 000 / 16 192 216 = ~488 us
    

    Let say that you set the ms value in the APP_TIMER_TICKS(MS, APP_TIMER_PRESCALER) to be higher than the max allowed value, with a prescaler set to 15. If you put 9 000 sec to the timer, the number of ticks the timer will try to put into the compare register will then be:

    ((9 000 000 * 32768) / (15+1) *1000) = 18 432 000
    

    But since the maximum tick count for the RTC is (2^24) the timer will never hit the compare value, and the timer will not work.

    Hope this helps you understand. If you have any questions, please post a question in the comments below.

    Best regards,
    Joakim

Reply Children
No Data
Related