<?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>nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17842/nrf51-timer-capture-task</link><description>Hello, 
 I want to measure a frequency of a PWM signal like this: 
 GPIOTE-Event --&amp;gt; PPI --&amp;gt; Timer1-Capture-Task 
 So every time the event occurs, the counter value is copied into the respective CC-Register (in my case channel 0). 
 Question: Where</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Nov 2016 09:28:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17842/nrf51-timer-capture-task" /><item><title>RE: nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/thread/68772?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 09:28:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53c695f5-4993-4a29-b89f-7434f76a2ec4</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Good that you were able to make it work!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/thread/68771?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 08:43:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b66a554-1a93-41cd-8f58-f76956c5f289</guid><dc:creator>mr91</dc:creator><description>&lt;p&gt;Got it. I found out, that Timer2/3 are only 16 Bit. After adjusting the reload value, everything seems to work fine :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/thread/68770?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 07:52:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf94ab45-ccf5-4db5-955f-321eca249eb8</guid><dc:creator>mr91</dc:creator><description>&lt;p&gt;Think I found the problem (using the linked example above):&lt;/p&gt;
&lt;p&gt;300 kHz -&amp;gt; Capture Value is 0x919B (37,2 kHz). I found out, that 0x&lt;strong&gt;4&lt;/strong&gt;919B would match the frequency (299419 Hz).&lt;/p&gt;
&lt;p&gt;Question: Why is Timer2 (used as counter) only delivering 16-Bit CC-values, despite it is initialized in 32 Bit-Mode:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TIMER2-&amp;gt;BITMODE = (TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/thread/68769?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 07:22:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ba0c02f-da15-4c1d-9063-062411d2bbc2</guid><dc:creator>mr91</dc:creator><description>&lt;p&gt;Thank you for your answer. It works both ways. However, I have encountered another problem.
I can measure frequencies only up to 60 kHz with this method.
I also tried another approach: &lt;a href="https://devzone.nordicsemi.com/question/50171/measuring-input-gpio-pin-frequency-with-soft-device-running/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;
but with exactly the same result.
Everything is ok when the frequency is under 60 kHz (e.g. 50 kHz is measured as 49992 Hz), but the result is totally wrong above (70 kHz is measured as 4330 Hz).&lt;/p&gt;
&lt;p&gt;Is there a maximum frequency the GPIOTE/PPI-combination can handle? The maximum frequency I want to measure is about 300 kHz.&lt;/p&gt;
&lt;p&gt;Thank you very much in advance!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/thread/68768?ContentTypeID=1</link><pubDate>Wed, 23 Nov 2016 12:24:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4272b01-58cf-483f-82c8-a404edf1c633</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Unfortunately, there is no event when the capture is finished, so I would think that it will be executed immediately.
If you are not using the softdevice, the GPIOTE event can be set to have the highest priority, and you know that you won&amp;#39;t have any other interrupt.&lt;/p&gt;
&lt;p&gt;You can check if the following will work:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;GPIOTE event --&amp;gt; PPI --&amp;gt; TASKS_CAPTURE&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;GPIOTE event handler: clear timer, then read the CC register.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If the above doesn&amp;#39;t work, i.e the capture has not finished before clearing the timer, you can test the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;GPIOTE event --&amp;gt; PPI --&amp;gt; TASKS_CAPTURE&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;GPIOTE event handler: dummy read CC values, clear timer, then read the CC register.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Even though the capture/clear timing may be a little delayed, this delay will always be the same, so it should be possible to measure the frequency.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/thread/68767?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2016 10:09:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3cfcef4-35c1-48fd-ab53-f585c8cdb584</guid><dc:creator>mr91</dc:creator><description>&lt;p&gt;Thank you very much for your support. In order to get that working accurately, it seems necessary to clear the timer immediately after the capture is done. Is the timer generating an interrupt after finishing the capture?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51: Timer Capture Task</title><link>https://devzone.nordicsemi.com/thread/68766?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2016 10:01:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a2f6931-02bd-49d5-a759-4b0327491d48</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;There is no specific ideal place to copy the content of the CC register, typically, the content in the CC register can be copied to a variable, a data array should work fine.&lt;/p&gt;
&lt;p&gt;The benefit of using PPI instead of normal GPIO interrupt handling is that when using PPI, the CPU is not being used:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Programmable Peripheral
Interconnect (PPI) enables different
peripherals to interact autonomously
with each other using tasks and events
without use of the CPU. The PPI
provides a mechanism to automatically
trigger a task in one peripheral as a
result of an event occurring in
another. A task is connected to an
event through a PPI channel.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;(nRF51 series reference manual chapter 3.3.4)&lt;/p&gt;
&lt;p&gt;Clearing timer as soon as the capture is done:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Capture value (will be copied to the CC register).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Clear timer&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Read captured value from the CC register.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This should work as long as every reading of captured values is finished before the next captured value.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>