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

Decrease the timer resolution of SDK 14

How can we decrease the resolution of the timer to 500 ms in SDK 14? The minimum resolution I could get to was 1 ms by changing the APP_TIMER_CONFIG_RTC_FREQUENCY macro to 31. 

Thanks

Atul

  • Hi Atul,

    I believe this link will be helpful for you. Since you want a resolution of 500 ms, this is the same as 1/.5 s = 2 Hz. Therefore f_RTC = 2Hz.

    Solving for the equation gives you a prescaler value of:

    PRESCALER = round(32768 Hz/ 2 Hz) - 1 = 16383.

  • Hi Bjorn

    I knew it already that I have to change the PRESCALER to get the resolution I want. But, I am working with SDk 14.2 and I found that they have removed the PRESCALER argument from the APP_TIMER_TICKS function which was threre in SDK 13. The details can be found here

    Thus, I need to know the code or any command which will change the PRESCALER value. As far as I searched, I can only find that I need to change the APP_TIMER_CONFIG_RTC_FREQUENCY macro present in sdk_config.h file and that too it's maximum value was 31. If I change it to 16383, my device stops advertising. 

    Atul

  • The RTC peripheral has a 12 bit prescaler. So the max value for prescaler will be (2^12) - 1 = 4095. This will give you a counter resolution of 125 ms with an overflow of 582.542 hours.

    If you want the l̶o̶w̶e̶s̶t̶ highest counter resolution, you can set the prescaler (APP_TIMER_CONFIG_RTC_FREQUENCY) to 0. This will give you a counter resolution of 30.517 us and an overflow of 512 seconds.

  • 16383 will not work as the prescaler is only 12 bits!

  • The counter resolution of 30.517 us is the highest resolution right, not the lowest one. 

    Is there any way in which I can get a resolution of 500 ms? And even if I make do with the 125 ms resolution, where should I change the PRESCALER register? I didn't see any such command in the documentation of SDK 14. I could change the APP_TIMER_CONFIG_RTC_FREQUENCY macro, but in the description, there are some values provided to us, and I suppose, only those can be used as the possible values of the macro. I am attaching the code from the sdk_config file. 

    // <o> APP_TIMER_CONFIG_RTC_FREQUENCY  - Configure RTC prescaler.
     
    // <0=> 32768 Hz 
    // <1=> 16384 Hz 
    // <3=> 8192 Hz 
    // <7=> 4096 Hz 
    // <15=> 2048 Hz 
    // <31=> 1024 Hz 
    
    #ifndef APP_TIMER_CONFIG_RTC_FREQUENCY
    #define APP_TIMER_CONFIG_RTC_FREQUENCY 31        
    #endif
    

Related