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

Calculate time until next RTC Interrupt

Greetings -

I am using (the slightly out-dated) 12.3 SDK with a nRF52840. I'm also using s132 as my softdevice.

As I've been slowly reducing my RTC interrupt frequency to cut down on power consumption, I have a growing need to be able to determine the length of time until the next RTC interrupt.

I can calculate the period from the PRESCALER register, but there is no register which counts up or down which could be used to determine how far along in the process things happen to be.

The other two RTC peripherals are being used by the soft device or I'm sure I could come up with some other way. It seems this should be a pretty basic thing. Why is it impossible!

Parents
  • Hi Julie,

    From what I understand about S132 (applies also to S140) Soft Device and nRF52:

    • BLE stack "blocks" only first RTC, all the rest are available for your app.
    • The only interrupts generated by RTC block are TICK, OVERFLOW and COMPARE. You can enable each of them independently so it typically is used either in TICK or COUNTER mode.
    • Whatever mode is used COUNTER is always incremented and you can read it any time. So e.g. your app can easily count what was the difference between last and current interrupt and by knowing all the parameters like frequency and PRESCALER you can come to the actual time measurements. I actually believe that if you need just random time keeping you might be able to read RTC0 COUNTER - because reading shouldn't make any harm to the SD (but worth checking with other Q&S on this forum and testing) - and just subtract delta from previous "time stamp".

    So what exact mode are you using now and what interrupts are we talking about? Secondly am I wrong that COUNTER is not available and used by every RTC or it could use for any kind of computation? Or is there other concern I missed?

  • Unfortunately, according to this answer -- devzone.nordicsemi.com/.../ -- RTC2 is the only RTC available if I'm using the BLE stack and app_timer(). I could probably work-around using app_timer(), but as that answer also says, Good Luck With That!

    I do like your suggestion that I look at the COUNTER register for RTC0. I'll take a look and see how it's run and see what that turns up.

Reply Children
No Data
Related