<?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>Calculating ppm offset between the 32khz and the 16mhz clocks</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/36744/calculating-ppm-offset-between-the-32khz-and-the-16mhz-clocks</link><description>I am trying to build a run time test routine that will return the ppm offset between the 32khz and the 16mhz clocks. 
 Can i use PPI to hook 10 clocks 32khz ticks to capture the value of a 16mhz time? 
 Can you instrurct me how to do that? 
 I need to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 31 Jul 2018 14:02:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/36744/calculating-ppm-offset-between-the-32khz-and-the-16mhz-clocks" /><item><title>RE: Calculating ppm offset between the 32khz and the 16mhz clocks</title><link>https://devzone.nordicsemi.com/thread/142210?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2018 14:02:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:488a8ebf-2c5d-414e-ba0a-ef6a0f8904ef</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;The way I read your code, you should only be affected by the compare-compare jitter as the timer is started and stopped by compare events via PPI. You could perhaps let the test run for a longer time to get a more exact average.&lt;/p&gt;
&lt;p&gt;If the accuracy you have measured is correct, then there could be an issue with your LF oscillator. Are you using a crystal or the internal RC? If you use the internal RC, then&amp;nbsp; you should calibrate it regularly. If you are using a crystal, then you need to make sure that you have proper load capacitors.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculating ppm offset between the 32khz and the 16mhz clocks</title><link>https://devzone.nordicsemi.com/thread/141846?ContentTypeID=1</link><pubDate>Mon, 30 Jul 2018 08:22:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8688aa8a-4011-4f99-adcb-95afdc248d91</guid><dc:creator>Omri Friedman</dc:creator><description>&lt;p&gt;I have implemented the ppm test code mentioned above, but i get offset of ~4000ppm between the 32768hz and the 16mhz&amp;nbsp; clocks.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I read this&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Frtc.html"&gt;http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Frtc.html&lt;/a&gt;&amp;nbsp;and wondered if that has to do with my results.&lt;/p&gt;
&lt;p&gt;I saw in the link&amp;nbsp;&lt;span&gt;15 to 46 &amp;mu;s delay on task&amp;nbsp;&lt;/span&gt;&lt;span&gt;START and&amp;nbsp;+/- 15 &amp;mu;s on &amp;quot;START to COUNTER increment&amp;quot; and&amp;nbsp;+/- 62.5 ns on &amp;quot;COMPARE to COMPARE&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I start the RTC and use CC[0] and CC[1] to trigger capture of TIMER2 (via PPI). then i use the delta to calculate ppm offset.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Which of the above jitters/delays should i expect? just the&amp;nbsp;+/- 62.5 ns?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculating ppm offset between the 32khz and the 16mhz clocks</title><link>https://devzone.nordicsemi.com/thread/141075?ContentTypeID=1</link><pubDate>Tue, 24 Jul 2018 06:00:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a7ab872-9a37-46a4-8a04-73644c8693b8</guid><dc:creator>Omri Friedman</dc:creator><description>&lt;p&gt;Thanks a lot.&lt;/p&gt;
&lt;p&gt;I have written a quick code without testing it yet.&lt;/p&gt;
&lt;p&gt;Is it in line with your suggestion?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void ppm_test(void)
{
  // user RTC2 to count 32khz tick via its compare registers 
  NRF_RTC2-&amp;gt;PRESCALER = 0;
  NRF_RTC2-&amp;gt;EVTENSET = RTC_EVTENCLR_COMPARE0_Enabled | RTC_EVTENCLR_COMPARE1_Enabled;
  NRF_RTC2-&amp;gt;CC[0] = 1;  // get 1st tick 
  NRF_RTC2-&amp;gt;CC[1] = 21; // get 21th tick 
  
  // get interrupt on RTC2 CC[1] 
  NRF_RTC2-&amp;gt;INTENSET = RTC_INTENSET_COMPARE1_Enabled; 
  NVIC_ClearPendingIRQ(RTC2_IRQn);
  NVIC_EnableIRQ(RTC2_IRQn);
  
  // use TIMER2 capture counting 16mhz ticks  
  NRF_TIMER2-&amp;gt;MODE = (TIMER_MODE_MODE_Timer &amp;lt;&amp;lt; TIMER_MODE_MODE_Pos); 
  NRF_TIMER2-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit;
  NRF_TIMER2-&amp;gt;PRESCALER = 0; // 16mhz 
  NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;

  // use ppi to hook RTC compare and to timer capture 
  NRF_PPI-&amp;gt;CH[0].EEP = (uint32_t) &amp;amp;NRF_RTC2-&amp;gt;EVENTS_COMPARE[0]; 
  NRF_PPI-&amp;gt;CH[0].TEP = (uint32_t) &amp;amp;NRF_TIMER2-&amp;gt;TASKS_CAPTURE[0]; 
  NRF_PPI-&amp;gt;CH[1].EEP = (uint32_t) &amp;amp;NRF_RTC2-&amp;gt;EVENTS_COMPARE[1]; 
  NRF_PPI-&amp;gt;CH[1].TEP = (uint32_t) &amp;amp;NRF_TIMER2-&amp;gt;TASKS_CAPTURE[1]; 
  NRF_PPI-&amp;gt;CHENSET = (PPI_CHENSET_CH0_Enabled &amp;lt;&amp;lt; PPI_CHENSET_CH0_Pos) | 
                     (PPI_CHENSET_CH1_Enabled &amp;lt;&amp;lt; PPI_CHENSET_CH1_Pos); 

  // enable it all 
  NRF_TIMER2-&amp;gt;TASKS_START = 1; 
  NRF_RTC2-&amp;gt;TASKS_START = 1; 
}

// interrupt on compare 1 
void TIMER2_IRQHandler(void)
{
  NVIC_ClearPendingIRQ(TIMER2_IRQn);
  NVIC_DisableIRQ(TIMER2_IRQn);

  int delta = NRF_TIMER2-&amp;gt;CC[1] - NRF_TIMER2-&amp;gt;CC[0];
  
  // in there are 100000 16mhz ticks in 20 32khz tick (as if it is a 1.6khz)
  ppm = (delta - 100000) * ( 1000000 / 100000 );

  // disable it all 
  NRF_TIMER2-&amp;gt;TASKS_STOPT = 1; 
  NRF_RTC2-&amp;gt;TASKS_STOP = 1; 
  NRF_PPI-&amp;gt;CHENCLR = (PPI_CHENCLR_CH0_Clear &amp;lt;&amp;lt; PPI_CHENCLR_CH0_Pos) | 
                      PPI_CHENCLR_CH1_Clear &amp;lt;&amp;lt; PPI_CHENCLR_CH1_Pos);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Calculating ppm offset between the 32khz and the 16mhz clocks</title><link>https://devzone.nordicsemi.com/thread/141036?ContentTypeID=1</link><pubDate>Mon, 23 Jul 2018 17:49:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14d8791f-bcf2-4f69-9796-b82f6feaa294</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;You can try connecting the COMPARE0/COMPARE1 events in an RTC (I&amp;#39;d use RTC2) to the CAPTURE[0]/CAPTURE[1] task in a timer via two PPI channels. Most examples leave TIMER2 instance free to use. The time will be measured in the CC[1]-CC[0] difference of the running timer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>