<?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>measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9036/measuring-input-gpio-pin-frequency-with-soft-device-running</link><description>Hello, 
 is it possible to measure frequency from 1Hz up to 400kHz (50% duty cycle) on gpio pin having soft device enabled with Peripheral functionality? The measurement will be invoked on demand by the connected central device. I will use nRF51822,</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 12 Dec 2021 05:35:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9036/measuring-input-gpio-pin-frequency-with-soft-device-running" /><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/343017?ContentTypeID=1</link><pubDate>Sun, 12 Dec 2021 05:35:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20226f6d-107d-4a71-829b-b8ec57f69802</guid><dc:creator>thenagi</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/adriand"&gt;adriand&lt;/a&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Followed same stratergy , same code for a similar requriment if frequency measurement. Able to get frequency count in gpio. But when we left it for a long run of 48 hours, we observed a one side always decreasing frequency. Screenshot of counter shared. We know both external source frequency and hfclk will have some temperature component. But instead of periodic ups and down it just kept on decreasing one way. We are yet to found a reasonable explanation fir this. External frequency is tested with with another probe and result in a fix frequency slightly going up and down with ambient temperature in a day cycle. Any pointer regarding this is highly appreciated.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;48hour frequency reading&lt;/p&gt;
&lt;p&gt;&lt;a href="https://drive.google.com/file/d/1G5xzhS_Ezr-IesiiFBsoQaHxW3D2Oft-/view?usp=drivesdk"&gt;drive.google.com/.../view&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33303?ContentTypeID=1</link><pubDate>Thu, 19 May 2016 06:41:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5167fc86-10ba-455a-83e1-165d89c91502</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;commented on your post&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33302?ContentTypeID=1</link><pubDate>Wed, 18 May 2016 22:14:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcf1fc9b-b4ba-4e7e-819b-f1c414ec5d31</guid><dc:creator>Tim</dc:creator><description>&lt;p&gt;I&amp;#39;m using Simblee in a product. It uses the nRF51822 and I think softdevice 110. I&amp;#39;m using TIMER1 for critical timing of GPIO pin pulse from 0-1 second in width. I discovered impact of BLE on TIMER1 function even when used only with PPI and GPIOTE. Please see &lt;a href="https://devzone.nordicsemi.com/question/79934/ble-affects-timer12-accuracy/"&gt;this post&lt;/a&gt; and comment if you can offer any insight. Much appreciated. -Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33298?ContentTypeID=1</link><pubDate>Tue, 12 Apr 2016 10:01:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd48108c-2c2b-4233-8bf5-4741801361e5</guid><dc:creator>adriand</dc:creator><description>&lt;p&gt;Aryan, probably I wasn&amp;#39;t sure if the timer/counter is still counting after clear, this is redundant I see.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33296?ContentTypeID=1</link><pubDate>Tue, 12 Apr 2016 09:40:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:323e7690-865b-405a-8a09-b9b6ac4491ae</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi, I think above implementation should have been very accurate with/Without softdevice enabled.&lt;/p&gt;
&lt;p&gt;adriand, in the timer1 interrupt handler, why did you start NRF_TIMER2-&amp;gt;TASKS_START = 1;  ??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33299?ContentTypeID=1</link><pubDate>Tue, 12 Apr 2016 08:22:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9174409-7c9d-404a-ae02-9c9647750671</guid><dc:creator>adriand</dc:creator><description>&lt;p&gt;accuracy wasn&amp;#39;t so important to me, I just wanted to know if I have 1500Hz or 1800Hz.. so I didn&amp;#39;t analyze it very accurately. Maybe try to measure your signal for a bit longer time than 1 second if you can. And don&amp;#39;t forget to divide counted value by the the time [seconds] you&amp;#39;ll try.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33301?ContentTypeID=1</link><pubDate>Tue, 12 Apr 2016 08:15:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9793c646-19de-467f-81fb-d7719d02f7bd</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;Oh I undestand. And what accuracy did you get? On the logic analyzer I have 665 Hz and the Nordic chip measures 657 Hz.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33300?ContentTypeID=1</link><pubDate>Tue, 12 Apr 2016 07:53:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96f30208-0b27-44c0-b89c-c41593f611b3</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;I tested the same code without SD. And then it works. I dont need the SD so this is good for me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33297?ContentTypeID=1</link><pubDate>Tue, 12 Apr 2016 07:23:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c256b0b-f3de-415b-97f2-8f85d1abd295</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Inspectron,
Check if there are any hardfaults or other conflicts with modules used here somewhere else in your code, this code should work perfectly when used alone.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33295?ContentTypeID=1</link><pubDate>Mon, 11 Apr 2016 14:34:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7bd628a-8605-43bc-9bd0-17ce9fc371ce</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;I try to use the same code, but I will never get into TIMER1_IRQHandler. What can be a reason, that i dont get into the TIMER1IRQHandler? Or is there a newer example to measure frequency on a Pin? I&amp;#39;m working with SDK 11.0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33304?ContentTypeID=1</link><pubDate>Fri, 18 Mar 2016 15:40:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86be659b-9ce8-43ad-ae5f-1055c36466f4</guid><dc:creator>azizg</dc:creator><description>&lt;p&gt;Hi,
i would like to also measure frequency on a pin by this method. But i have not a regular square signal to measure. Namely it is not a symmetrical signal. And it&amp;#39;s amplitude is bigger than 5V.
Can anybody help to me, to design the input circuit? And how i should define the input pin to not damage it?&lt;/p&gt;
&lt;p&gt;Thanks a lot
aziz&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33294?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2015 10:59:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff283770-0497-4c5d-a47a-c1b011262cf1</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Good to know, thanks for coming back here to update me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33293?ContentTypeID=1</link><pubDate>Sun, 25 Oct 2015 22:47:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c72aa084-f5e4-43eb-af8c-eb30cdba918b</guid><dc:creator>adriand</dc:creator><description>&lt;p&gt;@Aryan, It&amp;#39;s been a long time, however now I&amp;#39;ve already got time to deal with this frequency meter. Your advice works perfectly! After datasheet and forum reading I came up with the final code using all of these peripherals according to your scheme. PPI rulez :-) It also works with Soft Device enabled. I share my code below (not yet so beautiful..) so maybe someone would save his time on a similiar problem.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define FREQ_MEASURE_PIN 6

static void timer_init()
{
	NRF_TIMER1-&amp;gt;TASKS_STOP = 1;
	NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Timer;
	NRF_TIMER1-&amp;gt;PRESCALER = 8;	// Fhck / 2^8 
	NRF_TIMER1-&amp;gt;CC[0] = 62500;	// 62500 - 1s
	
	NRF_TIMER1-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_16Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);	
	
	NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;
	NRF_TIMER1-&amp;gt;INTENSET = (TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos);
	
	NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0;
}

static void counter_init()
{
	NRF_TIMER2-&amp;gt;TASKS_STOP = 1;	
	NRF_TIMER2-&amp;gt;MODE = TIMER_MODE_MODE_Counter;
	NRF_TIMER2-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_24Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);
	NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;
	NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0;
}

static void gpiote_init(uint32_t pin)
{
	NRF_GPIOTE-&amp;gt;CONFIG[0] 	= 	0x01 &amp;lt;&amp;lt; 0; 								// MODE: Event
	NRF_GPIOTE-&amp;gt;CONFIG[0] 	|= 	pin &amp;lt;&amp;lt; 8;								// Pin number
	NRF_GPIOTE-&amp;gt;CONFIG[0] 	|= 	NRF_GPIOTE_POLARITY_LOTOHI	&amp;lt;&amp;lt; 16;		// Event rising edge 	
}

static void ppi_timer_stop_counter_init()
{
	NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; 0;
	*(&amp;amp;(NRF_PPI-&amp;gt;CH0_EEP)) = (uint32_t)&amp;amp;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0];
	*(&amp;amp;(NRF_PPI-&amp;gt;CH0_TEP)) = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_STOP;
	NRF_PPI-&amp;gt;CHENSET |= 1 &amp;lt;&amp;lt; 0;
}

static void ppi_gpiote_counter_init()
{
	NRF_PPI-&amp;gt;CHEN |= 1 &amp;lt;&amp;lt; 1;
	*(&amp;amp;(NRF_PPI-&amp;gt;CH1_EEP)) = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[0];
	*(&amp;amp;(NRF_PPI-&amp;gt;CH1_TEP)) = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_COUNT;
	NRF_PPI-&amp;gt;CHENSET |= 1 &amp;lt;&amp;lt; 1;
}

int main()
{
    // Soft Device initialization..

   	NVIC_EnableIRQ(TIMER1_IRQn);
    NVIC_SetPriority(TIMER1_IRQn, NRF_APP_PRIORITY_LOW);	

    nrf_gpio_cfg_input(FREQ_MEASURE_PIN, NRF_GPIO_PIN_NOPULL);

	counter_init();
	timer_init();
	gpiote_init(FREQ_MEASURE_PIN);
	ppi_gpiote_counter_init();
	ppi_timer_stop_counter_init();

	NRF_TIMER1-&amp;gt;TASKS_START = 1;
	NRF_TIMER2-&amp;gt;TASKS_START = 1;
	
	for(;;) {
		// power manage //
	}
}

void TIMER1_IRQHandler(void) 
{
	if (NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] != 0)
	{
		NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0;
		NRF_TIMER2-&amp;gt;TASKS_CAPTURE[0] = 1;
				
		LOG_INFO(&amp;quot;cc: %dHz&amp;quot;, NRF_TIMER2-&amp;gt;CC[0]);
      	
		NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;
		NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;	
						
		NRF_TIMER2-&amp;gt;TASKS_START = 1;			
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33292?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 13:23:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e69d4e0d-64a7-4c2c-b645-e3e5280e8485</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;your welcome, please let me know if it worked after you implement it. I can help you if there are any problems you face.
I have changed the title for this thread to reflect the contents, i hope it is ok.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33291?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 13:18:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0524798-06a5-48d6-a688-97e093996407</guid><dc:creator>adriand</dc:creator><description>&lt;p&gt;@Aryan - thank you for the great explanation! I will try your method as soon as I get the sensor. Thx!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33290?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 08:54:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8d7694a-67eb-4344-b8a4-8644faa4365e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;at the end of the day you will get a very good understanding of all these peripherals :) Good luck and let me know how it goes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33289?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 08:50:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd98fc0e-efe7-44e7-ba48-30f86d45357c</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;ah I see. It is doable
Configure Timer1 in timer mode to generate an event in X seconds. This event should be converted to TASK_STOP using a PPI
Configure other peripherals as below but do not enable the last block timer 2 yet.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0638.Capture.PNG" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;When you want to start the measurements, START the timer1 and timer2.&lt;/p&gt;
&lt;p&gt;After X number of seconds, Timer2 counter will have counted the number of rising edges of the pin in X seconds. get the value into timer CC[n] by triggering a CAPTURE[n] task on timer 2.&lt;/p&gt;
&lt;p&gt;Divide Timer2-&amp;gt;CC[n] by X and you have your frequency. This should work even with softdevice as we are not using any interrupts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33288?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 08:06:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:147da6d2-f3ee-48d9-91d2-46fca3d34a10</guid><dc:creator>adriand</dc:creator><description>&lt;p&gt;@Aryan - thank you for the answer, however, no no, I don&amp;#39;t want to generate clock on pin. I want to measure frequency of a square wave. I need to connect Light-to-Frequency converter to the nRF51822. This converter gives square wave (50% duty) (toggling its output pin) depending on the light intensity. Its output frequency has range from several Hz up to 400kHz.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: measuring input GPIO pin frequency with soft device running</title><link>https://devzone.nordicsemi.com/thread/33287?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 07:52:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c9be35e-ee9e-4fd6-a3c8-bd4848f77a3a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;What do you mean by manage measurements on gpio pin, I presume that you want to generate clock on the gpio pin.&lt;/p&gt;
&lt;p&gt;Check &lt;a href="https://devzone.nordicsemi.com/question/44628/maximum-clock-possible-on-gpio-pin-nrf51/"&gt;this&lt;/a&gt; older thread.
You can generate a 4MHZ stable clock on GPIO using the modules gpiote, ppi and Timer2 and this should work with or without softdevice enabled and with and without and BLE activity as we do not use any interrupts to generate this clock.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>