<?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>Huge problems with RTC1-&amp;gt;Counter and S310</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/15700/huge-problems-with-rtc1--counter-and-s310</link><description>Hi All, 
 I am using the nrf51422 and softdevice S310 to send out ANT+ and BT Smart in my project. 
 I use RTC1-&amp;gt;Counter in order to get a timestamp for an interrupt from a hall sensor. 
 But the there seem to be something strange going on because</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 12 Aug 2016 13:52:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/15700/huge-problems-with-rtc1--counter-and-s310" /><item><title>RE: Huge problems with RTC1-&gt;Counter and S310</title><link>https://devzone.nordicsemi.com/thread/59947?ContentTypeID=1</link><pubDate>Fri, 12 Aug 2016 13:52:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4a25dc0-eb17-4385-be86-ca1728ac9242</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi Flemming&lt;/p&gt;
&lt;p&gt;Thank you for your question&lt;/p&gt;
&lt;p&gt;I suspect that the RTC1 interrupt handler execution is delay as softdevice activity and other higher priority tasks block the CPU for period of time to service the RTC1 interrupt. You can find delay caused by softdevice in chapter 13 in the &lt;a href="http://infocenter.nordicsemi.com/pdf/S310_SDS_v3.0.pdf"&gt;S310 Softdevice Specification (SDS) document&lt;/a&gt;. Furthermore, if you have your RTC1 interrupt priority as APP_IRQ_PRIORITY_LOW, all softdevice callbacks will block the RTC1 interrupt handler. Setting the RTC1 priority to APP_IRQ_PRIORITY_HIGH however makes it have priority over softdevice callbacks, and I suspect it will make your timing more accurate. Still, BLE events will interrupt or block the application regardsless.  Priority scheme for the nRF51 Cortex-M0 processor is found &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.sds/dita/softdevices/s130/processor_avail_interrupt_latency/exception_mgmt_sd.html?cp=3_6_2_0_15_1"&gt;here&lt;/a&gt;. APP_IRQ_PRIORITY_LOW maps to Cortex-M0 priority 3 and APP_IRQ_PRIORITY_HIGH maps to Cortex-M0 priority 1. Softdevice callbacks have priority 2 and BLE protocol events have priority 0. Lower priority number is higher priority.&lt;/p&gt;
&lt;p&gt;If you want however to get very precise timing, it is hard to do with the RTC. If you get the interrupt from the hall sensor via signal change on a GPIO pin then you could use GPIOTE+PPI+TIMER to get very precise timing. Connect GPIOTE event with TIMER task via PPI channel. Make the TIMER count the time. When signal change occurs on GPIO, GPIOTE event will trigger and immediately trigger TIMER capture event which will capture TIMER counter value into a CC compare register. You can then generate a timer interrupt to read the timer value from the CC compare register in the same way as you have done in the RTC1 interrupt handler. To see how GPIOTE+PPI+TIMER can be set up, look at the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/nrf_gpiote_example.html?cp=6_0_0_4_5_7"&gt;gpiote example&lt;/a&gt; in the SDK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>