<?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>2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34911/2-timers-as-counter-with-external-input-capture-pin</link><description>Hi. I have to make mesuring impulses quantity of two external low freq signals without interrupts. 
 I tried to use GPIOTE EVENTS_IN[0] and 1 with PPI ch 0 and 1 to timer 2 and 3 TASKS_COUNT generate. it works, but when the event on pins polarity change</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Jun 2018 09:51:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34911/2-timers-as-counter-with-external-input-capture-pin" /><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/135107?ContentTypeID=1</link><pubDate>Thu, 07 Jun 2018 09:51:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ae6152f-ddd0-4d74-8cfe-d6f27fa758db</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;Yes. I have found that relay works incorrect&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/135077?ContentTypeID=1</link><pubDate>Thu, 07 Jun 2018 08:01:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0064ff42-1e78-4c74-947d-2e54a1c615c0</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Just to confirm; the source of the issue has been found?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/135041?ContentTypeID=1</link><pubDate>Thu, 07 Jun 2018 05:13:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:582b8093-4f60-4c2a-bdca-8ce76e60778c</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;oh, i find, one of my relay time-to-time works incorrect.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/135039?ContentTypeID=1</link><pubDate>Thu, 07 Jun 2018 05:03:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d83681e3-e32e-4583-8361-2ea08cf81db6</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;Ok.I took an experiment using nrf51 pca10001 board. i had the same problem on nrf51, but when i had used errata&amp;nbsp;&lt;span&gt;code ,&amp;nbsp; nrf51 code starts to work well! no double events.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void GPIOTE_IRQHandler(void)
{
		if(NRF_GPIOTE-&amp;gt;EVENTS_IN[0] == 1)
		{	
			NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
			counter1++;

		}
		if(NRF_GPIOTE-&amp;gt;EVENTS_IN[1] == 1)
		{			
			NRF_GPIOTE-&amp;gt;EVENTS_IN[1] = 0;
			counter2++;
		}
}
...
...
...
nrf_gpio_cfg_input(0, GPIO_PIN_CNF_PULL_Pullup);
nrf_gpio_cfg_input(1, GPIO_PIN_CNF_PULL_Pullup);

*(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 0)) = 1;
*(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 1)) = 1;

NRF_GPIOTE-&amp;gt;CONFIG[0] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
												0 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos												 |	
												GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos;

NRF_GPIOTE-&amp;gt;CONFIG[1] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
												1 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos												 |	
												GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos;	

NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
NRF_GPIOTE-&amp;gt;EVENTS_IN[1] = 0;

NRF_GPIOTE-&amp;gt;INTENSET = GPIOTE_INTENSET_IN0_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN0_Pos | 
											 GPIOTE_INTENSET_IN1_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN1_Pos ; 

NRF_GPIOTE-&amp;gt;POWER = 	GPIOTE_POWER_POWER_Enabled &amp;lt;&amp;lt; GPIOTE_POWER_POWER_Pos;
NVIC_EnableIRQ(GPIOTE_IRQn);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then i remake code for nrf 52&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void GPIOTE_IRQHandler(void)
{
		if(NRF_GPIOTE-&amp;gt;EVENTS_IN[0] == 1)
		{	
			NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
			counter1++;
		}
		if(NRF_GPIOTE-&amp;gt;EVENTS_IN[1] == 1)
		{			
			NRF_GPIOTE-&amp;gt;EVENTS_IN[1] = 0;
			counter2++;
		}
}
...
...
...
nrf_gpio_cfg_input(3, GPIO_PIN_CNF_PULL_Pullup);
nrf_gpio_cfg_input(4, GPIO_PIN_CNF_PULL_Pullup);

*(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 0)) = 1;
*(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 1)) = 1;

NRF_GPIOTE-&amp;gt;CONFIG[0] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
						3 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos												 |	
						GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos;

NRF_GPIOTE-&amp;gt;CONFIG[1] = GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
						4 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos												 |	
						GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos;	

NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
NRF_GPIOTE-&amp;gt;EVENTS_IN[1] = 0;

NRF_GPIOTE-&amp;gt;INTENSET = GPIOTE_INTENSET_IN0_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN0_Pos | 
					   GPIOTE_INTENSET_IN1_Enabled &amp;lt;&amp;lt; GPIOTE_INTENSET_IN1_Pos ; 

NVIC_SetPriority(2, GPIOTE_IRQn);
NVIC_DisableIRQ(GPIOTE_IRQn);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But for nrf52 it doesnt works, it always has double event for EVENTS_IN[1]&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/135005?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 19:02:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b88b208-3f30-435b-8f00-a713c1a19f0f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;It&amp;nbsp;is not the pin used, but the GPIOTE-&amp;gt;IN[] instance used. If there are no other IN channels in use, then this is 0 and 1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134992?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 15:57:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e26e3fc-c13d-48a6-bd20-e9baa977d04b</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;Yes, i tried, i use&amp;nbsp;construction from errata with in GPIOTE initialising.&amp;nbsp;&lt;code&gt;if GPIOTE_CH_USED  is pin number like 4 or 5, i made it write. But it has no effect.&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;
&lt;pre class="pre codeblock"&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134941?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 12:35:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a7533c8-908b-4ed9-b21b-f4f3ae132efa</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Could you try to enable this errata workaround, just to see if the two signals are triggered, at some point, very close together?&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev2.errata/dita/errata/nRF52832/Rev2/latest/anomaly_832_155.html?cp=2_1_1_0_1_41"&gt;http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev2.errata/dita/errata/nRF52832/Rev2/latest/anomaly_832_155.html?cp=2_1_1_0_1_41&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134922?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 11:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0198fb1d-ce98-41b1-b5b4-2980bd18df7c</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;All the same. RTT&amp;nbsp;does not affect&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134908?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 11:32:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:076ed8bf-e444-42bf-8df5-e3c3878fb836</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;I assume your inputs should then alternate between CNT1 and CNT2, ie: the input signal phase is 0/180 degrees.&lt;/p&gt;
&lt;p&gt;Could you try to omit RTT, and do something like this to see if this might be a RTT polling/buffering issue?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
        static nrf_drv_gpiote_pin_t last_pin;
		if( pin == 4 )
		{	
			counter1++;
			//SEGGER_RTT_WriteString(0,&amp;quot;CNT1\r\n&amp;quot;);
		}
		else if( pin == 5 )
		{			
			counter2++;
			//SEGGER_RTT_WriteString(0,&amp;quot;CNT2\r\n&amp;quot;);
		}
		if (pin == last_pin)
		{
		  // Same evt happen twice in a row.
		  static uint32_t double_count;
		  double_count++;
		}
		last_pin = pin;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134890?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 10:53:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38568a7b-3bd4-4064-8490-b630ed09df81</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;With PPi or not, it has double event. There is no pulses (i use cap 0.1 uf&amp;nbsp;on input pins). Variables are volatile but&amp;nbsp;SEGGER_RTT_WriteString(0,&amp;quot;CNT2\r\n&amp;quot;); prints twice&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134888?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 10:44:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:181dfecd-5337-494f-9fb5-a47c10221f72</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Your code does not use PPI. Do you still see double-events with this code? Have you scoped pin 5 to see if there are any glitches or pulses that might account for this double increment?&lt;/p&gt;
&lt;p&gt;Is your counter values declared as volatile? This is important when variables are used in interrupt vectors.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134885?ContentTypeID=1</link><pubDate>Wed, 06 Jun 2018 10:23:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6071afc1-5691-4a53-9615-337eb1936d4a</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;Delay between signals 1 - 1.5 ms/&lt;/p&gt;
&lt;p&gt;Code (next i remake without ppi)&lt;/p&gt;
&lt;p&gt;void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)

		if( pin == 4 )
		{	
			counter1++;
			SEGGER_RTT_WriteString(0,&amp;quot;CNT1\r\n&amp;quot;);
		}
		else if( pin == 5 )
		{			
			counter2++;
			SEGGER_RTT_WriteString(0,&amp;quot;CNT2\r\n&amp;quot;);
		}
}

static void buttons_leds_init(bool * p_erase_bonds)
{
	nrf_gpio_cfg_output(17);
	nrf_gpio_cfg_output(18);
	nrf_gpio_cfg_output(19);
	nrf_gpio_cfg_output(20);
	nrf_gpio_pin_set(17);
	nrf_gpio_pin_set(18);
	nrf_gpio_pin_set(19);
	nrf_gpio_pin_set(20);

	err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
	
    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;
    nrf_drv_gpiote_in_init(4, &amp;amp;in_config, in_pin_handler);
    nrf_drv_gpiote_in_event_enable(4, true);
    nrf_drv_gpiote_in_init(5, &amp;amp;in_config, in_pin_handler);
    nrf_drv_gpiote_in_event_enable(5, true);
    
    NVIC_SetPriority(2, GPIOTE_IRQn);
    NVIC_DisableIRQ(GPIOTE_IRQn);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;cnt2 sets twice&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 2 Timers as counter with  external input capture pin</title><link>https://devzone.nordicsemi.com/thread/134032?ContentTypeID=1</link><pubDate>Wed, 30 May 2018 12:47:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:003c9621-e9a5-4b22-a29c-3cd8ac54b794</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you share a piece of the code where you tie everything together, so I can look at the logic?&lt;/p&gt;
&lt;p&gt;Are the signals occurring within a very short period of time? If yes, then it might be that you are running into this errata:&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev1.errata/anomaly_832_155.html?cp=2_1_1_1_1_44"&gt;http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev1.errata/anomaly_832_155.html?cp=2_1_1_1_1_44&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>