<?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>RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19621/rtc1-counter-return-to-0</link><description>Hi all, 
 i use softdevice and app timer.
I know that the softdevice use a RTC0 and app timer RTC1. 
 I would use a rtc to have a timestamp. but i see that after 512 second the counter come back to 0. Someon can clarify why? 
 Thanks,
Anna</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Mar 2017 09:39:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19621/rtc1-counter-return-to-0" /><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76376?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 09:39:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7d951b7-ebd5-414d-8e77-a699488af4e6</guid><dc:creator>annapalu</dc:creator><description>&lt;p&gt;Is there a method that allow to know when the rtc1 goes in overflow? Maybe can be most useful instead of create a new timer, What do you think?
Anna&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76375?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2017 16:16:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dff8e93c-1e3e-42e9-85ae-b0f4ddf1c57b</guid><dc:creator>annapalu</dc:creator><description>&lt;p&gt;Hi cirlmar,&lt;/p&gt;
&lt;p&gt;i have a new issue: Since i introduce this functionality, i have sometime a strange behavior of my device. I have two different events on press button:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One for short press&lt;/li&gt;
&lt;li&gt;One for long press
Sometimes i see that if i press a button a long press event is send. It seems that can be a problem with a timer that expires faster. Do you give me a suggestion about that?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thanks,
Anna&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76372?ContentTypeID=1</link><pubDate>Tue, 14 Feb 2017 09:58:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a788d5c2-1860-401b-8b7d-109778347fdd</guid><dc:creator>cirlam</dc:creator><description>&lt;p&gt;24 - The RTC counter on the NRF52 is 24 bits :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76373?ContentTypeID=1</link><pubDate>Tue, 14 Feb 2017 08:29:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:461d35f6-20ec-4201-8819-7a351e21f642</guid><dc:creator>annapalu</dc:creator><description>&lt;p&gt;thank you cirlam!&lt;/p&gt;
&lt;p&gt;It&amp;#39;s very useful, but what&amp;#39;s the value of RTC_TICKS_BITS? Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76374?ContentTypeID=1</link><pubDate>Tue, 14 Feb 2017 08:09:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7b39ebb-8e0b-434f-b87a-4d97791247a6</guid><dc:creator>cirlam</dc:creator><description>&lt;p&gt;I believe if you are using a softdevice, then you may find that the ble stack delays your timer interrupt handler a little, meaning your &amp;#39;lOneSecond&amp;#39; variable won&amp;#39;t be accurate. The link to the thread i posted in the answer above gives some useful information about this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76371?ContentTypeID=1</link><pubDate>Mon, 13 Feb 2017 09:00:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45a2b111-61a2-440c-bc60-6dba3506b5e2</guid><dc:creator>annapalu</dc:creator><description>&lt;p&gt;Hi cirlam,
Thanks for the answer.
if i understood correctly, the idea is count the number of times that the rtc go in overflow, and use it to calculate the second and millisecond.
it&amp;#39;s good idea, but i have a doubt. If a create a timer with a delay of one second, and in the his handler i incremented a variable second, can i use it to trace the time? Somethink like this:&lt;/p&gt;
&lt;p&gt;void DRV_RTC_Init(void)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;uint32_t err_code = 0;
// Create Rtc timer
err_code=TIMER_Create(TIMER_RTC,APP_TIMER_MODE_REPEATED,DRV_RTC_handler_rtc1);
APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;DRV_RTC_Start();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;uint32_t DRV_RTC_ReturnValue()&lt;/p&gt;
&lt;p&gt;{&lt;br /&gt;
return lOneSecond;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void DRV_RTC_Start(void)&lt;/p&gt;
&lt;p&gt;{&lt;br /&gt;
uint32_t err_code ;
// Start rtc timers.
err_code = TIMER_Start (TIMER_RTC,TIMER_RTC_CALLBACK_DELAY,NULL);
APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void DRV_RTC_handler_rtc1(void * p_context)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;UNUSED_PARAMETER(p_context);&lt;/p&gt;
&lt;p&gt;lOneSecond++;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Do you think that can be a problem?&lt;/p&gt;
&lt;p&gt;Thanks,
Anna&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76370?ContentTypeID=1</link><pubDate>Sun, 12 Feb 2017 09:54:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe9034c7-0fe9-4522-8a6b-f4b8ba06439b</guid><dc:creator>cirlam</dc:creator><description>&lt;p&gt;I implemented a workaround for this by using a Repeated App-Timer, with the timeout handler going off the moment before it overflows.&lt;/p&gt;
&lt;p&gt;To create timer:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; err_code = app_timer_create(&amp;amp;m_millis_id,
  APP_TIMER_MODE_REPEATED,
  timer_a_handler);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To start timer:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = app_timer_start(m_millis_id, APP_TIMER_TICKS(511999, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Timeout handler:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;   static void timer_a_handler(void *p_context) {
  overflow++;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can then retrieve the timestamp from the code below&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; void timestampGet(timestamp_t *ts) {
  uint32_t ticks, s, t;

  ticks = app_timer_cnt_get();

  s = ticks / TIMER_TICKS_PER_SECOND; // becomes &amp;gt;&amp;gt;
  t = ticks % TIMER_TICKS_PER_SECOND; // becomes &amp;amp;

  ts-&amp;gt;seconds = overflow * ((1 &amp;lt;&amp;lt; RTC_TICKS_BITS) / TIMER_TICKS_PER_SECOND) + s;
  ts-&amp;gt;milli_seconds = t * (APP_TIMER_PRESCALER + 1) * (1000.0 / APP_TIMER_CLOCK_FREQ);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The code above is adapted from Clem Taylor&amp;#39;s answer here (&lt;a href="https://devzone.nordicsemi.com/question/53893/best-way-to-implement-system-clock-on-nrf51/)"&gt;devzone.nordicsemi.com/.../)&lt;/a&gt;. I had implemented his approach, but found the PPI based counting mechanism increased the current draw from 50ua to 500ua.&lt;/p&gt;
&lt;p&gt;My code above feels like a bit of a hack, so any criticism/suggestions are welcome.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC1 counter return to 0</title><link>https://devzone.nordicsemi.com/thread/76369?ContentTypeID=1</link><pubDate>Fri, 10 Feb 2017 16:03:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4158a6f7-da50-43f5-a3d6-9ae1c8b1562e</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The RTC is a low-frequency timer (real time counter), not a Real Time Clock, as the acronym is used for in some other settings.&lt;/p&gt;
&lt;p&gt;The RTC counts using a 24 bit register. With the timer running at 32768 Hz, the register will overflow after 512 seconds.&lt;/p&gt;
&lt;p&gt;You can set the PRESCALER register, to make the RTC count at a slower rate, allowing it to run up to 582.542 hours before overflowing.&lt;/p&gt;
&lt;p&gt;See &lt;a href="https://devzone.nordicsemi.com/question/72753/clocks-timers-rtc-why/?answer=72870#post-id-72870"&gt;this thread&lt;/a&gt; for more information.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>