<?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>Counter using timer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82355/counter-using-timer</link><description>I am using timer 3 as a counter for my capacitor discharge time. Currently, the value of is always problematic because it shows with too many deviation values ​​sometimes 15837, but other times 239 while the environment for the hr202 sensor remains unchanged</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Dec 2021 11:09:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82355/counter-using-timer" /><item><title>RE: Counter using timer</title><link>https://devzone.nordicsemi.com/thread/342296?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 11:09:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c923c1f-4e4a-4b0f-8852-b17749826948</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There is an example of using LPCOMP with a timer and PPI in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/57418/comparator-ppi-timer-counter-issue"&gt;his thread&lt;/a&gt;. Perhaps that is the best one to look at. For the COMP you could look at the implementation in &amp;lt;SDK&amp;gt;\components\libraries\csense_drv\nrf_drv_csense.c.&amp;nbsp;Perhaps it would also be good&amp;nbsp;to look at and understand the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ppi_example.html"&gt;PPI example&lt;/a&gt;. This just use two timers, but demonstrates well how PPI works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counter using timer</title><link>https://devzone.nordicsemi.com/thread/342211?ContentTypeID=1</link><pubDate>Tue, 07 Dec 2021 01:48:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7afe4b36-9a31-4a8b-ab76-5c49de1f1675</guid><dc:creator>Judge</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;can you give me a sample of code using all 3 of them? (PPI, timer, and comp) I&amp;#39;m using nrf mesh SDK 16&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counter using timer</title><link>https://devzone.nordicsemi.com/thread/342097?ContentTypeID=1</link><pubDate>Mon, 06 Dec 2021 13:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ba5faf2-27c2-4c66-8799-69db9bc8833d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;PPI does not contribute to increased current consumption. In practice, it should lead to a small reduction in over all energy use as the operation is as efficient as possible, and without using the CPU more than necessary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counter using timer</title><link>https://devzone.nordicsemi.com/thread/341942?ContentTypeID=1</link><pubDate>Sat, 04 Dec 2021 07:11:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf447250-be57-453e-a7e0-37bb4097d79d</guid><dc:creator>Judge</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Great for your suggestion. But I am having a question when using PPI what will be the current consumed? Since our device has to optimize the power level in the best way, I want to know this&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Counter using timer</title><link>https://devzone.nordicsemi.com/thread/341881?ContentTypeID=1</link><pubDate>Fri, 03 Dec 2021 12:58:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70b3c878-d646-4c29-af43-34b1658b0909</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There are a few potential error sources here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You are measuring an analog input signal by reading it as a digital input. This will be&amp;nbsp; inaccurate as there is a significant undefined region (see &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/gpio.html?cp=4_2_0_19_3_0#unique_1260823213"&gt;GPIO Electrical Specification&lt;/a&gt;). You should use the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/comp.html?cp=4_2_0_37#topic"&gt;comparator&lt;/a&gt;&amp;nbsp;for such tasks.&lt;/li&gt;
&lt;li&gt;You have a while loop where you read. If there is an interrupt in between here that could cause additional delay. You should solve this using &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/ppi.html?cp=4_2_0_21#concept_sxf_21l_1s"&gt;PPI&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As you see, the proper way to do this, which would solve both these issues is to use the comparator to get an event when the voltage passes a threshold, and use PPI to capture the timer when that happens. This way this will happen all in HW, and you can read the value later when the CPU has time. Any interrupts at a bad time will not affect the measurements.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>