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

Best Way to Keep Track of Time with the nRF52

I need to keep track of time on a device featuring the nRF52 and have an RTC run continuously in the background. The drift should not be more than a few seconds over a year. Is this possible to achieve with a moderate power consumption?

I am a bit overwhelmed with the number of of ways to keep track of time in the SDK:

  • app_timer*
  • Also, the changes to app_timer posted in this forum by Clem Taylor. This dates back to 2015, though and targets the nRF51?
  • app_simple_timer*
  • nrf_drv_timer*
  • nrf_drv_rtc*
  • nrf_drv_clock*

Is there anything that comprehensively explains the difference between these? Also, what should my approach be to get a system clock with as little time drift as possible?

Parents
  • Hi,

    The clock control system is basically the system that drives the whole chip, including the CPU and all peripherals. It can be divided into 2 clock systems, the low frequency clock(LFCLK) and the high frequency clock (HFCLK) . With nrf_drv_clock* you have several ways to interact with the clocks, including initialization and calibrating.


    The nrf_drv_rtc* includes drivers for the Real-time counter (RTC) peripheral.

    The nrf_drv_timer* includes drivers for the TIMER peripheral.

    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).

    The app_timer* and app_simple_timer* are libraries that builds on top the RTC1 peripheral(app_timer) and the TIMER1 peripheral(app_simple_timer). This gives more high-level functionality where you can create multiple timer instances, and you have functions to start and stop the timers. Take a look at the Application Timer Tutorial if you want to learn more.


    For keeping track of time on the nRF52, I would recommend taking a look at the nrf-calendar-example we have on Github.

Reply
  • Hi,

    The clock control system is basically the system that drives the whole chip, including the CPU and all peripherals. It can be divided into 2 clock systems, the low frequency clock(LFCLK) and the high frequency clock (HFCLK) . With nrf_drv_clock* you have several ways to interact with the clocks, including initialization and calibrating.


    The nrf_drv_rtc* includes drivers for the Real-time counter (RTC) peripheral.

    The nrf_drv_timer* includes drivers for the TIMER peripheral.

    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).

    The app_timer* and app_simple_timer* are libraries that builds on top the RTC1 peripheral(app_timer) and the TIMER1 peripheral(app_simple_timer). This gives more high-level functionality where you can create multiple timer instances, and you have functions to start and stop the timers. Take a look at the Application Timer Tutorial if you want to learn more.


    For keeping track of time on the nRF52, I would recommend taking a look at the nrf-calendar-example we have on Github.

Children
Related