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

Usage of RTC0 as time basis (system time) possible?

Hello everybody,

RTC0 is used by the SoftDevice. Is it possible to use the current RTC0 counter value as a system time, so that RTC1 doesn't have to run additionally? For this purpose, RTC0 would have to run continuously.

My goal is to save timestamps for certain events (e.g. a interrupt through a GPIO pin, or a BLE event) and measure time difference between these events.

This is why I need to know if the RTC0 counter value can be accessed without any problem, and if the RTC0 may be stopped/disabled at any time after the SoftDevice has been enabled (using SOFTDEVICE_HANDLER_INIT()):

  • Is RTC0 disabled on S110 when there is no advertising and no connection in progress (so the stack is completely idle)?

  • Is RTC0 disabled on S120 when there is no scanning and no connection in progress (so the stack is completely idle)?

  • Is the RTC0 counter value reset at any time? E.g. when switching from Advertising mode to Connection mode, or restarting Advertising with a different interval.

One more question regarding energy consumption: Will there be a different sleep energy consumption with the S110 stack whether advertising/connection is active or the SoftDevice is idle? Sleep mode is entered with sd_app_evt_wait() in both cases. This question is related to my concern that RTC0 might be switched off when the SoftDevice is idle. (We intend to measure the sleep energy consumption without any wakeup because the measurement resolution would be too low otherwise.)

  • Hi

    When the softdevice is enabled, the RTC0 is blocked, so you would need to disable the softdevice to use the RTC0. Many of the nRF51 SDK BLE example use app_timer library which uses RTC1 in the background, so if you have app_timer enabled, you can not use RTC1 either.

    The current consumption is ~0.1uA for the RTC so it is relatively very low current consumption. So there is practically no current cost of using the RTC1, if that is your concern.

    Most of the current consumption is during radio events. The largest factors are radio RX ~13mA, radio TX ~10.5mA, CPU ~4.1mA. The softdevice conumes ~3.1uA when idle and enabled. Usually, advertising is more current consuming than being in a connection. More on current connection on this thread.

    Putting the chip into System On sleep mode is actually just disabling the CPU. Putting the chip into System Off sleep mode is actually just disabling the CPU and all nRF51 peripherals.

    Update 27.1.2015 RTC0 is listed as "blocked" in the SDS. That means that it is in use by the SoftDevice when the SoftDevice is enabled, and the application should not assume anything about the state of this peripheral.

  • Hi Stefan,

    there might be a misunderstanding in your interpretation of my question. I do NOT intend to do any write operations to RTC0, neither change its configuration that was made by the SoftDevice. All I want to do is use it as a constantly running counter (I am also aware that there will be an overflow every 512 seconds).

    Accessing RTC0 is not a problem: I can read NRF_RTC0->COUNTER anytime, from within on_ble_evt() for example. That's all I need to do.

    My question is: Is there any situation when this counter is stopped or manually reset/written by the SoftDevice? Or can I use it as a reliable time reference?

  • Even if currently RTC0 ran constantly, never stopped and was never reset and you could read it as you suggest, basing your application on that would be a very bad idea. The softdevice implementation could change at any time, in any way, to run, not run, reset the counter etc. as part of Nordic's softdevice evolution.

    You should treat the resources which are documented as used by the softdevice as unavailable for any purpose unless there's an exposed user API point or a documented exception.

  • Okay, I think your update makes it clear: Even if it seems to work at the moment, it's against the specification and there is no guarantee that it will work in a reliable manner. Thanks!

  • Hi puz_md,

    i have the some problem. I'm thinking to use a RTC2, even if RTC0 or RTC1.

    What do you think about that?

    Thanks, Anna

Related