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

Microseconds timer using RTC

Hi everyone,

I need to set up a timer using the RTC. The default function that converts ms to ticks APP_TIMER_TICKS() accepts only milliseconds. So, I wrote my own conversion function as below

#define APP_TIMER_TICKS_US(US)               \
  ((uint32_t)ROUNDED_DIV(                    \
      (US) * (uint64_t)APP_TIMER_CLOCK_FREQ, \
      1000000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1)))

and now I can set up a timer in microseconds like this:

#define SAADC_INTERVAL APP_TIMER_TICKS_US(200)

My questions are:

1. Is this approach correct?

2. RTC running on 32768Hz meaning that the resolution is ~30us. Does this mean that I can set up a timer down to 30us? For example

#define SAADC_INTERVAL APP_TIMER_TICKS_US(30)

Thanks in advance

Nick

Related