<?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>Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99283/incorrect-counting-of-the-pulse-period</link><description>Hi, I ran into the following problem: 
 I am counting the period of each pulse during the 10 pulses that come to one of the nRF52833 inputs. I am using nRF Connect SDK and GPIOTE, PPI and TIMER peripherals. 
 The timer is set to a frequency of 16 MHz</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 05 May 2023 08:59:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99283/incorrect-counting-of-the-pulse-period" /><item><title>RE: Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/thread/423921?ContentTypeID=1</link><pubDate>Fri, 05 May 2023 08:59:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8801c5a1-d9a0-458c-96c2-37d66d7120cf</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am glad I could be of help &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The best of luck with your project!&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/thread/423907?ContentTypeID=1</link><pubDate>Fri, 05 May 2023 08:04:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc5ecfd3-a932-4662-b127-54f6092c9f5d</guid><dc:creator>SerhiiR</dc:creator><description>&lt;p&gt;Hi&lt;br /&gt;&lt;br /&gt;Oh, I get it, thanks for your help, you helped me out!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/thread/423906?ContentTypeID=1</link><pubDate>Fri, 05 May 2023 07:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a18efe18-7ca4-4442-8fdc-a923924c7c69</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can keep the GPIOTE interrupt, while also channeling the GPIOTE event to the timer through the PPI.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then the capture will happen immediately through the PPI controller, and the interrupt handler will be triggered some time later allowing you to process the captured value.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As I mentioned there is a risk that the capture will happen multiple times before the pin_handler is allowed to run, so you need to take this into account when processing the capture value.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Assuming the frequency doesn&amp;#39;t change radically from one pulse to the next it should be possible to compensate for this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/thread/423776?ContentTypeID=1</link><pubDate>Thu, 04 May 2023 12:29:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:502b5650-3ea6-46b4-9337-64903c25c522</guid><dc:creator>SerhiiR</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I do have the BLE working.&lt;br /&gt;&lt;br /&gt;Thanks for the very detailed answer, can you tell me how I know that I can pick up values after PPI has done a capture?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/thread/423770?ContentTypeID=1</link><pubDate>Thu, 04 May 2023 12:05:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:703e72c0-7a36-44f1-86b3-c3f4c072ff1c</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Basing the count on the callback is a bit risky, as the callback might be delayed by other higher priority interrupts in the system.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you running Bluetooth or something else that might be interrupting the CPU repeatedly?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think a safer approach would be to use a PPI channel for the capture task rather than the start task. Then you know that even if the pin_handler is delayed the capture will happen on time, and it is just the processing that will be delayed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You might get in a position where the pin_handler is delayed so much that you miss a capture value, but then you should see by the difference in values that an event was missed, and you should be able to compensate for this in your code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Alternatively you can set up a separate timer module in counter mode, and fork the PPI event that triggers the capture to the counter. Then you will be able to count the events in hardware directly, removing any risk of losing events.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/thread/423454?ContentTypeID=1</link><pubDate>Wed, 03 May 2023 07:58:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8db3eb6f-07ef-4740-aed3-3fedcc2a8d68</guid><dc:creator>SerhiiR</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;Here are my settings: &lt;br /&gt;GPIOTE&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    static const nrfx_gpiote_handler_config_t handler_config = {
		.handler = pin_handler,
    };

    nrfx_err_t err;

    err = nrfx_gpiote_init(NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);

    if((err == NRFX_SUCCESS) || (err == NRFX_ERROR_INVALID_STATE))
        {
            err = NRFX_SUCCESS;
            err = nrfx_gpiote_channel_alloc(&amp;amp;(periodPPI_s.gpiote_ch));

            if(err == NRFX_SUCCESS)
                {
                    nrfx_gpiote_input_config_t inCfg = {.pull = NRF_GPIO_PIN_NOPULL};
                    nrfx_gpiote_trigger_config_t trCfg = {
                                                            .trigger = NRFX_GPIOTE_TRIGGER_HITOLO,
                                                            .p_in_channel = &amp;amp;(periodPPI_s.gpiote_ch)};

                    err = nrfx_gpiote_input_configure(gen_out.pin,&amp;amp;inCfg,&amp;amp;trCfg,&amp;amp;handler_config);

                    if(err == NRFX_SUCCESS)
                        {
                            nrfx_gpiote_trigger_enable(gen_out.pin, true);
                        }
                }
        }&lt;/pre&gt;&lt;br /&gt;PPI&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	err = nrfx_gppi_channel_alloc(&amp;amp;(periodPPI_s.gppi_ch));
	NRFX_ASSERT(err == NRFX_SUCCESS);

	nrfx_gppi_channel_endpoints_setup((periodPPI_s.gppi_ch), nrfx_gpiote_in_event_addr_get(gen_out.pin), nrfx_timer_task_address_get(&amp;amp;measureTimer, NRF_TIMER_TASK_START));&lt;/pre&gt;&lt;br /&gt;TIMER&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	err = nrfx_timer_init(&amp;amp;measureTimer, &amp;amp;cfgMeasureTimer, NULL);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I get the timer values from the gpiote handler.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void pin_handler(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t trigger, void *context)
{
    static uint32_t count = 0;
    static uint32_t arrMeas[12] = {0};

    
    nrfx_timer_capture(&amp;amp;measureTimer, NRF_TIMER_CC_CHANNEL0);
    arrMeas[count] = nrfx_timer_capture_get(&amp;amp;measureTimer, NRF_TIMER_CC_CHANNEL0);
    nrfx_timer_clear(&amp;amp;measureTimer);
    
    count++;

    if(count &amp;gt;= 12) {
        nrfx_gpiote_trigger_disable(gen_out.pin);
        nrfx_timer_disable(&amp;amp;measureTimer);

        for(uint8_t i; i &amp;lt; 12; i++) LOG_INF(&amp;quot;%u %u&amp;quot;,i, arrMeas[i]);

    }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incorrect counting of the pulse period</title><link>https://devzone.nordicsemi.com/thread/423449?ContentTypeID=1</link><pubDate>Wed, 03 May 2023 07:38:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfa516f0-8363-421e-9b57-b4aeebb01a37</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How are you taking the measurements?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you using the PPI controller to connect the GPIOTE input to the timer, or are you relying on interrupts?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you share the code you use to configure the GPIOTE, PPI and timer, and measure the length of the pulses?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>