This blog is to introduce how to use the RTC as the stop watch to measure the timing.

On nRF52 Series MCU, it has difference number of timers, RTC as below.

nRF5281xnRF52832nRF52833nRF52840
3×32 bit
16MHz Timer
5×32 bit
16MHz Timer
5×32 bit
16MHz Timer
5×32 bit
16MHz Timer
2×32.768kHz
RTC
3×32.768kHz
RTC
3×32.768kHz
RTC
3×32.768kHz
RTC
Watchdog timer (32.768kHz) Watchdog timer (32.768kHz) Watchdog timer (32.768kHz) Watchdog timer (32.768kHz)

In the NRF52840 Product Specification, the current consumption of each RTC (internal RC or external oscillator) configuration is pretty small < 1uA.

RTC as the Stop Watch

Step 1 (including the nrfx_rtc.c and counter.c)

Step 2:

Enable the RTC inside the sdk_config.h

// <e> RTC_ENABLED - nrf_drv_rtc - RTC peripheral driver - legacy layer
//==========================================================
#ifndef RTC_ENABLED
#define RTC_ENABLED 1
#endif
// <o> RTC_DEFAULT_CONFIG_FREQUENCY - Frequency  <16-32768> 

// <q> RTC2_ENABLED  - Enable RTC2 instance
 

#ifndef RTC2_ENABLED
#define RTC2_ENABLED 1
#endif

Step 3:

include the header file “counter.h”

Step 4:

Initialize the counter module

Step 5:

Run the counter (start)

Step 6:

Stop the counter if finish. Get the tick and convert to corresponding time unit.