<?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>Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64611/implementing-64-bit-epoch-time-using-timer</link><description>I have an application that requires that timestamps be 64-bit epoch to the millisecond. I&amp;#39;m currently using a Timer peripheral to track 1ms and increment a 64-bit counter. I was concerned reading the value in an atomic way so I am currently disabling</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 May 2021 07:39:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64611/implementing-64-bit-epoch-time-using-timer" /><item><title>RE: Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/thread/311974?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 07:39:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa05660d-d002-4a6e-a90a-d0aa071d3a16</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Darren&lt;/p&gt;
&lt;p&gt;Yes, you shouldn&amp;#39;t have to disable the compare event itself, just temporarily disable the interrupt.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;nrf_timer_int_disable/enable should work fine, or you could disable the timer interrupt globally.&amp;nbsp;&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><item><title>RE: Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/thread/311622?ContentTypeID=1</link><pubDate>Wed, 26 May 2021 02:57:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ebbd2670-20f8-4259-84ee-2d3a221fa408</guid><dc:creator>WestCoastDaz</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have some followup questions regarding the suggested implementation. &amp;nbsp;You sequence mentions disabling the timer interrupt and then enabling the timer interrupt once I have gotten the number of milliseconds using the capture.&lt;/p&gt;
&lt;p&gt;I took this&amp;nbsp;to mean disabling the CC[0]&amp;nbsp;interrupt and then enable the CC[0] interrupt. The nrfx_timer.c implementation &amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrfx_timer_compare_int_enable&lt;/pre&gt;&amp;nbsp;calls&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_timer_event_clear&lt;/pre&gt;&amp;nbsp;which clears the timer&amp;nbsp;counter which will cause time to be lost every time the epoch is read, no?&lt;/p&gt;
&lt;p&gt;Should I just call&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_timer_int_enable&lt;/pre&gt;&amp;nbsp;directly instead?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/thread/265034?ContentTypeID=1</link><pubDate>Tue, 18 Aug 2020 09:11:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b1774f2-c1d9-4eb4-b0b6-dd8b29ff2081</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Darren&lt;/p&gt;
&lt;p&gt;Yes,&amp;nbsp;dividing by 1000 should work fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can also reduce the speed of the timer to 125kHz by using a PRESCALER value of 7, and divide by 125 to get the milliseconds, but the end result is the same.&amp;nbsp;&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><item><title>RE: Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/thread/264950?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2020 20:38:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:474f34e9-78f5-473a-8d2c-cf839e3c52c2</guid><dc:creator>WestCoastDaz</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thank you for taking the time to answer.&amp;nbsp; Sorry I couldn&amp;#39;t reply until now as I was away on vacation without much access to good internet.&lt;/p&gt;
&lt;p&gt;I understand your implementation.&amp;nbsp; I don&amp;#39;t need the microseconds so it looks like the best option to get the milliseconds is to divide the result of the compare by 1000?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Darren&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/thread/264309?ContentTypeID=1</link><pubDate>Wed, 12 Aug 2020 14:39:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6786a8ee-a83d-4cd3-ac4a-99fc70bf5a38</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Darren&lt;/p&gt;
&lt;p&gt;As you probably know the CC registers can be used either as compare registers, capture registers or both.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My point is just that if you use say CC[0] to generate an interrupt after 1 second you should use a separate register, such as CC[1], to capture the current timer value whenever you want to read the current time.&amp;nbsp;&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><item><title>RE: Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/thread/264143?ContentTypeID=1</link><pubDate>Wed, 12 Aug 2020 03:31:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:091ae639-92a3-4185-9db3-0d40f7f8e8e0</guid><dc:creator>WestCoastDaz</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks for taking time to answer.&amp;nbsp; I like this idea as it reduces overall load on the system.&amp;nbsp; Can you elaborate on point 2?&amp;nbsp; I&amp;#39;m not sure I follow on the meaning of &amp;quot;capture the current timer value to a separate CC register&amp;quot;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Darren&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implementing 64-bit Epoch Time Using Timer</title><link>https://devzone.nordicsemi.com/thread/263951?ContentTypeID=1</link><pubDate>Tue, 11 Aug 2020 08:10:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00a976dd-be9e-49e0-9bcb-72fbb805aeff</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Darren&lt;/p&gt;
&lt;p&gt;For efficiency reasons I would suggest using a longer interval before you update your variable, and do a timer capture to get the &amp;#39;lower bits&amp;#39; of the timestamp.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As an example if you configure the timer to run at a 1MHz frequency (prescaler = 4) you can reload it every second, and get the milliseconds (and microseconds if needed) by doing a capture on the timer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To get the current timer value you could do the following:&lt;/p&gt;
&lt;p&gt;- Disable timer interrupt&lt;br /&gt;- Capture the current timer value to a separate CC register&lt;br /&gt;- Add the captured value to your variable counting the seconds, and return this as the current time&lt;br /&gt;- Enable timer interrupt&lt;/p&gt;
&lt;p&gt;Then in the interrupt you essentially need to increment the second variable, and&amp;nbsp;increment the capture register by a million to schedule the next interrupt.&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>