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

Parents
  • Hi Stanley,

    Timer1 and Timer2 only support 16bit and these are the only timers accessable by applications when using softdevice.

    Only Timer0 has 32/24/16 bit mode and its access is restricted when using the softdevice. For details on which bitmodes are supporting which timers see the device product specification.

    Timer0 can be used by apps in a restricted way when using Multiprotocol Timeslot API

Reply
  • Hi Stanley,

    Timer1 and Timer2 only support 16bit and these are the only timers accessable by applications when using softdevice.

    Only Timer0 has 32/24/16 bit mode and its access is restricted when using the softdevice. For details on which bitmodes are supporting which timers see the device product specification.

    Timer0 can be used by apps in a restricted way when using Multiprotocol Timeslot API

Children
Related