<?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>PWM analyzer / Pulse counter</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/2584/pwm-analyzer-pulse-counter</link><description>Is it possible to count pulses with the 51822 from an external device in the range of 250-15.000 pulses pr. second, while the CPU is powered down (softdevice sleep)? 
 I&amp;#39;ve had a look at the pwm_analyzer sample, which might do the trick. But I&amp;#39;m not</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Jun 2014 10:50:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/2584/pwm-analyzer-pulse-counter" /><item><title>RE: PWM analyzer / Pulse counter</title><link>https://devzone.nordicsemi.com/thread/10238?ContentTypeID=1</link><pubDate>Thu, 12 Jun 2014 10:50:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfabd401-34c7-40e7-bd3d-92aeecc84d65</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Try now  :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM analyzer / Pulse counter</title><link>https://devzone.nordicsemi.com/thread/10237?ContentTypeID=1</link><pubDate>Tue, 10 Jun 2014 21:30:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e03dc926-ed6d-4f60-8bb0-47edb64b5e9a</guid><dc:creator>Syrius</dc:creator><description>&lt;p&gt;Hi Stefan!&lt;/p&gt;
&lt;p&gt;Could you relink the timer exampe? I have similar task and I would like to download it, but unavailable.&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM analyzer / Pulse counter</title><link>https://devzone.nordicsemi.com/thread/10236?ContentTypeID=1</link><pubDate>Thu, 22 May 2014 06:45:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c11b54b3-6823-4784-948a-b2e28245bbd3</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Ok, since the frequency is that low, then perhaps, as you have pointed out, there is not so much power to save by periodically enable the peripherals. However, if your average pulse frequency is e.g. 50 Hz, and you need to measure on average perhaps 3 times a second, then the method would pay off since you would only have the peripherals enabled 6% of the time. On the other hand, if your pulse freqency at any instance is down to 4 Hz and you are measuring 5 times a socond, it is not going to work.&lt;/p&gt;
&lt;p&gt;However, if the above method would work, you could use RTC timer instead of TIMER to measure the pulse, which is very low power. This should be adequate since your max frequency is only 250Hz. Current consumption is &amp;lt;1uA for RTC+LFCLK if you use 32kHz external crystal as the low frequency clock source. If you use the internal 32kHz RC clock source, the current consumption is ~10uA with calibration to obtain 250ppm accuracy, see &lt;a href="https://devzone.nordicsemi.com/index.php/what-low-frequency-clock-sources-can-i-use"&gt;this thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Example code for TIMER in COUNTER mode is found on &lt;a href="https://github.com/NordicSemiconductor/nrf51-TIMER-examples"&gt;Nordic&amp;#39;s Github&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM analyzer / Pulse counter</title><link>https://devzone.nordicsemi.com/thread/10235?ContentTypeID=1</link><pubDate>Wed, 21 May 2014 20:47:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ab096e7-a868-493c-a969-2fd05f9261d6</guid><dc:creator>KPE</dc:creator><description>&lt;p&gt;Thanks for your thorough answer, I wasn&amp;#39;t aware that the HFClock was needed. What about the LFClock, I have it on board - will this make any difference?&lt;/p&gt;
&lt;p&gt;I only need to measure the frequency (count pulses), and the duty cycle was just an alternative to that, in order to do the measuring in a small window. I could live with a measurement every second, but 5 measures would be optimal.&lt;/p&gt;
&lt;p&gt;Anyhow, I&amp;#39;ve made a mistake. The pulse input of 250-15000 is actually the number of pulses per minute. So the real figure is 4-250Hz, which is just making the pulse periods longer, and more costly to measure.&lt;/p&gt;
&lt;p&gt;I like your idea in the seconds paragraph, but it would still mean that if I was to measure a 4Hz signal, the TIMER would need to be on for at least 250ms right (@ ~1mA)?&lt;/p&gt;
&lt;p&gt;This would then consume ~0,25 mA at maximum, but only for 1 reading per second. At 4 readings we are back at ~1 mA, so it would probably be easier to just use the Timer as a counter as you mention.&lt;/p&gt;
&lt;p&gt;Well, right now I&amp;#39;ll probably start with the counter. Aside from the pwm_analyzer, is there any examples on using a Timer in counter mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM analyzer / Pulse counter</title><link>https://devzone.nordicsemi.com/thread/10234?ContentTypeID=1</link><pubDate>Wed, 21 May 2014 13:30:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d1c2dc2-2f39-4b7b-bfcd-7e5cb5534615</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Initial thoughts on this is that yes, you can use TIMER peripheral for this purpose and have it in COUNTER mode. Then the hardware will count the pulses and, as you say, you can make calculations to calculate the frequency based on the counter value. However, this will not be specifically low power, as TIMER peripheral constantly requires 16HMz clock to be enabled, so the operation will require ~1mA of current.&lt;/p&gt;
&lt;p&gt;However, if you intend only periodically to measure the frequency of the PWM signal, then it should be possible to monitor GPIO pin for signal transition, and let that signal transition start a TIMER. When the timer has been started, you configure the pin signal transition to stop the timer and trigger an interrupt so you can check the value of the timer and calculate the frequency. If you do not need to check the frequency very often, this method could be relatively low power, since you only need to enable the peripherals while you perform the measurement. Let me know if you would consider this method instead of the other one.&lt;/p&gt;
&lt;p&gt;What do you need to measure exactly, the duty cycle of the PWM or also the frequency?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>