<?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>Reading 3 Encoders using PPI, Timers, and GPIOTE with NRFX</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74613/reading-3-encoders-using-ppi-timers-and-gpiote-with-nrfx</link><description>The encoders I am using generating about 500 pulses per second, and I need to read 3 of them at the same time. I assume a good approach for that is to use the hardware timer to count the pulses and then using a separate timer to read the pulses. I am</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 03 May 2021 23:20:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74613/reading-3-encoders-using-ppi-timers-and-gpiote-with-nrfx" /><item><title>RE: Reading 3 Encoders using PPI, Timers, and GPIOTE with NRFX</title><link>https://devzone.nordicsemi.com/thread/308029?ContentTypeID=1</link><pubDate>Mon, 03 May 2021 23:20:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02642659-203b-40b0-be48-1902429cda63</guid><dc:creator>czuvich</dc:creator><description>&lt;p&gt;That did the trick! Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading 3 Encoders using PPI, Timers, and GPIOTE with NRFX</title><link>https://devzone.nordicsemi.com/thread/308008?ContentTypeID=1</link><pubDate>Mon, 03 May 2021 18:49:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6e5a96a-28a6-4955-8043-d6bdf20604a0</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;1-4 is good.&lt;/p&gt;
&lt;p&gt;Regarding 5, you are right that you do not need PPI. you need to trigger the capture task from SW in order to copy the counter value to a capture register so that it can be read and read it. Both these tasks are integrated in the&amp;nbsp;nrfx_timer_capture() function. Regarding clearing the counter you can do that by calling&amp;nbsp;nrfx_timer_clear(). However, as this does not happen at the same time as you call&amp;nbsp;nrfx_timer_capture() you risk counting one more between reading out the counter and resetting it (the counting happens in HW using PPI, so critical sections are no help here). That means that unless that is not a problem or you know this will not happen, then it would probably be better to never reset the counter but instead remember the previous counter value as well, so that you can calculate the difference between each time you capture and read the value. Note that then you also need to handle when the counter overflows and wraps around.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading 3 Encoders using PPI, Timers, and GPIOTE with NRFX</title><link>https://devzone.nordicsemi.com/thread/307953?ContentTypeID=1</link><pubDate>Mon, 03 May 2021 13:26:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7aa8157-3f2a-4f33-a38e-65b80cc4137b</guid><dc:creator>czuvich</dc:creator><description>&lt;p&gt;Thanks for the reply!&amp;nbsp; So, is my workflow correct?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;1) Setup 3 separate timer instances used for counting&lt;/p&gt;
&lt;p&gt;2) Setup a single app_timer that fires every 250ms&lt;/p&gt;
&lt;p&gt;3) Enable GPIOTE for the pin receiving the pulse&lt;/p&gt;
&lt;p&gt;4) Use&amp;nbsp;nrfx_ppi_channel_assign to perform a&amp;nbsp;NRF_TIMER_TASK_COUNT for the GPIOTE.&lt;/p&gt;
&lt;p&gt;5) ??? How do I capture and reset the COUNTER in the app_timer interrupt?&amp;nbsp;&amp;nbsp;I don&amp;#39;t need PPI for that right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading 3 Encoders using PPI, Timers, and GPIOTE with NRFX</title><link>https://devzone.nordicsemi.com/thread/307652?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 11:58:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:085b52be-b175-4e38-9bb7-02c2dc88783f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]1) Could I just use a single timer instance to capture all 3 counts separately (maybe using a different channel?)[/quote]
&lt;p&gt;No, the TIMER peripherals have several capture/compare registers, but only a single counter. So you will need to use 3 timers for this. (See &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/timer.html?cp=4_0_0_5_29"&gt;Figure 1: Block schematic for timer/counte&lt;/a&gt;r for an overview).&lt;/p&gt;
[quote user=""]2) Could I use the app_timer to generate the software interrupt to read the hardware counters (for instance, app_timer would run every 250ms).[/quote]
&lt;p&gt;Yes, the app_timer is perfect for such use cases.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>