<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/25416/calculate-time-until-next-rtc-interrupt</link><description>Greetings - 
 I am using (the slightly out-dated) 12.3 SDK with a nRF52840. I&amp;#39;m also using s132 as my softdevice. 
 As I&amp;#39;ve been slowly reducing my RTC interrupt frequency to cut down on power consumption, I have a growing need to be able to determine</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 02 Oct 2017 15:01:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/25416/calculate-time-until-next-rtc-interrupt" /><item><title>RE: Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/thread/100171?ContentTypeID=1</link><pubDate>Mon, 02 Oct 2017 15:01:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aeb28ff3-6ba2-4ece-b76d-cb360b058b5b</guid><dc:creator>Julie H</dc:creator><description>&lt;p&gt;Yes! I&amp;#39;m able to see NRF_LOG messages with timestamps that aren&amp;#39;t multiples of my RTC tick interval.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/thread/100168?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2017 18:37:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6bd80db-8f7f-4259-9554-7353fa76b750</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;But it means that you have resolved the core of the problem? Sounds promising;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/thread/100167?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2017 18:14:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee2fff0e-3234-4c14-914b-27247705f2f2</guid><dc:creator>Julie H</dc:creator><description>&lt;p&gt;My solution was to keep using RTC2 the way I&amp;#39;m doing it today, but to fetch RTC1&amp;#39;s COUNTER register and compare it against the COUNTER register value I saved the last time I did that, and do all that in an interrupt-safe and lockless (no critical sections) fashion. I didn&amp;#39;t use RTC0 because I don&amp;#39;t know if it is turned off when I turn off the radio. And I&amp;#39;m impatient.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/thread/100169?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2017 15:51:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21d82064-93cf-496f-a3ab-b49ffcce8a4b</guid><dc:creator>Julie H</dc:creator><description>&lt;p&gt;Based on the other answer, app_timer() seems to be pretty thoroughly infiltrated into the SDK. I also hate how it handles events, so I wrote my own RTOS. Because, everyone needs to write their own RTOS from time to time ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/thread/100170?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2017 15:48:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:873c5545-6d33-44c0-92b6-6df04ffb7555</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;That&amp;#39;s different situation;) Yes, app_timer lib needs one RTC instance. But when you have app_timer why you need anything else? Are you running some RTOS with RTC systick or similar thing? If so then why you use app_timer? Anyway even if you would occupy all three RTCs with these functions there should be counter visibly ticking on each of them (which was root of your question). Or did I miss anything?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/thread/100172?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2017 15:35:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:458a1bd6-e692-484f-9cab-b53c17582182</guid><dc:creator>Julie H</dc:creator><description>&lt;p&gt;Unfortunately, according to this answer -- &lt;a href="https://devzone.nordicsemi.com/question/938/rtc0-rtc1-and-the-app_timer-with-softdevice/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt; -- RTC2 is the only RTC available if I&amp;#39;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!&lt;/p&gt;
&lt;p&gt;I do like your suggestion that I look at the COUNTER register for RTC0. I&amp;#39;ll take a look and see how it&amp;#39;s run and see what that turns up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculate time until next RTC Interrupt</title><link>https://devzone.nordicsemi.com/thread/100166?ContentTypeID=1</link><pubDate>Sat, 23 Sep 2017 21:42:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9b0d4a0-35b4-44ed-8822-46f9366ebee7</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;Hi Julie,&lt;/p&gt;
&lt;p&gt;From what I understand about S132 (applies also to S140) Soft Device and nRF52:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.sds/dita/softdevices/s130/sd_resource_reqs/hw_block_interrupt_vector.html?cp=2_3_0_0_6_0"&gt;BLE stack &amp;quot;blocks&amp;quot; only first RTC&lt;/a&gt;, all the rest are available for your app.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/rtc.html?cp=2_1_0_24_9_0#register.INTENSET"&gt;The only interrupts generated by RTC block are TICK, OVERFLOW and COMPARE&lt;/a&gt;. You can enable each of them independently so it typically is used either in TICK or COUNTER mode.&lt;/li&gt;
&lt;li&gt;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&amp;#39;t make any harm to the SD (but worth checking with other Q&amp;amp;S on this forum and testing) - and just subtract delta from previous &amp;quot;time stamp&amp;quot;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;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?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>