<?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>How to get a accurate millisecond?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40860/how-to-get-a-accurate-millisecond</link><description>Hi , 
 What we want is a accurate ms. 
 below is what we do 1. Set the prescaler config.prescaler = 31; 
 2.When I need the Elapsed ms, First ,I get the elapsed rtc counter by nrf_drv_rtc_counter_get(&amp;amp;m_rtc) And ,the elapsed ms =elapsed rtc *1000/1024</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 26 Nov 2018 10:30:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40860/how-to-get-a-accurate-millisecond" /><item><title>RE: How to get a accurate millisecond?</title><link>https://devzone.nordicsemi.com/thread/158993?ContentTypeID=1</link><pubDate>Mon, 26 Nov 2018 10:30:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:770c2ef5-0ce7-43a0-8e68-7bdb7e2ef72d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;1) I cannot say for sure without seeing your code. However, doing processing in CPU introduces some latency so you will typically get some &amp;quot;jitter&amp;quot; in the time, particularly if higher priority interrupts happen when there should have been some time related CPU activity. If you do it correctly, the average time should be correct though. The app timer is tested and verified to be correct on average.&lt;/p&gt;
&lt;p&gt;2) If you can live with some jitter, then using the app timer is probably the best as it allows you to share a single RTC instance between an arbitrary number of &amp;quot;soft&amp;quot; timers. If you cannot accept the jitter, then you should use a dedicated RTC instance and configure it using PPI and/or shorts so that everything happens in HW.&lt;/p&gt;
&lt;p&gt;3) Both the RTC and app_timer can be trusted. For the RTC, it is always as accurate as your 32 kHz clock source. The app_timer is tested and verified and will be equally accurate to the RTC in the long run but have more jitter. But you need to be aware of those and adjust accordingly. Also, you have not concluded your code, so it could also be that you have a logic flaw in how you do things (for instance a typical &amp;quot;wrong&amp;quot; way of doing things is to read the RTC tick value then clear the RTC. You will typically lose some ticks between these two operations. Even worse - the number of ticks you lose could be difficult to predict, as you risk bad luck and getting a higher priority interrupt between reading the RTC value and clearing it. Therefore, you should use the app_timer if you want to do things in software, as that is a tested and verified implementation).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>