<?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>Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/15996/can-the-nrf52-output-the-32-768khz-clock-on-a-gpio</link><description>Can the nRF52 output the 32.768kHz clock on a GPIO. If so, do I need the 32.768kHz xtal, or can I output the generated clock from the 32MHz xtal? I need this clock to sync other ICs.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 02 Sep 2016 10:17:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/15996/can-the-nrf52-output-the-32-768khz-clock-on-a-gpio" /><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61021?ContentTypeID=1</link><pubDate>Fri, 02 Sep 2016 10:17:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d6eb6b9-d8d8-4aa0-819b-137a8cf74ffa</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;i am not aware of any method that you can do it with the MCU.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61020?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 13:56:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc595b54-0419-48e7-896b-c0eab679a6f2</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;I see; didn&amp;#39;t realize the delayed clock was &amp;quot;recalibrated&amp;quot; every clock cycle, which in essence gives you a delayed RTC clock. I suppose this should work; thanks! There&amp;#39;s no way to do the XOR internally to the MCU though, right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61019?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 06:18:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25eb1ea2-70a9-4c59-886e-4b2eee13c2fb</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;They should not drift, like you can see in the code, the rising and falling edge of the generated clock through RTC are resets for the generating the delayed clock edges (In a way the first one is calibrating the second delayed generated clock every cycle). So it should be perfectly calibrated every cycle. I verified it over 50 seconds log and i can confirm that, you can also try this and look in the signal analyzer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61018?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 14:46:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79eb5839-ae6a-4f62-8c01-e75238a8f652</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;XOR is a passive gate; it does not affect timing (other than prop delay).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61017?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 14:44:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04cad9c2-7503-4594-986a-9bbd9fb56aa1</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;One is toggling a GPIO @ 16.384kHz; the other @ 16.394kHz, right? If you take a long capture, won&amp;#39;t you see the pulses deviate from each other?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61016?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 06:33:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d389541-b3ef-471d-a086-0bf235d9ff6a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;are you sure they drift over time? these are outputs from two XTALs (HFCLK and LFCLK) you think XORing them will drift?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61015?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 01:15:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68634135-33da-4278-93a7-8305a596affc</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;I don&amp;#39; think that this will work; the two different clock frequencies (32.768kHz and 32.787kHz) drift over time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61014?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2016 10:31:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61ba84e1-bb45-4371-b127-1ba822028c21</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Try this code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define LFCLK_OUTPUT             (11U)
#define DELAYED_LFCLK_OUTPUT     (12U)


void start_timer(void)
{       
    
        /* Start 16 MHz crystal oscillator */
    NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART    = 1;

    /* Wait for the external oscillator to start up */
    while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0)
    {
        // Do nothing.
    }
    
  NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Timer;  
  NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;       
  NRF_TIMER1-&amp;gt;PRESCALER = 0; 
  NRF_TIMER1-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_16Bit;
  
    // Timer expires 1
  NRF_TIMER1-&amp;gt;CC[0] = 244;  // expires  (1/4)*(1/16384) microseconds
 
}

void lfclk_config()
{
  NRF_CLOCK-&amp;gt;LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);
  NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
  NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;
  while (NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED == 0) {}
      
  NRF_RTC1-&amp;gt;PRESCALER = 0; //1kHz frequency
  NRF_RTC1-&amp;gt;EVTEN     = (RTC_EVTENSET_TICK_Msk ); /* event on COMPARE0 and TICK */

}



int main(void) {

  lfclk_config();
    
  start_timer();

  // configure GPIOTE
  NRF_GPIOTE-&amp;gt;CONFIG[0] = ( (GPIOTE_CONFIG_MODE_Task      &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos)
                          | (LFCLK_OUTPUT                  &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos)
                          | (GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos) )
                          | (0 &amp;lt;&amp;lt; GPIOTE_CONFIG_OUTINIT_Pos);

  // configure timer CC event to toggle  DELAYED_LFCLK_OUTPUT
  NRF_GPIOTE-&amp;gt;CONFIG[1] = ( (GPIOTE_CONFIG_MODE_Task      &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos)
                          | (DELAYED_LFCLK_OUTPUT         &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos)
                          | (GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos) )
                          | (1 &amp;lt;&amp;lt; GPIOTE_CONFIG_OUTINIT_Pos);
    
  // configure PPI  channel 2 convert timer CC event to GPIOTE task out
  NRF_PPI-&amp;gt;CH[2].EEP    = (uint32_t)(&amp;amp;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0]);
  NRF_PPI-&amp;gt;CH[2].TEP    = (uint32_t)(&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[1]);
  NRF_PPI-&amp;gt;CHENSET    |= PPI_CHENCLR_CH2_Msk;  // enable   
  
  // configure PPI  
  NRF_PPI-&amp;gt;CH[0].EEP    = (uint32_t)(&amp;amp;NRF_RTC1-&amp;gt;EVENTS_TICK);
  NRF_PPI-&amp;gt;CH[0].TEP    = (uint32_t)(&amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[0]);
  NRF_PPI-&amp;gt;CHENSET      = PPI_CHENCLR_CH0_Msk;


  // configure PPI  channel 1 to clear timer counter
  NRF_PPI-&amp;gt;CH[1].EEP    = (uint32_t)(&amp;amp;NRF_RTC1-&amp;gt;EVENTS_TICK);
  NRF_PPI-&amp;gt;CH[1].TEP    = (uint32_t)(&amp;amp;NRF_TIMER1-&amp;gt;TASKS_CLEAR);
  NRF_PPI-&amp;gt;CHENSET    |= PPI_CHENCLR_CH1_Msk;  // enable   
        
  NRF_RTC1-&amp;gt;TASKS_START = 1;
  NRF_TIMER1-&amp;gt;TASKS_START = 1;               // Start TIMER1
  
    while (true)
    {
        __SEV();
        __WFE();
        __WFE();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;output is like below
&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/1512.Capture.JPG" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;XOR both outputs and you should have LFCLK with required accuracy. Hopefully the propagation delays within the chip for rerouting events are negligible.&lt;/p&gt;
&lt;p&gt;I understand the TIMER1 (HFCLK) is used to create the second signal, but XORing it with first signal which is generated from RTC (LFCLK). So the signal that is generated by XORing these two should have better accuracy.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61013?ContentTypeID=1</link><pubDate>Mon, 29 Aug 2016 20:11:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e1ed0f3-8742-4c91-9bc0-2368c92ec710</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Let me try to do this tomorrow  morning.  Maybe we can do it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61008?ContentTypeID=1</link><pubDate>Mon, 29 Aug 2016 14:14:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1f299be-77fb-434e-aa80-c9cf3bac78e4</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;I am not following your latest comment...in order to get a 32.768kHz clock I was thinking of XORing the 16.384kHz clock with a delayed version of itself. The link you posted shows how to get a 16.384kHz clock based on the LFCLK, right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61011?ContentTypeID=1</link><pubDate>Fri, 26 Aug 2016 16:12:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff52637b-b350-474b-978e-c1c4de2b5e40</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/question/1111/lfclk-32khz-on-a-gpio-pin-for-precision-measurement/?answer=1112#post-id-1112"&gt;That&lt;/a&gt; could potentially work if the LFCLK-GPIO can be XORed with another delayed LFCLK-GPIO. Can this be done internal to the nRF52?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61012?ContentTypeID=1</link><pubDate>Fri, 26 Aug 2016 06:56:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44f6b3a6-95cb-4250-aebe-62adcf03cb75</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/question/1111/lfclk-32khz-on-a-gpio-pin-for-precision-measurement/?answer=1112#post-id-1112"&gt;this&lt;/a&gt; might be of little help here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61010?ContentTypeID=1</link><pubDate>Thu, 25 Aug 2016 23:01:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a4cdc7a-f2f4-4275-973a-533431ecebe4</guid><dc:creator>Tosa</dc:creator><description>&lt;p&gt;I don&amp;#39;t see how to get 32.768 kHz from this solution. The timer runs off 16MHz (or 1MHz for slow f_timer). The closest I can get is 32.787kHz (if using 16MHz clock), which is over 500ppm off.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can the nRF52 output the 32.768kHz clock on a GPIO?</title><link>https://devzone.nordicsemi.com/thread/61009?ContentTypeID=1</link><pubDate>Thu, 25 Aug 2016 19:55:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db2c8df3-f781-4dd5-aaeb-6a0af53994c4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;&lt;a href="https://github.com/NordicSemiconductor/nrf51-8-mhz-gpio-clock"&gt;here&lt;/a&gt; it gives you an idea of how to generate 8Mhz clock from HFCLK using timer and gpiote. On nrf52 it should be the same logic. Ofcourse to get the lower frequency out you need higher prescaler and different value in TIMER CC&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>