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

nrf52840 RTC vs app_timer plus timestamping

hello Nordic

i am working with nrf52840, sdk16, over the peripheral app_ble_blinky example

my system will go to sleep mode for 10 minutes each time, i wonder if there is any advantage to use RTC directly instead of app_timer in meters of power consumption, is there less cpu interventions or over head when using RTC directly ?

also if i have some gpio interrupt during the 10 min sleep then i want to be able to read the current clock at resolution of 100ms. 

first thought was to use an app_timer that counts in 100ms intervals but that seems wasteful, i think i should seek for a way to have one timer interrupt every 10 minutes but ne able to get the current time stamp from the clock maybe.

1. is there a way to read a clock value while in sleep mode, that has some meaning, does it start from '0' every time we put the power on so we can try to calculate the delta each time ? 

2. is there a way to have an app_timer running on REPEATED mode that wakes up every 10 minutes ? does it really save something or it ticks every 32khz anyway? and is it better to do it directly with RTC ?

not so relevant but what's the difference between WFI and WFE beside the Event/Interrupt, does it refer to the type of sleep mode - system ON sleep(for WFE) vs system OFF sleep (for WFI)?

hope to read from you soon

best regards

Ziv

Parents
  • Hi,

    my system will go to sleep mode for 10 minutes each time, i wonder if there is any advantage to use RTC directly instead of app_timer in meters of power consumption, is there less cpu interventions or over head when using RTC directly ?

    App_timer has a few additional interrupts that trigger on at specific events (overflow, compare1 at half of max count), to handle internal flow. When using RTC directly, you can configure it for your exact needs, to avoid these interrupts. Depending on the configuration, these events should not have a very big impact on the average current consumption.

    1. is there a way to read a clock value while in sleep mode, that has some meaning, does it start from '0' every time we put the power on so we can try to calculate the delta each time ? 

    Not sure exactly how you intend to read the clock value while you are in sleep mode, but if you mean before and after sleep, you can use the app_timer_cnt_get() and app_timer_cnt_diff_compute() functions. These functions will simply get the count register from the RTC and compute the difference between them, but if you configure APP_TIMER_CONFIG_RTC_FREQUENCY to allow the RTC to not overflow more than once during the longest expected sleep cycle, this should work. If you want to translate this to actual time in your application, you need to store the counts, or use a similar approach to the nRF5 Calendar Example.

    2. is there a way to have an app_timer running on REPEATED mode that wakes up every 10 minutes ? does it really save something or it ticks every 32khz anyway? and is it better to do it directly with RTC ?

    App_timer uses compare events to wakeup when the next timer expires, it does not wake every 32 kHz to "tick". The frequency is also configurable, allowing for longer timers, as described above.

    not so relevant but what's the difference between WFI and WFE beside the Event/Interrupt, does it refer to the type of sleep mode - system ON sleep(for WFE) vs system OFF sleep (for WFI)?

    Both uses System On idle mode. The chip can only wake from System OFF from a limited set of peripheral signals (see System OFF mode), and wakeup will cause a chip reset. See this post for more details on WFE/WFI.

    Best regards,
    Jørgen

  • hi Jorgen

    thanks for your reply

    Not sure exactly how you intend to read the clock value while you are in sleep mode

    i mean that while i am in sleep mode there can be an event that wakes up the system, not by the timer, and i may want to know how much time has passed in the 0-2 last hours (i wake up every 10 min for small sampling and every 2 hours 10*12 for bigger operation)  

    just few more clarifications on that matter: 

    1. if i use the APP_TIMER_CONFIG_RTC_FREQUENCY, to change pre scaling if i understand correct, would it affect other app_timer instances that i have in my program ? 

    2. the APP_TIMER_CONFIG_RTC_FREQUENCY to 1024 (minimum) but, with RTC, if i get this right,

    in the "sdk_config.h": "NRFX_RTC_DEFAULT_CONFIG_FREQUENCY - Frequency  <16-32768> "

    i can get down to 16 tick per second, am i right ?

    3. if i want to use the RTC directly, is there an example in the sdk for using the RTC directly, and if i have softdevice, timer (HFCLK), SPI(at 8MHz), TWI (not sure if the serials clock matter) and one instance of app_timer in my program, can i use only the RTC2 for this 10min sleep ?

    hope to read from you soon

    best regards

    Ziv

Reply
  • hi Jorgen

    thanks for your reply

    Not sure exactly how you intend to read the clock value while you are in sleep mode

    i mean that while i am in sleep mode there can be an event that wakes up the system, not by the timer, and i may want to know how much time has passed in the 0-2 last hours (i wake up every 10 min for small sampling and every 2 hours 10*12 for bigger operation)  

    just few more clarifications on that matter: 

    1. if i use the APP_TIMER_CONFIG_RTC_FREQUENCY, to change pre scaling if i understand correct, would it affect other app_timer instances that i have in my program ? 

    2. the APP_TIMER_CONFIG_RTC_FREQUENCY to 1024 (minimum) but, with RTC, if i get this right,

    in the "sdk_config.h": "NRFX_RTC_DEFAULT_CONFIG_FREQUENCY - Frequency  <16-32768> "

    i can get down to 16 tick per second, am i right ?

    3. if i want to use the RTC directly, is there an example in the sdk for using the RTC directly, and if i have softdevice, timer (HFCLK), SPI(at 8MHz), TWI (not sure if the serials clock matter) and one instance of app_timer in my program, can i use only the RTC2 for this 10min sleep ?

    hope to read from you soon

    best regards

    Ziv

Children
Related