<?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>Occasional long cycles (jitter) on looping timer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64105/occasional-long-cycles-jitter-on-looping-timer</link><description>I use the following code to enable a timer that clears itself to loop continuously via the compare0-clear shortcut. (I then use other compares, PPI, and GPIOTE to output pulses.) The timing is very solid except occasionally (randomly about once per second</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 Jul 2020 16:01:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64105/occasional-long-cycles-jitter-on-looping-timer" /><item><title>RE: Occasional long cycles (jitter) on looping timer</title><link>https://devzone.nordicsemi.com/thread/262049?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2020 16:01:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e2b1dec-9668-4642-84bc-ba0286f357da</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Ok, thanks for reporting back. Glad you figured it out.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Occasional long cycles (jitter) on looping timer</title><link>https://devzone.nordicsemi.com/thread/262045?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2020 15:38:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e274be3-50e2-402a-83e7-83f2e7de5343</guid><dc:creator>Chris Ergo</dc:creator><description>&lt;p&gt;I found the problem. It is in my software. I had added code that resets the timer if interrupts aren&amp;#39;t serviced fast enough and things get out of sync. I need to change how I handle that.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/stian"&gt;Stian Røed Hafskjold&lt;/a&gt;, I&amp;#39;m sorry to bother you with all of this. Thank you for your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Occasional long cycles (jitter) on looping timer</title><link>https://devzone.nordicsemi.com/thread/261951?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2020 11:01:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31759819-2237-468b-a252-fe2b3997d64e</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;That&amp;#39;s interesting. If it is related to RC clock calibration I think the only explanation is that during calibration the HF clock source is switched from HFINT to HFXO, and that these two sources have different accuracy. But then again, you are seeing about 10% difference, and it can&amp;#39;t really be that much drift between the clocks. Also the calibration lasts for 17ms, so then you should have seen several consecutive pulses with extended intervals.&lt;/p&gt;
&lt;p&gt;HFXO is also switched on during regular BLE events. So if you are advertising with a 20ms interval you should see the clock jitter more often, if it is related to the switching between the two sources.&lt;/p&gt;
&lt;p&gt;Actually what you can do to check this is to just start the HFXO right after softdevice init. &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html?cp=4_7_3_1_2_7_2_3#ga3e5afb495a1b0307c749cc268df94a74"&gt;https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.0.1/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html?cp=4_7_3_1_2_7_2_3#ga3e5afb495a1b0307c749cc268df94a74&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then the HFXO will be running all the time and the source will not be changed during calibration.&lt;/p&gt;
&lt;p&gt;Can you also list down the PPI channel numbers, TIMER peripheral number, CC number etc that you are using? Maybe there are some conflicts with the softdevice. e.g. TIMER0 is used by the softdevice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Occasional long cycles (jitter) on looping timer</title><link>https://devzone.nordicsemi.com/thread/261847?ContentTypeID=1</link><pubDate>Mon, 27 Jul 2020 17:02:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25a26e86-e618-407d-bff9-af65cd86d46a</guid><dc:creator>Chris Ergo</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/stian"&gt;Stian Røed Hafskjold&lt;/a&gt; the problem only occurs when the SoftDevice is enabled. A coworker hypothesized that it could be related to the RC clock calibration. Is that possible? I was going to try disabling &lt;em&gt;BLE_COMMON_OPT_EXTENDED_RC_CAL&lt;/em&gt;, but I am using a relatively old SoftDevice (s132 6.0.0) that doesn&amp;#39;t have it. Maybe I should bite the bullet and update my SDK (v15.0.0) and SoftDevice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Occasional long cycles (jitter) on looping timer</title><link>https://devzone.nordicsemi.com/thread/261661?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2020 23:19:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3c82996-e936-42c3-bba4-d6e8deda1a89</guid><dc:creator>Chris Ergo</dc:creator><description>&lt;p&gt;timer_event_handler() is an empty function because I haven&amp;#39;t figure out how to disable the timer interrupt. Would it be worth figuring out how to disable the interrupt?&lt;/p&gt;
&lt;p&gt;Code for initializing the rest of the hardware:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define IR_TIMER_CH_ON          NRF_TIMER_CC_CHANNEL1  // Compare channel to turn on the emitter
#define IR_TIMER_CH_OFF         NRF_TIMER_CC_CHANNEL2  // Compare channel to turn off the emitter
#define IR_ON_POINT_nS              1500000 // 
#define IR_OFF_POINT_nS             2000000 //

    // Compare channels
    time_ticks = timer_ns_to_ticks(&amp;amp;IR_DRV_AND_SAMPLE_TIMER, IR_ON_POINT_nS);
    nrf_timer_cc_write(IR_DRV_AND_SAMPLE_TIMER.p_reg, IR_TIMER_CH_ON, time_ticks);
    time_ticks = timer_ns_to_ticks(&amp;amp;IR_DRV_AND_SAMPLE_TIMER, IR_OFF_POINT_nS);
    nrf_timer_cc_write(IR_DRV_AND_SAMPLE_TIMER.p_reg, IR_TIMER_CH_OFF, time_ticks);

    // PPI
    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    // Set up GPIO and GPIOTE for emitter enable
    nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
    if (!nrfx_gpiote_is_init()) {
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    }
    err_code = nrf_drv_gpiote_out_init(IR_LED_PIN, &amp;amp;config);
    APP_ERROR_CHECK(err_code);
    
    // Assign a timer compare to turn IR emitter ON
    nrf_ppi_channel_t     m_ppi_ch_ir_emitter;
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_ch_ir_emitter);
    APP_ERROR_CHECK(err_code);

    uint32_t event_addr_emitter = nrfx_timer_compare_event_address_get(&amp;amp;IR_DRV_AND_SAMPLE_TIMER,
                                                                       IR_TIMER_CH_ON);
    uint32_t gpiote_task_addr = nrf_drv_gpiote_set_task_addr_get(IR_LED_PIN);
    nrf_drv_gpiote_out_task_enable(IR_LED_PIN);

    err_code = nrf_drv_ppi_channel_assign(m_ppi_ch_ir_emitter, event_addr_emitter, gpiote_task_addr);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_enable(m_ppi_ch_ir_emitter);
    APP_ERROR_CHECK(err_code);

    // Assign a timer compare to turn IR emitter OFF
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_ch_ir_emitter);
    APP_ERROR_CHECK(err_code);

    event_addr_emitter = nrfx_timer_compare_event_address_get(&amp;amp;IR_DRV_AND_SAMPLE_TIMER,
                                                              IR_TIMER_CH_OFF);
    gpiote_task_addr = nrf_drv_gpiote_clr_task_addr_get(IR_LED_PIN);
    nrf_drv_gpiote_out_task_enable(IR_LED_PIN);

    err_code = nrf_drv_ppi_channel_assign(m_ppi_ch_ir_emitter, event_addr_emitter, gpiote_task_addr);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_enable(m_ppi_ch_ir_emitter);
    APP_ERROR_CHECK(err_code);
    
    // Enable timer
    nrfx_timer_clear(&amp;amp;IR_DRV_AND_SAMPLE_TIMER);
    nrf_drv_timer_enable(&amp;amp;IR_DRV_AND_SAMPLE_TIMER);
    
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Yes, there is lots of other code running, including the SoftDevice. I can try disabling (nearly) all of it.&lt;/p&gt;
&lt;p&gt;It may not be relevant, but I needed more than 6 CC channels to control various things (GPIOTE and SAADC), so I have a second timer running simultaneously that is also cleared by CC0 of this first one. I have code that changes SAADC settings in time for the trigger for it over PPI. I am using the SAADC interrupt to trigger the code that does those changes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Occasional long cycles (jitter) on looping timer</title><link>https://devzone.nordicsemi.com/thread/261632?ContentTypeID=1</link><pubDate>Fri, 24 Jul 2020 14:39:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d67ffc0c-558a-48f7-9dcd-61ee0de95e41</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;This is weird. Not sure what is going on here.&lt;/p&gt;
[quote user=""](I then use other compares, PPI, and GPIOTE to output pulses.)[/quote]
&lt;p&gt;Can you show me how this is initialized as well? I see that you enable the interrupt on CC0. Are you using this interrupt, or just CC0 -&amp;gt; PPI -&amp;gt; GPIOTE ?&lt;/p&gt;
&lt;p&gt;Any other code that is running at the same time?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>