<?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>TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30105/ticktimer-accuracy</link><description>Hi, 
 
 We are using SD110 with SDK 7.2.0 in our application 
 Our application needs to be quite accurate in timing 
 We set out to determine what the accuracy of the TickTimer was, which is provided by the SD (110 in our case) 
 Our hardwaresetup is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 02 Feb 2018 13:25:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30105/ticktimer-accuracy" /><item><title>RE: TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/thread/119541?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 13:25:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efc17312-b5c0-49c0-9ae5-fc0b5279de54</guid><dc:creator>JayPRab</dc:creator><description>&lt;p&gt;I did not know that. I thought it used the HF clock...&lt;/p&gt;
&lt;p&gt;Yes, I do have a crystal.&lt;/p&gt;
&lt;p&gt;Thanks for all the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/thread/119452?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2018 00:31:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:134669cc-70ae-4dfe-9b3c-775c2926f9e7</guid><dc:creator>Hein</dc:creator><description>&lt;p&gt;So, the app timer runs from the 32.768kHz clock, I assume you have a crystal for this? Either way, you cannot get a 1ms interrupt because 32.768kHz does not divide cleanly into 1ms.&amp;nbsp; You will probably get much more reasonable results if you set a repeating app timer to expire after 1 second and then check your counter value. But as stated by Ambystomalabs, it still takes time to service events, so there will always be some jitter in your measurements.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/thread/119443?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2018 23:05:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c98f0a6-7338-470b-aae5-7488890b7020</guid><dc:creator>JayPRab</dc:creator><description>&lt;p&gt;I will check. &lt;/p&gt;
&lt;p&gt;Thanks for that!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/thread/119442?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2018 23:04:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86e4465d-1201-4026-a5e5-d4cf0503d6cc</guid><dc:creator>JayPRab</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the FAST response!&lt;/p&gt;
&lt;p&gt;Yes. 1mSec rep rate. That is the basis for ALL my timing in my application.&lt;/p&gt;
&lt;p&gt;In the ISR, I up a counter ever time the ISR is hit (for this test)&lt;/p&gt;
&lt;p&gt;So every count represents 1 mSec&lt;/p&gt;
&lt;p&gt;I start the counter.&lt;/p&gt;
&lt;p&gt;In 60,000 visits to the ISR (1 minute), I should have 14,604 counts in CC[0] because my Counter input is 244Hz&lt;/p&gt;
&lt;p&gt;APP_TIMER_PRESCALER is 0&lt;/p&gt;
&lt;p&gt;The inaccuracy is DEFINITELY from the App Timer...&lt;/p&gt;
&lt;p&gt;Hence, my question... How can I get rid of this inaccuracy?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/thread/119441?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2018 22:51:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8f38e1c-8a27-4415-a11f-ec163e2788aa</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;The accuracy of any system is fundamentally driven by it&amp;#39;s clock accuracy.&amp;nbsp; The external RTC is generally a 40ppm clock on most designs. If you happen to have designed out the external RTC then the BLE stack keeps the internal RC based RTC at 250ppm. Any of the main timers on the HF clock are normally 10 or 20 ppm.&lt;/p&gt;
&lt;p&gt;But of course none of this explains why you see such a large error. The answer of course lies in the fact that you coded something using ISR&amp;#39;s to accomplish a timing task and that will never work.&amp;nbsp; The way your tick timer works is to set an RTC for an event and when the event comes through run some code to set future events. The app timer is similar but actually has more code and more latency since it handles more events.&lt;/p&gt;
&lt;p&gt;The very nature of ISR&amp;#39;s means that your clear events will always be late some random amount depending on what the SD was doing and what your code was doing.&amp;nbsp; Also just servicing the ISR alone takes quite a few clocks as there is a lot of work for the processor to do.&lt;/p&gt;
&lt;p&gt;The only way to get an accurate clock is to keep the whole thing in PPI and only use interrupts to keep track of time but never to drive the clock.&lt;/p&gt;
&lt;p&gt;So basically the thing has to wrap around in PPI where when a CC event happens it triggers a clear via PPI but keeps going. You can use the event to trigger an ISR to add to a count but NEVER to actually manipulate the timer.&amp;nbsp; If you want to be really cool about it you can further use PPI to drive a second counter such that you can count for all eternity in hardware but just capture the value of the count register in code whenever you want to know what time it is.&lt;/p&gt;
&lt;p&gt;Just search in the blog for answers/code on this question.&amp;nbsp; It comes up a lot.&lt;/p&gt;
&lt;p&gt;Also if you are just counting out seconds better to use the RTC timers.&amp;nbsp; As RK pointed out you have to request the external HF clock.&amp;nbsp; Otherwise the SD will just run your code on HF int which has a few percent accuracy.&amp;nbsp; Also if you use the RTC you can put the device to sleep and it will still count.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/thread/119439?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2018 22:32:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6a29366-dc49-419e-a380-4dbd8bdc529a</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Have you explicitly started the HFCLOCK in your code? If you haven&amp;#39;t you&amp;#39;re running by default on the internal RC oscillator and that&amp;#39;s going to be very inaccurate.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TickTimer Accuracy</title><link>https://devzone.nordicsemi.com/thread/119438?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2018 22:13:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db3c5848-bae7-4239-824c-620eb39d1d49</guid><dc:creator>Hein</dc:creator><description>&lt;p&gt;You are using an app timer to run a 1ms counter to get the 60 seconds ? What is the app timer prescaler ? It seems likely that the inaccuracy is from the app timer, not from your hardware clocking system ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>