<?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>Jitter on Timer1+PPI+GPIOTE?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37621/jitter-on-timer1-ppi-gpiote</link><description>I need to implement a 4kHz signal to drive a buzzer on a custom board of nRF51822 with external 16MHz and 32kHz crystal. 
 I am using Timer1+PPI+GPIOTE to generate this 4kHz signal. 
 Unfortunately there is sound distortion issue. 
 Measured by CRO, the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Aug 2018 03:41:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37621/jitter-on-timer1-ppi-gpiote" /><item><title>RE: Jitter on Timer1+PPI+GPIOTE?</title><link>https://devzone.nordicsemi.com/thread/145205?ContentTypeID=1</link><pubDate>Wed, 22 Aug 2018 03:41:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4e52b42-fb5c-4961-b2f9-e68f72df9fe7</guid><dc:creator>Motti Ng</dc:creator><description>&lt;p&gt;I changed the HFCLKSTART to use sd_clock_hfclk_request() instead of NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART.&lt;/p&gt;
&lt;p&gt;It works! Now the 4kHz signal has no jittering and the distorted sound disappeared.&lt;/p&gt;
&lt;p&gt;I will mark your reply as answer. Thank you!&lt;/p&gt;
&lt;p&gt;Below is the modified code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void buzzer_service(){
	uint32_t is_hfclk_running = 0;
	if (m_main_flag.buzzer_flag){
		sd_clock_hfclk_request();
		do{
			sd_clock_hfclk_is_running(&amp;amp;is_hfclk_running);
		}while(is_hfclk_running != 1);
		
		nrf_drv_gpiote_out_task_enable(BUZZER_PIN_0);
		nrf_drv_timer_enable(&amp;amp;timer1);
	}else{
		sd_clock_hfclk_is_running(&amp;amp;is_hfclk_running);
		if (is_hfclk_running == 1){
			sd_clock_hfclk_release();
		}
		nrf_drv_gpiote_out_task_disable(BUZZER_PIN_0);
		nrf_drv_timer_disable(&amp;amp;timer1);
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Jitter on Timer1+PPI+GPIOTE?</title><link>https://devzone.nordicsemi.com/thread/145201?ContentTypeID=1</link><pubDate>Wed, 22 Aug 2018 02:03:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9875b8d8-b281-462d-a1b9-7b7faf6ee2b1</guid><dc:creator>Motti Ng</dc:creator><description>&lt;p&gt;I am using SDK v11.0 and softdevice S130 v2.0.0.&lt;/p&gt;
&lt;p&gt;I am sorry it is a typo that the crystal used should be 16MHz.&lt;/p&gt;
&lt;p&gt;I added HFCLKSTART task as shown below, however I did not see any big different:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void buzzer_service(){
	if (m_main_flag.buzzer_flag){
	    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
        /* Wait for the external oscillator to start up */
        while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);
        NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
	
		nrf_drv_gpiote_out_task_enable(BUZZER_PIN_0);
		nrf_drv_timer_enable(&amp;amp;timer1);
	}else{
		nrf_drv_gpiote_out_task_disable(BUZZER_PIN_0);
		nrf_drv_timer_disable(&amp;amp;timer1);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I will update this post to include screenshots.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Jitter on Timer1+PPI+GPIOTE?</title><link>https://devzone.nordicsemi.com/thread/145156?ContentTypeID=1</link><pubDate>Tue, 21 Aug 2018 14:08:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fbc97f9-f9a0-4463-a45d-8fac60e75a69</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you show a screenshot of the jitter?&lt;/p&gt;
&lt;p&gt;What SDK are you using?&lt;/p&gt;
&lt;p&gt;Are you really using a 12 MHz crystal or is that a typo? nRF51 only supports 16 or 32 MHz crystals.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tested your code and was caught off guard by this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/20843/not-in-changelist---change-to-nrf_drv_timer-c-in-sdk-13-0-0"&gt;bug/feature&lt;/a&gt;. With SDK 12.3.0 you are not allowed to pass NULL as config parameter to nrf_drv_timer_init() (even though it says so in the documentation). The result of passing NULL is a randomly configured timer.&lt;/p&gt;
&lt;p&gt;Anyway, after configuring the timer correctly&amp;nbsp;I&amp;#39;m seeing a jitter of max 0.1 us and about 0.35 % error on the frequency. Note that to get an as accurate clock as possible you need to explicitly turn on the HF crystal using the NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART task or&amp;nbsp;&lt;a title="sd_clock_hfclk_request" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.api.v2.0.1/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html?cp=3_7_2_1_0_2_7_2_3#ga3e5afb495a1b0307c749cc268df94a74"&gt;sd_clock_hfclk_request&lt;/a&gt;() if you are using a Softdevice. Otherwise the Timer will use the internal RC Oscillator which&amp;nbsp;has a typical accuracy of only ~5 %.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>