How to RTC with Nordic and Zephyr

I am using an NRF52840 custom board with a high quality crystal on the low frequency clock. 

I see that to configure this I should specify the following in the .conf file:

CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y

My question is simply, "What is the best way to query the value of this clock". Seems a simple question, but looking at the
documentation and this forum, there is just a mind-boggling number of possible answers given.

Here are the possibilites I have come up with so far:

1)
k_uptime_get(); Does this actually query this clock, or is it using the program counter's clock?

2)
k_uptime_ticks();


3)
CONFIG_COUNTER
=y in .conf, and
counter_start(); followed by
counter_get_value();

4)
From the samples/subsys/logging/logger, though its really unclear where NRF_RTC1 comes from.
NRF_RTC1->COUNTER;

5)
nrfx_rtc_counter_get(); // from nrfx_rtc.h

6)
z_nrf_rtc_timer_read(); // from the timer tests


Questions:

Which of these actually are based on the LFCLK?
Which are recommended?
Which of these are best for low power consumption?
Which of these will continue to count if the SOC is put in a low-power mode?
What if the main thread is put to sleep waiting on an interrupt, will it keep counting?
How does the following effect the recommended call, if at all?
- Using an app timer
- Using a watchdog timer
- Using BLE
- Using MPSL





Parents
  • Hi

    1. All of the above (kernel functions, RTC, and counter) use the LF clock as the source here I believe, and can be used for different things depending on what you want to do. 

    2. If your goal is to just see the value of the clock, I would think the k_uptime_get(); function is best suited which just lets you get the time of how long the LF clock has been up and running.

    3. The power consumption between these should be neglectable.

    4. As long as the device is put in a system ON mode, you should be able to let the counter/timer run even in low power mode, both with the RTC and the k_... functions.

    5. The kernel will keep counting as long as you don't put the device to system OFF or specifically disable the LF clock.

    6. I think only the watchdog timer will be able to effect the timer if it is triggered and restarts the device. The BLE stack can interrupt the functions or take priority over them I guess, but won't restart it as far as I know.

    Best regards,

    Simon

Reply
  • Hi

    1. All of the above (kernel functions, RTC, and counter) use the LF clock as the source here I believe, and can be used for different things depending on what you want to do. 

    2. If your goal is to just see the value of the clock, I would think the k_uptime_get(); function is best suited which just lets you get the time of how long the LF clock has been up and running.

    3. The power consumption between these should be neglectable.

    4. As long as the device is put in a system ON mode, you should be able to let the counter/timer run even in low power mode, both with the RTC and the k_... functions.

    5. The kernel will keep counting as long as you don't put the device to system OFF or specifically disable the LF clock.

    6. I think only the watchdog timer will be able to effect the timer if it is triggered and restarts the device. The BLE stack can interrupt the functions or take priority over them I guess, but won't restart it as far as I know.

    Best regards,

    Simon

Children
Related