<?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>Suggestions for low power time keeping on nRF51?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19125/suggestions-for-low-power-time-keeping-on-nrf51</link><description>I&amp;#39;m trying to decide the best way to be able to have sub millisecond time keeping, but keep the processor sleeping until it gets a hardware interrupt. 
 Basically I need to time the period of pulse signals, e.g from a flow meter. Where I may get one</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Aug 2017 08:18:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19125/suggestions-for-low-power-time-keeping-on-nrf51" /><item><title>RE: Suggestions for low power time keeping on nRF51?</title><link>https://devzone.nordicsemi.com/thread/74010?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2017 08:18:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e953740-0758-4582-b91b-cdeaf4f87548</guid><dc:creator>Nicolas Brunner</dc:creator><description>&lt;p&gt;Doing the following can result in error when the RTC overflow:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;total_time = RAM_counter &amp;lt;&amp;lt; 24 | RTC_counter;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you are doing the read in a lower interrupt priority than RTC overflow interrupt, you can do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;do {
  RAM_counter_copy = RAM_counter;
  total_time = RAM_counter_copy &amp;lt;&amp;lt; 24 | RTC_counter;
} while (RAM_counter_copy != RAM_counter);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suggestions for low power time keeping on nRF51?</title><link>https://devzone.nordicsemi.com/thread/74009?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2017 19:57:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6fab4e9-47f0-4e7d-b149-d5984ffd1a99</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Thanks Torbjørn.&lt;/p&gt;
&lt;p&gt;I will try using that method.&lt;/p&gt;
&lt;p&gt;Re: Time drift&lt;/p&gt;
&lt;p&gt;I think the drift in the crystal is well within the limits of what I need, and I am not using the value to calculate an accumulated value, but only to broadcast an instantaneous indication of flow rate, based on frequency of pulses, which would normally occur at a maximum frequency of 10Hz&lt;/p&gt;
&lt;p&gt;This data is encoded into the manufacturer data of the advertising packet, which is broadcast once per second ( to give longer battery life)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suggestions for low power time keeping on nRF51?</title><link>https://devzone.nordicsemi.com/thread/74008?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2017 14:46:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3377a04-fb5c-443d-ae74-b56658bd0998</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Roger&lt;/p&gt;
&lt;p&gt;You can definitely use the RTC counter value to keep track of the 32kHz clock.
The RTC counter is 24 bits, which means it will overflow every 512 seconds when using the smallest prescaler (for maximum accuracy).&lt;/p&gt;
&lt;p&gt;When it overflows you can wake up, and increment a counter in RAM.&lt;/p&gt;
&lt;p&gt;To read out the current value you just have to concatenate the counter with the current RTC value:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;total_time = RAM_counter &amp;lt;&amp;lt; 24 | RTC_counter;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The time of each 32kHz clock is ~30.5us, so this will be the limit of your accuracy.
If you want to keep track of absolute time you also have to consider the drift of your clock source.
As an example a 20ppm 32k crystal would introduce a potential drift of 1.7 seconds per day.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;
Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>