<?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 count timer overflows on a synchronized clock?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27938/how-to-count-timer-overflows-on-a-synchronized-clock</link><description>I am working with a modified project based on the time sync example using two nRF52832 DKs. 
 I want to capture how many times the timer overflows on the receiving board, while being synchronized to the sending board. 
 I created high_freq_timer[2]</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Dec 2017 12:18:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27938/how-to-count-timer-overflows-on-a-synchronized-clock" /><item><title>RE: How to count timer overflows on a synchronized clock?</title><link>https://devzone.nordicsemi.com/thread/110268?ContentTypeID=1</link><pubDate>Wed, 06 Dec 2017 12:18:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b7e5d76-31e6-47ca-9258-90a50c5a4db6</guid><dc:creator>Audun</dc:creator><description>&lt;p&gt;Hi Nick,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure I fully understand the question, and might need some further background information to understand better if the tip below doesn&amp;#39;t make sense.&lt;/p&gt;
&lt;p&gt;When a timing packet is received from a peer device the local synchronization timer is reset/cleared slightly ahead of, or slightly after, the wraparound value (2^24 in this case). As you write, this is done by using CC[2] to trigger the TIMER.CLEAR task.&lt;/p&gt;
&lt;p&gt;In the synchronization code, a PPI channel is used to trigger TIMER.CLEAR from the CC[2] compare event, and another PPI channel is used to disable the first PPI channel such that it only clears the timer once.
Disabling PPI channels via other PPI channels is done using &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/ppi.html?cp=2_1_0_21#concept_sxf_21l_1s"&gt;PPI Channel Groups&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In your case, I recommend adding PPI channel 5 to the &lt;a href="https://github.com/nordic-auko/nRF5-ble-timesync-demo/blob/master/nRF5_SDK_14.2.0_17b948a/examples/ble_peripheral/ble_app_uart/time_sync.c#L593"&gt;PPI Channel group which is disabled when CC[2] fires&lt;/a&gt;. The behavior should be the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A timer packet is received, and an local sync timer adjustment is determined to be required&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nordic-auko/nRF5-ble-timesync-demo/blob/master/nRF5_SDK_14.2.0_17b948a/examples/ble_peripheral/ble_app_uart/time_sync.c#L559"&gt;CC[2] is updated with the adjustment factor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/nordic-auko/nRF5-ble-timesync-demo/blob/master/nRF5_SDK_14.2.0_17b948a/examples/ble_peripheral/ble_app_uart/time_sync.c#L564"&gt;PPI.CHENSET is set to enable all relevant PPI channels, including channel 5&lt;/a&gt; (only update the channel mask value. Adding a second write to the CHENSET register will allow race conditions).&lt;/li&gt;
&lt;li&gt;When CC[2] fires the timer will be cleared as normal, PPI channel 5 will cause TIMER4 counter to increment, and then the PPI group containing all relevant channels will be disabled such that CC[2] doesn&amp;#39;t continuously trigger this behavior.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;
&lt;p&gt;Audun&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>