<?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>RTC drift ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/98624/rtc-drift</link><description>Hi, 
 We have a custom board with an nRF9160. We are using NCS 2.0.2 and we are using the RTC to keep track of local time. For this we are using the &amp;quot;counter&amp;quot; from Zephyr. 
 In the overlay file we have configured the RTC to count in 1/256 second steps</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 May 2023 22:08:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/98624/rtc-drift" /><item><title>RE: RTC drift ?</title><link>https://devzone.nordicsemi.com/thread/423871?ContentTypeID=1</link><pubDate>Thu, 04 May 2023 22:08:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6ac7c03-901f-4dca-9b18-8de3db8ca2bd</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi MaLu,&lt;/p&gt;
&lt;p&gt;I got feedback from our engineers a few days ago but&amp;nbsp;was too occupied&amp;nbsp;and could only relay the information today. My apologies.&lt;/p&gt;
&lt;p&gt;The tolerance listed for LFXO in the nRF9160 Product Specification is only the tolerance of the crystal component. Meanwhile, the tolerance of LFXO is also dependent on the tolerance of the capacitors in the crystal oscillator circuit.&lt;/p&gt;
&lt;p&gt;Considering that, the&amp;nbsp;drift that you observed is not&amp;nbsp;impossible. We have made a note to make improvement regarding this part of the Product Specification.&lt;/p&gt;
&lt;p&gt;Regarding real time tracking, the amount of RTC drift that each device has is going to be stable given the same&amp;nbsp;environment conditions. Therefore, we suggest perhaps you could have the algorithm adapt to the drift. For example, instead of&amp;nbsp;hard-coded one second to advance after 32768 RTC ticks, you could calculate a more accurate number of ticks and update the algorithm to use that instead.&lt;/p&gt;
&lt;p&gt;However, if the strategy you currently use is good enough for you, then that is also totally fine.&lt;/p&gt;
&lt;p&gt;My apology for the long wait and the inconveniences.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC drift ?</title><link>https://devzone.nordicsemi.com/thread/421028?ContentTypeID=1</link><pubDate>Tue, 18 Apr 2023 12:33:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a68127a1-7673-4363-ad84-8bea49a3fef9</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you check if the drift is more/less when using the LFRC as the clock source?&lt;/p&gt;
&lt;p&gt;On my end,&amp;nbsp;I found a contact point for the RTC in the nRF91 and have just now&amp;nbsp;sent&amp;nbsp;an internal ticket to them.&lt;/p&gt;
&lt;p&gt;Do you have a SiP version for referencing?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC drift ?</title><link>https://devzone.nordicsemi.com/thread/420640?ContentTypeID=1</link><pubDate>Mon, 17 Apr 2023 05:18:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:319e1296-0847-4609-9135-9ef4c5099ea2</guid><dc:creator>MaLu</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;I just realized in the code, a channel alarm is also called&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void Rtc_SetFlushWakeup(void)
{
  struct counter_alarm_cfg sAlarmCfg =
  {
    .callback = Rtc_FlushWakeupHandler,
    .flags    = 0,
    .ticks    = counter_us_to_ticks(psRtc_Dev, RTC_FLUSH_TIMEOUT_S * RTC_USEC_IN_SEC),
    .user_data = NULL
  };

  counter_set_channel_alarm(psRtc_Dev, RTC_ALARM_CHANNEL, &amp;amp;sAlarmCfg);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Can this cause the rtc to desync?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve removed this alarm and the drift still occurs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC drift ?</title><link>https://devzone.nordicsemi.com/thread/420175?ContentTypeID=1</link><pubDate>Thu, 13 Apr 2023 10:35:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6d90878-f995-4ba7-8b12-cb64cbc2be5c</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi MaLu,&lt;/p&gt;
&lt;p&gt;Thanks a lot for the detailed explanation. I definitely am less confused than before&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think your code ought to be fine then. However, I am also out of ideas at this point, unless your nRF9160 has been running for two years.&lt;/p&gt;
&lt;p&gt;Let me check with other engineers here to see if this could be something else.&lt;/p&gt;
&lt;p&gt;I am partially out of office for the rest of the week, so I hope you could wait until early next week for&amp;nbsp;my follow-ups.&amp;nbsp;&lt;span&gt;If this is urgent, please let me know and we can look for alternatives.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC drift ?</title><link>https://devzone.nordicsemi.com/thread/420090?ContentTypeID=1</link><pubDate>Thu, 13 Apr 2023 06:30:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a4c0230-dc85-4679-9abf-a50c369887d4</guid><dc:creator>MaLu</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the reply. We are testing at about room temperature in the office, so ~21&amp;deg;C.&lt;/p&gt;
&lt;p&gt;We need a precision of 1/256s. A single u32 is too small to contain the absolute timestamp with the resolution needed, so we split it in two.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We store the full seconds of our absolute timestamp in the &lt;code&gt;sRtc_StoredStamp.&lt;strong&gt;u32&lt;/strong&gt;SysTime&lt;/code&gt; and the number of 1/256th seconds, that overshoot the full seconds, in&amp;nbsp;&lt;code&gt;sRtc_StoredStamp.&lt;strong&gt;u8&lt;/strong&gt;SysTime&lt;/code&gt;. Since the RTC counts with 256Hz, this u8 Value is basically the number of ticks, that overshoot the full seconds.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This adds the full seconds, that have passed to the variable that stores the full seconds of our absolute timestamp&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="ui-code" data-mode="text"&gt;sRtc_StoredStamp.u32SysTime += u32DeltaTicks / counter_get_frequency(psRtc_Dev);&amp;#160;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;but this disregards the additional ticks, that have passed in this measurement.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This isolates the ticks, that are above the full seconds, that have passed since the last read.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;u32DeltaTicks = u32DeltaTicks &amp;amp; 0xFF;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Since the ticks have a resolution of 1/256s, they are the same unit as the&amp;nbsp;&lt;code&gt;sRtc_StoredStamp.u8SysTime&lt;/code&gt; of the absolute timestamp. We now need to add the ticks to the&amp;nbsp;1/256s part of the absolute timestamp. If this would result in a value above 255, then the addition of the 1/256s part of the delta ticks caused the absolute timestamp to roll over to the next second.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;  if(u32DeltaTicks + sRtc_StoredStamp.u8SysTime &amp;gt; 0xFF)
    sRtc_StoredStamp.u32SysTime++;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;At last, we just add the 1/256s part of the delta ticks to the &lt;span&gt;1/256s part&amp;nbsp;of the&amp;nbsp;&lt;/span&gt;absolute timestamp.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;sRtc_StoredStamp.u8SysTime += u32DeltaTicks;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I know this may be a little confusing,so here is an example:&lt;/p&gt;
&lt;p&gt;lets say the stored absolute timestamp is 4.9765625s. This is 4 full seconds and &lt;span&gt;976.5625&lt;/span&gt;ms = 250 * 1/256s&lt;br /&gt;So the absolute stamp would be:&lt;br /&gt;&lt;span&gt;sRtc_StoredStamp.&lt;/span&gt;&lt;strong&gt;u32&lt;/strong&gt;&lt;span&gt;SysTime = 4&lt;br /&gt;sRtc_StoredStamp.&lt;strong&gt;u8&lt;/strong&gt;SysTime = 250&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;then we do an Rtc_Read() and calculate, for example, a&amp;nbsp;&lt;br /&gt;u32DeltaTick = 522&lt;br /&gt;which is equivalent to&amp;nbsp;2.0390625s (because we tick with 256Hz), that have passed since the last time we called for a read.&lt;br /&gt;so thats 2 full seconds and&amp;nbsp;&lt;span&gt;39.0625ms = 10 * 1/256s&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;so we do&amp;nbsp;&lt;br /&gt;sRtc_StoredStamp.&lt;strong&gt;u32&lt;/strong&gt;SysTime += 2, for the full 2 seconds since the last read&lt;br /&gt;for the u8 part, we would need to do 250 + 10, which would overflow to the next second, since a value of 260 would be&amp;nbsp;1.015625s.&lt;br /&gt;So we do another second in this case.&lt;br /&gt;sRtc_StoredStamp.&lt;strong&gt;u32&lt;/strong&gt;SysTime++&lt;br /&gt;Would the u8 part not overflow to the next second, we would not need to do this.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now we do&lt;br /&gt;sRtc_StoredStamp.&lt;strong&gt;u8&lt;/strong&gt;SysTime += 10&lt;br /&gt;which would result in a value of 260, but because an u8 can only hold values up to 255, it then rolls over. since we have 256 ticks in a second, an u8 is rather helpful here. We have handled the rollover above, by adding another second.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I hope you are less confused than before, but I could understand if this made you more confused haha.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC drift ?</title><link>https://devzone.nordicsemi.com/thread/420023?ContentTypeID=1</link><pubDate>Wed, 12 Apr 2023 15:11:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6bf54b40-1172-4747-abaf-d102bcda4858</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi MaLu,&lt;/p&gt;
&lt;p&gt;Thank you for your patience.&lt;/p&gt;
&lt;p&gt;I have gone over your code. I find the part where you calculate delta RTC tick fine. However I don&amp;#39;t fully understand the 1/256s handling part. Could you please elaborate about this part?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;  sRtc_StoredStamp.u32SysTime += u32DeltaTicks / counter_get_frequency(psRtc_Dev);

  /* handle 1/256s overflow */
  u32DeltaTicks = u32DeltaTicks &amp;amp; 0xFF;
  if(u32DeltaTicks + sRtc_StoredStamp.u8SysTime &amp;gt; 0xFF)
    sRtc_StoredStamp.u32SysTime++;

  sRtc_StoredStamp.u8SysTime += u32DeltaTicks;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The tolerance for the LFXO of the nRF9160 SiP is +-20ppm, according to its Product Specification. This means that it should drift only ~1.73s a day and would take 2.89 days to drift 5s. Thus, your observed drift of ~5s/day is indeed abnormal. But that&amp;#39;s if this is tested with a new SiP in the specified temperature.&lt;/p&gt;
&lt;p&gt;What is the temperature the SiP is being&amp;nbsp;tested in, and how long has the SiP been running, by the way? These can affect the tolerance.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC drift ?</title><link>https://devzone.nordicsemi.com/thread/419608?ContentTypeID=1</link><pubDate>Tue, 11 Apr 2023 10:17:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0b70937-c911-4f42-9474-4932d7f324fd</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;We just came back from Easter vacation and that was the reason for no response from out end.&amp;nbsp;&lt;/span&gt;&lt;span&gt;D&lt;/span&gt;&lt;span&gt;ue to very high traffic during this period on devzone and fewer people working this week,&amp;nbsp;&lt;/span&gt;&lt;span&gt;we did not manage to assign this to an expert yet. We will look into this as soon as possible, but please expect more delays the first two days. Thanks for your patience so far.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>