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

Question about high resolution timer

Hi,

I'd like to get a timer with 1ms interval or higher resolution, and found some questions about this:

  1. If the app_timer is used, looks like we only can get minimum interval 5ms. With the less interval, it causes the system crashed and reboot. BTW, to use the 5ms interval, I updated the example macro MS_TO_TICK to below:

    #define MS_TO_TICK(MS) ((TICKS_PER_100MS * MS) / 100)

Is 5ms as the resolution for app_timer expected? If it's using 32K RTC as the clock source, I suppose the resolution should be much higher, right?

  1. I turned to solution with the timer in TIMER mode as the example suggested, but observed some confusing issues:

For easier usage, I referred the code of app_timer to define below macros:

#define ROUNDED_DIV(A, B) (((A) + ((B) / 2)) / (B))
#define TIMER_PRESCALER                 6
#define TIMER_FREQUENCY                 (256 * 1024)   /* 16M / exp(2, PRESCALER) */
#define TIMER_TICKS_PER_MS              ROUNDED_DIV(TIMER_FREQUENCY, 1000)
#define TIMER_MS_TO_TICK(MS)            (TIMER_TICKS_PER_MS * MS)

and set CC as below:

NRF_TIMER2->CC[0] = TIMER_MS_TO_TICK(100);

But from the logs I added in timer handler, this setting gets 25ms interval instead of 100ms. What am I missing for this setting?

Another issue about timer is that whatever I set for BITMODE, 16 bit or 32 bit, the max CC value is always (64K - 1). If this is true, it will limit the max interval I'm trying to set. Could you please confirm this?

Thanks & Regards, Stanley

Related