How to use the RTC timer as the Stop Watch at Nordic nRF5 SDK

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.

One thought on “How to use the RTC timer as the Stop Watch at Nordic nRF5 SDK

  1. Thanks for your marvelous posting! I genuinely enjoyed reading it, you could be a great author.I will be sure to bookmark your blog and may come back someday. I want to encourage you to continue your great job, have a nice morning!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.