<?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>Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95651/using-timer-to-count-pulse-width-on-interrupt-pin</link><description>Hi! I&amp;#39;m trying to use a counter to count the pulse widths of an IR signal packet everytime it tirggers an event on a GPIO, however I&amp;#39;ve been going in loops without sucess. 
 Here is my current code: 
 
 I&amp;#39;ve used both methods to count pulse_duration incluing</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 15 Feb 2023 09:11:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95651/using-timer-to-count-pulse-width-on-interrupt-pin" /><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/410005?ContentTypeID=1</link><pubDate>Wed, 15 Feb 2023 09:11:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1f745d5-688a-4112-aec3-3d8e69c0eb03</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Thanks a lot for sharing the solution, good to hear you were able to get it to work!&lt;/p&gt;
&lt;p&gt;I will close the ticket then.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/409934?ContentTypeID=1</link><pubDate>Tue, 14 Feb 2023 17:05:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f2bf773-1263-4c59-b23b-ad7b5e173d67</guid><dc:creator>Gabriel Pinto</dc:creator><description>&lt;p&gt;Just to give some closure to ths thread, I did manage to implement this with a help of a colleague, but not following this method, as I couldn&amp;#39;t figure out what was wrong.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What we did was use the timers with a resolution of 10us, to count each time there was an interrupt on the GPIOTE peripheral activated by a toggle of the pin, this proved to be enough&amp;nbsp;as I didn&amp;#39;t exactly need to know the time of pulse in the &amp;quot;high&amp;quot; state, but only the duration between the pin toggles. With a state machine I then managed to parse the durations in accordance to the protocol type I was expecting (NEC IR protocol).&lt;/p&gt;
&lt;p&gt;Best regards, and thanks for the support.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/407745?ContentTypeID=1</link><pubDate>Thu, 02 Feb 2023 11:43:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38b1ccb3-00b8-4cec-b460-b4493de9c398</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I mean that you configure the GPIOTE by writing to the CONFIG registers directly, using hard coded indexes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_GPIOTE-&amp;gt;CONFIG[0] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
						GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
						IR_RECEIVER_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
NRF_GPIOTE-&amp;gt;CONFIG[1] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
						GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
						IR_RECEIVER_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;&lt;/pre&gt;&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: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/407631?ContentTypeID=1</link><pubDate>Wed, 01 Feb 2023 17:13:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:272fec53-332c-46db-99e1-3b99c3130ce7</guid><dc:creator>Gabriel Pinto</dc:creator><description>&lt;p&gt;Hi Torbjorn.&lt;/p&gt;
&lt;p&gt;By hard coding, do you mean just assigning the PPI channel to the GPIOTE channel this way?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    nrfx_ppi_channel_alloc(&amp;amp;ppi_channel_a);
    nrfx_ppi_channel_assign(ppi_channel_a,(uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[0], nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_START));
    nrfx_ppi_channel_fork_assign(ppi_channel_a, nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_CLEAR));
    nrfx_ppi_channel_enable(ppi_channel_a);

    nrfx_ppi_channel_alloc(&amp;amp;ppi_channel_b);
    nrfx_ppi_channel_assign(ppi_channel_b,(uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[1], nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_STOP));
    nrfx_ppi_channel_fork_assign(ppi_channel_b, nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_CAPTURE0));
    nrfx_ppi_channel_enable(ppi_channel_b);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m assuming it starts by assigning channel 0, 1 and so on. However just by doing this I&amp;#39;m not getting any&amp;nbsp;results inn my main loop.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the full code on my main function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    nrf_drv_gpiote_in_config_t in_config_1 = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    nrf_drv_gpiote_in_config_t in_config_2 = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    nrfx_gpiote_in_init(IR_RECEIVER_PIN, &amp;amp;in_config_1, gpiote_handler);
    nrfx_gpiote_in_init(IR_RECEIVER_PIN, &amp;amp;in_config_2, gpiote_handler);
    nrf_drv_gpiote_in_event_enable(IR_RECEIVER_PIN, true);

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&amp;amp;m_timer, &amp;amp;timer_cfg, NULL);
    APP_ERROR_CHECK(err_code);
    nrf_drv_timer_enable(&amp;amp;m_timer);

    nrfx_ppi_channel_alloc(&amp;amp;ppi_channel_a);
    nrfx_ppi_channel_assign(ppi_channel_a,(uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[0], nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_START));
    nrfx_ppi_channel_fork_assign(ppi_channel_a, nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_CLEAR));
    nrfx_ppi_channel_enable(ppi_channel_a);

    nrfx_ppi_channel_alloc(&amp;amp;ppi_channel_b);
    nrfx_ppi_channel_assign(ppi_channel_b,(uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[1], nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_STOP));
    nrfx_ppi_channel_fork_assign(ppi_channel_b, nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_CAPTURE0));
    nrfx_ppi_channel_enable(ppi_channel_b);

    // Enter main loop.
    for (;;) {
      idle_state_handle();
      pulse_length = nrfx_timer_capture_get(&amp;amp;m_timer, NRF_TIMER_CC_CHANNEL0);
      NRF_LOG_INFO(&amp;quot;PULSE LENGTH: %u&amp;quot;,pulse_length);
      nrf_delay_ms(1000);
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;To clarify the NRF_LOG_INFO just prints 0 on the pulse length.&lt;/p&gt;
&lt;p&gt;Am I missing something?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you and best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/406806?ContentTypeID=1</link><pubDate>Fri, 27 Jan 2023 09:31:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:accf783e-e7ba-4ca8-99e3-13007f6f6a58</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My bad, I didn&amp;#39;t realize you were using the nRF5 SDK...&lt;/p&gt;
&lt;p&gt;You can just hard code the channels. The GPIOTE peripheral has 8 channels in total, which means channel indexes in the range 0 to 7 are available.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is just critical to ensure that if you have other parts of your application using the nrf_gpiote driver you don&amp;#39;t get a conflict where you are trying to use the same GPIOTE channels multiple places.&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: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/406656?ContentTypeID=1</link><pubDate>Thu, 26 Jan 2023 12:52:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7891ee2b-5b42-4dbc-81ea-b8ee089ec118</guid><dc:creator>Gabriel Pinto</dc:creator><description>&lt;p&gt;Hello Torbjorn.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I just checked the nrfx_gpiote drivers and the&amp;nbsp;nrfx_gpiote_channel_alloc() function doesn&amp;#39;t seem to exist, that&amp;#39;s why I tried to translate the code Jared provided to my case.&lt;/p&gt;
&lt;p&gt;According to those drivers the allocation is done automatically through the in_init function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrfx_err_t nrfx_gpiote_in_init(nrfx_gpiote_pin_t pin, nrfx_gpiote_in_config_t const * p_config, nrfx_gpiote_evt_handler_t evt_handler)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Of course this function assumes I have previously declared a config before as in:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrf_drv_gpiote_in_config_t in_config_1 = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But through this method I&amp;#39;m not associating a channel to LoToHi and HiToLo events and this way I don&amp;#39;t know how to assign the different PPI channels to each event.&lt;/p&gt;
&lt;p&gt;Is there any other way to do this?&lt;/p&gt;
&lt;p&gt;Thank you for your support.&lt;/p&gt;
&lt;p&gt;Best regards.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/406636?ContentTypeID=1</link><pubDate>Thu, 26 Jan 2023 12:05:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3473270f-cc61-4584-b0f5-81c0c63e5e16</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Gabriel&lt;/p&gt;
&lt;p&gt;Jared is currently unavailable, and I will help you out in the mean time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The nrfx_gpiote driver is a bit limited if you want to assign multiple GPIOTE channels to the same pin, since the pin is used to index the different channels rather than the channel index.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In this case I think you would have to use the nrfx_gpiote driver only for allocating the channels, using the nrfx_gpiote_channel_alloc(uint8_t * p_channel) function, and then configure the channels directly using the NRF_GPIOTE-&amp;gt;CONFIG[ch] registers. Then you need to use the channel index provided by the alloc function as an index in the CONFIG register.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Small example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define IR_PIN 9
uint8_t gpiote_ch_a, gpiote_ch_b;
nrfx_gpiote_channel_alloc(&amp;amp;gpiote_ch_a);
nrfx_gpiote_channel_alloc(&amp;amp;gpiote_ch_b);
NRF_GPIOTE-&amp;gt;CONFIG[gpiote_ch_a] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
						GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
						IR_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;
NRF_GPIOTE-&amp;gt;CONFIG[gpiote_ch_b] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
						GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
						IR_PIN &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos;&lt;/pre&gt;&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: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/406105?ContentTypeID=1</link><pubDate>Mon, 23 Jan 2023 17:41:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51171511-6cf1-4b3a-8982-c434137a44c5</guid><dc:creator>Gabriel Pinto</dc:creator><description>&lt;p&gt;Hi Jared, thanks for the example, I have a question though.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How do I assign the different ppi channels to the different gpiote configs? I have these two configs:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;nrf_drv_gpiote_in_config_t in_config_1 = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
nrf_drv_gpiote_in_config_t in_config_2 = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
nrfx_gpiote_in_init(IR_RECEIVER_PIN, &amp;amp;in_config_1, gpiote_handler);
nrfx_gpiote_in_init(IR_RECEIVER_PIN, &amp;amp;in_config_2, gpiote_handler);&lt;/pre&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;But when I assign the ppi channels I&amp;#39;m doing the following:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    nrfx_ppi_channel_alloc(&amp;amp;ppi_channel_a);
    nrfx_ppi_channel_assign(ppi_channel_a, nrfx_gpiote_in_event_addr_get(IR_RECEIVER_PIN), nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_START));
    nrfx_ppi_channel_fork_assign(ppi_channel_a, nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_CLEAR));
    nrfx_ppi_channel_enable(ppi_channel_a);

    nrfx_ppi_channel_alloc(&amp;amp;ppi_channel_b);
    nrfx_ppi_channel_assign(ppi_channel_b, nrfx_gpiote_in_event_addr_get(IR_RECEIVER_PIN), nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_STOP));
    nrfx_ppi_channel_fork_assign(ppi_channel_b, nrfx_timer_task_address_get(&amp;amp;m_timer, NRF_TIMER_TASK_CAPTURE0));
    nrfx_ppi_channel_enable(ppi_channel_b);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However this doesn&amp;#39;t seem to be assigning the PPI to LOTOHI and HITOLO events but rather any gpiote event. Am I missing something? Can I configure GPIOTE channels in a different way?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/405527?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2023 15:34:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93ebced4-57d2-44a1-83ea-02069c46cc31</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sorry for the late reply, I was looking for other threads that might had done the same and I see that I sent you the wrong one. I was supposed to send you &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/93005/pulse-width-counter-using-peripheral-only/391337"&gt;this&lt;/a&gt;&amp;nbsp;example that my colleague Torbj&amp;oslash;rn made for Zephyr. It should be a small task to port it to nRF5SDK. Come back to me if you&amp;#39;re not able to port it and I&amp;#39;ll do it... Either way this is the correct one.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5736.pulse_5F00_length_5F00_measurement.zip"&gt;devzone.nordicsemi.com/.../5736.pulse_5F00_length_5F00_measurement.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/404847?ContentTypeID=1</link><pubDate>Fri, 13 Jan 2023 15:16:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ace1e3a-8f05-4697-bd44-90a630dae2ec</guid><dc:creator>Gabriel Pinto</dc:creator><description>&lt;p&gt;Hi Jared, Thank you for your answer.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been reading that thread before, but I always assumed that my application was supposed to be simpler.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Am I then to assume that measuring an IR signal requires either 2 simultaneous timers, or GPIOTE + TIMER + PPI? Or is this possible with only GPIOTE + TIMER like I&amp;#39;m doing?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Neither of the examples of your colleague Jorgen seems to directly correspond to my situation, which one should I follow?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using timer to count pulse width on interrupt pin</title><link>https://devzone.nordicsemi.com/thread/404811?ContentTypeID=1</link><pubDate>Fri, 13 Jan 2023 13:23:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2acf3160-8c72-47f0-ad8e-885e3b1038da</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;My colleague Jørgen has already shared a project on how to implement this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/34547/ppi-configuration-to-count-pulses/133136"&gt;here&lt;/a&gt;. Could you take a look at it?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>