<?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>NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28435/nrf52-timing-accuracy</link><description>I&amp;#39;m developing an accurate and low drift millisecond-resolution timer on the NRF52. I&amp;#39;m limited to the resources on the NRF52 itself. Details of the system: 
 
 Initialise TIMER0 to be clocked from the main crystal (16MHz 10 ppm, using the PCA10040</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Dec 2017 20:13:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28435/nrf52-timing-accuracy" /><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112307?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2017 20:13:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:676282a0-d0c1-4fd9-b193-bb052de99348</guid><dc:creator>Dave_couling</dc:creator><description>&lt;p&gt;You are likely subject to the HFCLK ramp-up time.  Manually requesting the HFCLK will keep it up until you release it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112295?ContentTypeID=1</link><pubDate>Fri, 26 May 2017 01:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1cbe8574-080e-4503-b7b1-59df7a19140b</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I was thinking about your previous post overnight and thought of sd_clock_hfclk_request() this morning, but you figured it out yourself before I got there. Good stuff, the softdevice code is written to be power aware and has to be pressed a little to keep everything running.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112294?ContentTypeID=1</link><pubDate>Fri, 26 May 2017 01:09:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79017caf-36fc-46f6-abe6-373776be556f</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;I&amp;#39;ve solved the drifting issue. I&amp;#39;ve tested the accuracy of my milli-second resolution timer and it is 13.4 ppm, similar to that of the 10 ppm HF XTAL on the NRF52 dev board. Key findings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You must call &amp;quot;sd_clock_hfclk_request&amp;quot; and wait for confirmation that it is running via &amp;quot;sd_clock_hfclk_is_running&amp;quot;. The call to &amp;quot;SOFTDEVICE_HANDLER_INIT&amp;quot; will set the system to use the HF CLOCK. However, the resulting timing suggests that the system is still using the internal RC oscillator if the aforementioned setup is not done afterwards. This is not very clear in the examples and I recommend that future examples explicitly do this, ideally not buried away in some optional module that the end user may not use in their application.&lt;/li&gt;
&lt;li&gt;When using the TIMER module in the timer mode, you need to get the current timer value via issuing a capture on a different channel than that of your compare. The internal timer count is then immediately accessible on the appropriate CC register. [This is&lt;/li&gt;
&lt;li&gt;The correct value for the compare channel is the (value), not the (value - 1). This is slightly odd as I&amp;#39;d assume the SHORTS mechanism reloads the timer value to 0 and the timer counter increment on the next clock.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I have also reduced the interrupt frequency of the compare to 20Hz (originally 1000Hz). This is to ensure that no interrupts are lost while the CPU servicing BLE radio tasks. In my application I also use this compare interrupt for timed callback functions. I&amp;#39;ll need to increase the interrupt frequency for finer controlled timed callbacks but run the risk of missing interrupts while using BLE.&lt;/p&gt;
&lt;p&gt;The updated example program can be found here: &lt;a href="https://www.dropbox.com/s/5kjxy3fm17dwobz/nrf_timer_accuracy_test_final.c?dl=0"&gt;www.dropbox.com/.../nrf_timer_accuracy_test_final.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112306?ContentTypeID=1</link><pubDate>Thu, 25 May 2017 04:25:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f35d3471-a763-409b-afc3-251ec0742289</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;I&amp;#39;ve since updated my test program. I&amp;#39;ve also reduced the capture compare interrupt frequency to 20Hz, so should not have any missing interrupts while the radio is being operated. If I enable the HF XTAL via the &amp;quot;registers&amp;quot;, I observer a drift of 3.21ms over 4 minutes. However, if I enable the HF XTAL via enabling the soft device, the drift is much worse - 193ms over 1 minute! Suggestions? Updated test program can be found here: &lt;a href="https://www.dropbox.com/s/jjhntmsorojazym/nrf_timer_accuracy_test2.c?dl=0"&gt;www.dropbox.com/.../nrf_timer_accuracy_test2.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112305?ContentTypeID=1</link><pubDate>Thu, 25 May 2017 03:11:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d05e1ea5-2942-44ac-aa3a-77ef252ad1d1</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;RK, I think your suggestion to check the clock source is the answer here. (I usually have the soft device running, but for the purpose of a small test program I neglected to switch over to the HF crystal). I&amp;#39;ve retested the timer and it is drifting at 13.4 ppm. I&amp;#39;ll stick with the current compare match feature, mainly because I also use this interrupt to trigger timed callbacks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112304?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 23:36:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4026351-a458-4c18-a6b9-63f900cee0b0</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;just keep a separate counter of the number of times it rolled over. your timestamp is then (rollover count * timer rollover ) + ( timer current value). This is sort of how everyone keeps a long-running timestamp.&lt;/p&gt;
&lt;p&gt;by the way - you did explicitly start the HF crystal didn&amp;#39;t you, the softdevice starts that for you usually, if you&amp;#39;re not using that and don&amp;#39;t start it yourself (you can check the bit in the mask to see if it&amp;#39;s running) then you&amp;#39;re on the internal oscillator.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112303?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 23:19:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce1e831d-8622-457d-b8aa-3d0f782096f0</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;RK, as for the method of clearing the counter, I&amp;#39;ve enabled the event-task shortcut to clear the timer on the compare event. The only thing I&amp;#39;m doing that is timer-related in the ISR is clearing the interrupt flag, so I don&amp;#39;t expect any drift to be occurring due to the duration of the ISR. I&amp;#39;ve posted a short program which demonstrates the problem. This can be downloaded here: &lt;a href="https://www.dropbox.com/s/poduuob67jwz8mo/nrf_timer_accuracy_test.c?dl=0"&gt;www.dropbox.com/.../nrf_timer_accuracy_test.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112302?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 23:17:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eac36b93-ecb3-456f-ba9d-591ae9fcbe7d</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;RK, good point about the timer value being the value. Unfortunately, I need to maintain a timestamp that is capable of values well beyond that of the rollover of the timer!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112301?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 22:55:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f953db1b-3c46-41e8-99b6-bd687e9bd331</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;also if you just want a time not a time signal, just let the TIMER run free and keep a counter each time it overflows, then you just read the timer value every time you need a timestamp and use it directly. You don&amp;#39;t have to increment a separate value in RAM, the timer IS your value.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112300?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 22:52:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90ad05ae-4081-4a70-9166-d727f61484e0</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;How are you resetting the TIMER after the interrupt fires. If you&amp;#39;d doing it in the interrupt handler, you&amp;#39;re going to drift all over the place as interrupt handlers can get delayed. If you don&amp;#39;t already have it, you need to set up the PPI or shortcut so that the timer firing event clears the timer in hardware.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112299?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 21:36:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12a873dd-c428-482e-a53a-85fe59ef1add</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;My requirement is to capture and record BLE packets. This data is to be synced up to another separate independent system that time-stamps data using UTC time and GPS PPS. I can &amp;quot;sync&amp;quot; the two data sets once only, but require both systems to time-stamp data with millisecond resolution timers that are have low drift (ideally within 10 ppm, currently 560 ppm is too much!), due to the nature of the data and duration of the events.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112298?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 21:27:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7664ef3d-a564-4274-bfb9-c208a02129ea</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;Unless I can somehow use the PPI to update the millisecond timer value in RAM? (My understanding that PPI is to connect one hardware peripheral to another without using the CPU).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112297?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 21:15:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:931f1d81-718c-44aa-a697-90c6abad5f89</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;Kristin,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying to create an accurate timestamp, not an accurate timer signal. (I&amp;#39;m only generating a timing output so I can validate the accuracy of the timer against the GPS PPS).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112296?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 09:12:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1098617-c239-448e-b627-ef28dc4959ac</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;To generate an accurate timer signal, you should use hardware peripherals (PPI and GPIOTE to toggle a GPIO), rather than software interrupts. The gpiote example in the SDK shows how to do so.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Timing Accuracy</title><link>https://devzone.nordicsemi.com/thread/112293?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 02:46:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:973d7374-a111-4bbf-8053-9e5195451ad0</guid><dc:creator>rct42</dc:creator><description>&lt;p&gt;I just had a read through the RTC module. Unfortunately, I can&amp;#39;t use this as I require a milli-second resolution (the RTC module is clocked from a 32.768kHz source). Basically I&amp;#39;m after something that increments a 32-bit value stored in ram every 0.99999 - 1.00001 ms (1ms +/- 10 ppm).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>