<?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 PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71093/using-pwm-to-measure-input-period-and-pulse-width</link><description>I have an input signal of unknown period and pulse width on a GPIO. I want to use the PWM capture capabilities to retrieve those parameters. 
 I see in the documentation there is 
 pwm_pin_configure_capture, pwm_pin_enable_capture, pwm_pin_disable_capture</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Mar 2021 14:27:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71093/using-pwm-to-measure-input-period-and-pulse-width" /><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/297231?ContentTypeID=1</link><pubDate>Tue, 02 Mar 2021 14:27:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0da6668f-e476-4610-acfb-04d61b6c8d88</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Smit&lt;/p&gt;
&lt;p&gt;below is the code that I am using to measure the output of a Hall effect sensor. Their is a pulse width of 30 - 200us.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;typedef struct&lt;br /&gt;{&lt;br /&gt;uint32_t pulseWidth; //!&amp;lt; pulse width in us&lt;br /&gt;uint32_t period; //!&amp;lt; period in us&lt;br /&gt;} sensorDataStruct;&lt;br /&gt;sensorDataStruct sensorData[SENSOR_BUFFER_SIZE];&lt;br /&gt;iuint16_t sensorDataIn;&lt;br /&gt;uint16_t sensorDataOut;&lt;br /&gt;uint16_t sensorDataCount;&lt;br /&gt;nt32_t inputPulseWidth;&lt;br /&gt;int32_t inputPeriod;&lt;br /&gt;void hallSensorCallback(struct device *dev, struct gpio_callback *cb, uint32_t pins);&lt;br /&gt;void configurePins();&lt;/p&gt;
&lt;p&gt;main()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;sensorDataIn = 0;&lt;br /&gt;sensorDataOut = 0;&lt;br /&gt;sensorDataCount = 0;&lt;br /&gt;timer_init();&lt;br /&gt;configurePins();&lt;/p&gt;
&lt;p&gt;&lt;span&gt;NRF_TIMER1-&amp;gt;TASKS_START = 1;&lt;/span&gt;&lt;br /&gt;...&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void timer_init()&lt;br /&gt;{&lt;br /&gt;NRF_TIMER1-&amp;gt;TASKS_STOP = 1;&lt;br /&gt;NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Timer;&lt;br /&gt;NRF_TIMER1-&amp;gt;PRESCALER = 4; // Fhck / 2^4 = 1us&lt;br /&gt;// NRF_TIMER1-&amp;gt;CC[0] = 62500; // 62500 - 1s&lt;br /&gt;&lt;br /&gt;NRF_TIMER1-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);&lt;br /&gt;&lt;br /&gt;NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt;// NRF_TIMER1-&amp;gt;INTENSET = (TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos);&lt;br /&gt;&lt;br /&gt;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;void hallSensorCallback(struct device *dev, struct gpio_callback *cb, uint32_t pins)&lt;br /&gt;{&lt;br /&gt;int pin;&lt;/p&gt;
&lt;p&gt;pin = gpio_pin_get(dev, HALL_SENSOR_PIN);&lt;br /&gt;gpio_pin_set(dev,LED3_PIN,pin);&lt;br /&gt;if(pin == 0)&lt;br /&gt;{&lt;br /&gt;NRF_TIMER1-&amp;gt;TASKS_CAPTURE[0] = 1;&lt;br /&gt;inputPeriod = NRF_TIMER1-&amp;gt;CC[0];&lt;br /&gt;NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt;if(sensorDataCount == 0) /* check if first pulse width measured */&lt;br /&gt;return;&lt;br /&gt;if( sensorDataIn == 0 )&lt;br /&gt;sensorData[SENSOR_BUFFER_SIZE - 1].period = inputPeriod;&lt;br /&gt;else&lt;br /&gt;sensorData[sensorDataIn - 1].period = inputPeriod;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;NRF_TIMER1-&amp;gt;TASKS_CAPTURE[0] = 1;&lt;br /&gt;inputPulseWidth = NRF_TIMER1-&amp;gt;CC[0];&lt;br /&gt;if(inputPulseWidth &amp;gt;= 1000) /* check if valid pulse width */&lt;br /&gt;return;&lt;br /&gt;if(sensorDataCount &amp;lt; SENSOR_BUFFER_SIZE)&lt;br /&gt;{&lt;br /&gt;sensorData[sensorDataIn++].pulseWidth = inputPulseWidth;&lt;br /&gt;sensorData[sensorDataIn - 1].period = 0;&lt;br /&gt;if(sensorDataIn == SENSOR_BUFFER_SIZE) /* is it wrap around */&lt;br /&gt;sensorDataIn = 0;&lt;br /&gt;sensorDataCount++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;void configurePins()&lt;br /&gt;{&lt;br /&gt;/* configure output pins */&lt;br /&gt;// gpio_pin_configure(gpioPtr, LED3_PIN,GPIO_OUTPUT | GPIO_ACTIVE_HIGH | GPIO_PULL_UP);&lt;br /&gt;gpio_pin_configure(gpioPtr, LED3_PIN,GPIO_OUTPUT );&lt;/p&gt;
&lt;p&gt;/* configure input pins */&lt;br /&gt;gpio_pin_configure(gpioPtr, HALL_SENSOR_PIN,GPIO_INPUT | GPIO_ACTIVE_LOW );&lt;/p&gt;
&lt;p&gt;/* configure interrupt callbacks */&lt;br /&gt;gpio_init_callback(&amp;amp;gpio_hall_sensor_cb, (gpio_callback_handler_t)hallSensorCallback, BIT(HALL_SENSOR_PIN));&lt;br /&gt;gpio_add_callback(gpioPtr, &amp;amp;gpio_hall_sensor_cb);&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/297197?ContentTypeID=1</link><pubDate>Tue, 02 Mar 2021 13:21:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b212f71d-9b91-46f9-a9c2-07a2681bf987</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;below is the code that I am using to measure the output of a Hall effect sensor. Their is a pulse width of 30 - 200us.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;typedef struct&lt;br /&gt;{&lt;br /&gt; uint32_t pulseWidth; //!&amp;lt; pulse width in us&lt;br /&gt; uint32_t period; //!&amp;lt; period in us&lt;br /&gt;} sensorDataStruct;&lt;br /&gt;sensorDataStruct sensorData[SENSOR_BUFFER_SIZE];&lt;br /&gt;iuint16_t sensorDataIn;&lt;br /&gt;uint16_t sensorDataOut;&lt;br /&gt;uint16_t sensorDataCount;&lt;br /&gt;nt32_t inputPulseWidth;&lt;br /&gt;int32_t inputPeriod;&lt;br /&gt;void hallSensorCallback(struct device *dev, struct gpio_callback *cb, uint32_t pins);&lt;br /&gt;void configurePins();&lt;/p&gt;
&lt;p&gt;main()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;sensorDataIn = 0;&lt;br /&gt; sensorDataOut = 0;&lt;br /&gt; sensorDataCount = 0;&lt;br /&gt;timer_init();&lt;br /&gt;configurePins();&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;void timer_init()&lt;br /&gt;{&lt;br /&gt; NRF_TIMER1-&amp;gt;TASKS_STOP = 1;&lt;br /&gt; NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Timer;&lt;br /&gt; NRF_TIMER1-&amp;gt;PRESCALER = 4; // Fhck / 2^4 = 1us&lt;br /&gt;// NRF_TIMER1-&amp;gt;CC[0] = 62500; // 62500 - 1s&lt;br /&gt; &lt;br /&gt; NRF_TIMER1-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos); &lt;br /&gt; &lt;br /&gt; NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt;// NRF_TIMER1-&amp;gt;INTENSET = (TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos);&lt;br /&gt; &lt;br /&gt; NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;void hallSensorCallback(struct device *dev, struct gpio_callback *cb, uint32_t pins)&lt;br /&gt;{&lt;br /&gt; int pin;&lt;/p&gt;
&lt;p&gt;pin = gpio_pin_get(dev, HALL_SENSOR_PIN);&lt;br /&gt; gpio_pin_set(dev,LED3_PIN,pin);&lt;br /&gt; if(pin == 0)&lt;br /&gt; {&lt;br /&gt; NRF_TIMER1-&amp;gt;TASKS_CAPTURE[0] = 1;&lt;br /&gt; inputPeriod = NRF_TIMER1-&amp;gt;CC[0];&lt;br /&gt; NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;&lt;br /&gt; if(sensorDataCount == 0) /* check if first pulse width measured */&lt;br /&gt; return;&lt;br /&gt; if( sensorDataIn == 0 )&lt;br /&gt; sensorData[SENSOR_BUFFER_SIZE - 1].period = inputPeriod;&lt;br /&gt; else&lt;br /&gt; sensorData[sensorDataIn - 1].period = inputPeriod;&lt;br /&gt; }&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt; NRF_TIMER1-&amp;gt;TASKS_CAPTURE[0] = 1;&lt;br /&gt; inputPulseWidth = NRF_TIMER1-&amp;gt;CC[0];&lt;br /&gt; if(inputPulseWidth &amp;gt;= 1000) /* check if valid pulse width */&lt;br /&gt; return;&lt;br /&gt; if(sensorDataCount &amp;lt; SENSOR_BUFFER_SIZE)&lt;br /&gt; {&lt;br /&gt; sensorData[sensorDataIn++].pulseWidth = inputPulseWidth;&lt;br /&gt; sensorData[sensorDataIn - 1].period = 0;&lt;br /&gt; if(sensorDataIn == SENSOR_BUFFER_SIZE) /* is it wrap around */&lt;br /&gt; sensorDataIn = 0;&lt;br /&gt; sensorDataCount++;&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;void configurePins()&lt;br /&gt;{&lt;br /&gt; /* configure output pins */&lt;br /&gt;// gpio_pin_configure(gpioPtr, LED3_PIN,GPIO_OUTPUT | GPIO_ACTIVE_HIGH | GPIO_PULL_UP);&lt;br /&gt; gpio_pin_configure(gpioPtr, LED3_PIN,GPIO_OUTPUT );&lt;/p&gt;
&lt;p&gt;/* configure input pins */&lt;br /&gt; gpio_pin_configure(gpioPtr, HALL_SENSOR_PIN,GPIO_INPUT | GPIO_ACTIVE_LOW );&lt;/p&gt;
&lt;p&gt;/* configure interrupt callbacks */&lt;br /&gt; gpio_init_callback(&amp;amp;gpio_hall_sensor_cb, (gpio_callback_handler_t)hallSensorCallback, BIT(HALL_SENSOR_PIN));&lt;br /&gt; gpio_add_callback(gpioPtr, &amp;amp;gpio_hall_sensor_cb);&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/297084?ContentTypeID=1</link><pubDate>Tue, 02 Mar 2021 09:22:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3eeb61ca-7d62-4e27-973c-f605a5f550f9</guid><dc:creator>Smit</dc:creator><description>[quote userid="87403" url="~/f/nordic-q-a/71093/using-pwm-to-measure-input-period-and-pulse-width/293328#293328"]when I changed the code to use hardware interrupts on the GPIO pin and not the user interface.[/quote]
&lt;p&gt;Hello timothy&lt;/p&gt;
&lt;p&gt;It would be wonderful if you state the change as above quoted comment.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/297037?ContentTypeID=1</link><pubDate>Tue, 02 Mar 2021 06:39:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a741b47-a226-45ec-9993-eee21abfebc0</guid><dc:creator>Smit</dc:creator><description>&lt;p&gt;Hello Timothy&amp;nbsp;I have similar use case as yours and i am glad you have found the solution for the same.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can you please share your code here so that we can leverage and appreciate your work that you have shared!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/293678?ContentTypeID=1</link><pubDate>Wed, 10 Feb 2021 07:44:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f6e3426-74b5-424c-bdb6-2ea3dd3cef49</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;Super&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/293328?ContentTypeID=1</link><pubDate>Mon, 08 Feb 2021 12:46:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e8c35ad-6048-40a7-9513-1c32c4d20f3b</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;&lt;span style="vertical-align:inherit;"&gt;&lt;span style="vertical-align:inherit;"&gt;Vkadal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I am able to get microsecond accuracies when I changed the code to use hardware interrupts on the GPIO pin and not the user interface. I have it working now. thank you for your help. The user interface caused polling changes on the GPIO pin and had millisecond latencies.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/293191?ContentTypeID=1</link><pubDate>Sat, 06 Feb 2021 04:49:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01d86299-b493-4dbf-9ba4-25b0a5cd7625</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;Let me assume the&amp;nbsp; hardware time has 16 Mhz clock input. Then the time elapsed&amp;nbsp; for&amp;nbsp; one tick is 1/16 uS.&amp;nbsp; That is roughly 60 Nano second. This is the level of&amp;nbsp; accuracy , you can achieve for pulse width or period measurement.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;If it is 1 MHz, then you need to&amp;nbsp; live with 1 us accuracy / resolution&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/293176?ContentTypeID=1</link><pubDate>Fri, 05 Feb 2021 17:46:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f892efa2-fe3a-4f7b-9bea-0841450468ec</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Vkadal&lt;/p&gt;
&lt;p&gt;no that will not work. that messes up the system timing. that is used by software timers. the TIMER1 are hardware timers counting at 16 MHz or 1MHZ. the problem is they have no hardware control. the control is all software which does not help get to microsecond measurements.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/293167?ContentTypeID=1</link><pubDate>Fri, 05 Feb 2021 16:16:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:117df378-58e0-47ae-a3dd-cc1b2b6f7ea8</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;I am not very conversant with Segger.&amp;nbsp; Could&amp;nbsp; you abe to increase the ticks here?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;SYS_CLOCK_TICKS_PER_SEC (32768)&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/293147?ContentTypeID=1</link><pubDate>Fri, 05 Feb 2021 15:16:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2da0d70-8d9d-4445-b39e-5699681e44be</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;vkadal&lt;/p&gt;
&lt;p&gt;I have a frequency coming into a GPIO. I trigger an interrupt on each edge. I can use the TIMER1 to measure *** width and period but I cannot get it measure below ~10ms for pulse width or period accurately. anything above ~10ms all works fine. I am setting an LED in the interrupt routine so I can see what I am measuring. There is milliseconds delay before the led toggles so I do not start the timer exactly when the interrupt occurs. the frequency I need to measure is ~12KHz and the pulse widths I need to measure are 30-150us. is there any way to accurately measure these. The TIMER does not have external start/stop capabilities. It must relay on interrupts and code to stop/start it.&lt;/p&gt;
&lt;p&gt;sample code below to measure the period. the code to measure pulse width was removed to simplify to see what the shortest period I could measure. This code saves the timer count (period) on every negative edge and clears the timer count.. This works well until you get &amp;lt; 10ms. any ideas how I measure us. the TIMER can measure us but I can not stop/start it fast enough. I removed the LED commands and the result was the same. It is not the LED commands causing the delay.&lt;/p&gt;
&lt;p&gt;if (evt.type == UI_EVT_BUTTON_ACTIVE) &lt;br /&gt; {&lt;br /&gt; dk_set_led(LED2,0x01);&amp;nbsp; /* positive edge */&lt;br /&gt;} &lt;br /&gt; else &lt;br /&gt; {&lt;br /&gt; dk_set_led(LED2,0x00);&amp;nbsp; &amp;nbsp;/*negative edge */&lt;br /&gt; NRF_TIMER1-&amp;gt;TASKS_CAPTURE[0] = 1;&lt;br /&gt; inputPeriod = NRF_TIMER1-&amp;gt;CC[0]; &lt;br /&gt; NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292674?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2021 12:56:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8701db03-700f-4872-911f-0c839a13765c</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;As I can understand, Seggar studio may the most complicated IDE in the world.&amp;nbsp; What I can do in few lines in Arduino or in CCS Compilers, this&amp;nbsp; Seggar takes few pages of codes.&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Simplicity of programming is not in nRF world. However, the support engineers are good to support.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292574?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2021 22:32:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e204b796-b3b8-4efe-aece-3f82d18526de</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Vkadal&lt;/p&gt;
&lt;p&gt;I figured it out. I was able to get NRF_TIMER1 working to measure pulse width and period. I can clock the timer at 1 MZ but I still have a problem getting the interrupts to handle times that short. I am working on it. thank you for your patience and you help. The problem is with the interrupts now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292564?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2021 20:10:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c87978a-c1d5-40cc-9bd3-2c301667a2a5</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Vkadal&lt;/p&gt;
&lt;p&gt;Ok I know I have to use NRF_TIMER1 (for example) but I do not see a complete example of how to set this up and use it. I want a simple example that just shows me how to start it, stop it, and read the values. I do not need interrupts. I just need something very simple. I am very confused with the examples you have pointed me to. The GPIO is generating the interrupt so I just want be able to read the timer value in the interrupt handler.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;something as simple as the following:&lt;/p&gt;
&lt;p&gt;init timer&lt;/p&gt;
&lt;p&gt;clear timer&lt;/p&gt;
&lt;p&gt;start timer&lt;/p&gt;
&lt;p&gt;delay x ms or us&lt;/p&gt;
&lt;p&gt;read timer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292538?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2021 15:31:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d84cc8b7-ee44-4efb-ba86-5b501f3b7ec5</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;&lt;span&gt;SYS_CLOCK_TICKS_PER_SEC (32768)&amp;nbsp; -- You almost&amp;nbsp; got it. You shall increase the value and get higher resolution. I&amp;nbsp; am also using nRF 9160 , but not its timer.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292512?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2021 14:30:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afb98fde-9c07-4e4b-917b-0a51e48eac2b</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Vkadal&lt;/p&gt;
&lt;p&gt;I am using the nRF9160 internal built in timers that count at&amp;nbsp;SYS_CLOCK_TICKS_PER_SEC (32768). I can change that to higher but that is the system clock and there is a big pop up screen that says there are severe limits on what values you can put there. they show millisecond resolution. I belive this value is used by many other things and it will change the system timing everywhere.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292489?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2021 13:30:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1c997a3-8481-416b-bd11-daca2326565f</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;nRF 9160 operates at 64MHz, Then the resolution of one clock / tick is around 16 nS. So you shall be able to measure the same. Look for some prescalar or post scalar setting of the timer you are using.&amp;nbsp; You should be able to measure to the level of accuracy you are looking for.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292478?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2021 13:07:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41edb26d-4cdd-4df8-8b97-63e6a496e874</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Vkadal&lt;/p&gt;
&lt;p&gt;I need to measure pulse width and periods in the microsecond range.(20 - 400 us pulse width). I do not see a way to get the nRF9160 timers to count that fast with interrupts and the latency involved. I do not see a way to send an external clock into the nRf9160 timers. they need to be started with a given expire time. using the timers I can measure pulse width in the order of ~10ms. I set a timer expiration time of 1000ms and start the timer on the leading edge interrupt and stop the timer on the falling edge interrupt. I get the remaining ticks and subtract it from&amp;nbsp; (1000 * ticks/sec) this gives me the pulse width. this fails as I get below 10 ms.&lt;/p&gt;
&lt;p&gt;How can I get microsecond resolution?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292082?ContentTypeID=1</link><pubDate>Sun, 31 Jan 2021 15:13:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:005e96b4-3fac-4d8f-9348-d8966433d156</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Vkadal&lt;/p&gt;
&lt;p&gt;Thank you for your response. I used the Nordic built in timers and can get the pulse width and the period using interrupts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292061?ContentTypeID=1</link><pubDate>Sat, 30 Jan 2021 15:32:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aaf2a3a1-b551-40a1-9870-3808ec249dd1</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;What I am writing is from the general knowledge of micro contriller and it shall be the same for Nordic too&lt;/p&gt;
&lt;p&gt;The micro controller can not measure time between two events directly. Let us assume&amp;nbsp; the micro controller operates an 1 MHz&amp;nbsp; clock speed. This has been given as the source to the timer. Then the timer will increment every clock cycle. That every 1 micro second, the timer will be&amp;nbsp; incremented&lt;/p&gt;
&lt;p&gt;Assume it is an 8 bit timer. the counter can increment from 0 to 255 and come back to zero again,&lt;/p&gt;
&lt;p&gt;Allow&amp;nbsp; the incoming signal&amp;nbsp; to interrupt the processor when the signal goes&amp;nbsp; low to high. Then start the counter . The counter will be counting from zero. The incoming signal shall generate another interrupt while it&amp;nbsp; is going from lhifh to low. Then stop the counter . Read the counter value&lt;/p&gt;
&lt;p&gt;Say the counter reads 100, then the&amp;nbsp; pulse width is 100 uS&lt;/p&gt;
&lt;p&gt;There are other complication to deal with. Will explain once you are done with this&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To know the time between two events&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292056?ContentTypeID=1</link><pubDate>Sat, 30 Jan 2021 01:07:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aee998e0-dc21-48f6-88e7-577b2f25eccf</guid><dc:creator>Timothy</dc:creator><description>&lt;p&gt;Vkadal&lt;/p&gt;
&lt;p&gt;thank you for your quick response. what counter are you referring to? I start a timer when the GPIO goes from low to high and stop the timer when it goes from high to low. I was expecting to be able to see how much time was left when I stopped it.&lt;/p&gt;
&lt;p&gt;for example if I get a low to high edge I set the timer to 1000ms with wait forever (one shot). when the high to low edge comes at 100ms I stop the timer. I expected to be able to see that 900ms was left on my timer and then I would know my pulse width was 1000 - 900 = 100ms. I could not find out how to tell how much time is left or what counter your are talking about. I do get an interrupt on both edges of the GPIO and I do see the timer stop function called.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: using PWM to measure input period and pulse width</title><link>https://devzone.nordicsemi.com/thread/292046?ContentTypeID=1</link><pubDate>Fri, 29 Jan 2021 17:10:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:437a7bc3-60ab-4a2d-928f-e26a03905a79</guid><dc:creator>vkadal</dc:creator><description>&lt;p&gt;You need to use timer for this purpose. You shall use GPIO pin which can create an interrupt. Create an interrupt when the pulse changes high low and start the counter. Stop the counter when the pulse goes&amp;nbsp; low. This will give you the pulse width&lt;br /&gt;&lt;br /&gt;Similarly to measure period, start the counter when the pusle goes from high to low and stop it in the next hight to low&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is standard procedure for any&amp;nbsp; micro&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>