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

nRF51822 Long Time Timekeeping

I want to measure the time between some different events in my application (using SoftDevice S110). My idea is, to collect some timestamps and calculate the elapsed duration by just subtract them (like app_timer.c do).

But the problem is, that the nRF51822's Rtc0 and Rtc1 are limited to 24 bit, so I'm limited to a measurable duration of 511 seconds.

Possible solution: I could create a app_timer driven task which triggers on each Rtc overflow to emulate some more Rtc bits.

May there be a better solution?

  • Obviously you can use RTC prescaler and with maximum prescaler value 4095 you can measure time between some different events up to 582.542 hours. But with a loss in measurement precision (measurement resolution will be 125 ms). If your device will be in low power mode with only RTC running and you need maximum time measurement precision then your only option is to wake up on owerflow interrupt and increment some variable in interrupt handler. If your device will always have 16 MHz system clock (SysClk) source ON, you can connect RTC OVRFLW event with COUNT task of one of the free timers through PPI.

  • Ok, what's the way if one want to implement a real Rtc (with real time and date) on it's nRF51822 based device. Is there some support from the chip or Sdk libraries (or SoftDevice) or must that implemented selfmade (counting seconds, wakeup periodically if long sleeping, …)?

  • I haven't seen similar examples from the Nordic, but I have seen appnote about RTC implementation from Atmel with source code, which can be taken as an example. How to work with RTC you can find in Nordic SDK: nRF51 SDK_v5.2.0.39364\Nordic\nrf51822\Board\nrf6310\rtc_example

Related