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

Clocks, timers, RTC, why?

I am developing software for the nRF52. As recommended by many recent posts here in the Developer Zone, I have upgraded to SDK 11. I am working on an application for a battery-powered device which will repeat the following cycle:

  1. Sleep, for one to 10 minutes.

  2. On waking, conduct six well-timed operations, about 0.1 seconds apart. These operations will include sampling the SAADC and acting as an I2C master to communicate with a peripheral.

  3. Communicate the results of the operations in step 2. At first I will send this information to the UART, but eventually I want to transmit over BLE.

Obviously, I don't want to use a busy-wait when the CPU will be idle for 10 minutes. But there seem to be three different ways to implement hardware timers. If I look at an nrf_config_drv.h file, I see flags for CLOCK_ENABLED, TIMER0_ENABLED through TIMER4_ENABLED, and finally, RTC0_ENABLED through RTC3_ENABLED.

The tutorials (which only cover SDK 10) and example code are not helping me to understand the different types of timers, or how to choose between them. Can someone please summarize the reasons for the existence of these various approaches to timing? Thanks.

Parents
  • The main difference between TIMER and RTC (Real-time counter) is that:

    • TIMER uses the high-frequency clock source (HFCLK, 16 MHz), which means better resolution (62.5 ns) and higher power consumption (typ. 5 or 70 uA depending on HFCLK source).
    • RTC uses the low-frequency clock source (LFCLK, 32 KHz), which means less resolution (~30 us) and lower power consumption (typ. 0.1 uA).

    For the details, see chapters 24 (TIMER -- Timer/counter) and 25 (RTC -- Real-time counter) of the nRF52832 Product Specification.

    For RTC there is also a library in the SDK: Timer library

    Based on what you write about your application I would suggest using RTC.

    CLOCK_ENABLED is for enabling the clock driver in the SDK. This is not a timer. Rather it is a driver for handling the low and high frequency clock sources.

  • For RTC, the rate at which the counter ticks is configured using the 12 bit PRESCALER register.

    The timer ticks every PRESCALER + 1 tick of the LFCLK (@32768 Hz). With the maximum PRESCALER setting of 4095, the RTC gets a period of 125 ms and overflows after 582.542 hours.

    I have fixed the broken link to the documentation for "RTC -- Real-time counter" in the answer above.

Reply
  • For RTC, the rate at which the counter ticks is configured using the 12 bit PRESCALER register.

    The timer ticks every PRESCALER + 1 tick of the LFCLK (@32768 Hz). With the maximum PRESCALER setting of 4095, the RTC gets a period of 125 ms and overflows after 582.542 hours.

    I have fixed the broken link to the documentation for "RTC -- Real-time counter" in the answer above.

Children
No Data
Related