<?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>Microsecond counter</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46104/microsecond-counter</link><description>I need to implement a uint64_t counter that increments every microseconds that I can then read. 
 I tried to use the timer API and increment the counter in the event handler call back but because it is being called at 1 us rate it never really exits the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 12 Apr 2019 19:26:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46104/microsecond-counter" /><item><title>RE: Microsecond counter</title><link>https://devzone.nordicsemi.com/thread/181910?ContentTypeID=1</link><pubDate>Fri, 12 Apr 2019 19:26:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ebce089f-91de-4aab-a45a-1cc62f90e0eb</guid><dc:creator>dvescovi</dc:creator><description>&lt;p&gt;works great thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Microsecond counter</title><link>https://devzone.nordicsemi.com/thread/181790?ContentTypeID=1</link><pubDate>Fri, 12 Apr 2019 08:20:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b70a5356-9459-4c52-bd5f-41335f77fadf</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Whenever an interrupt is fired there will be some latency, typically a couple of microseconds, and the timer API might add some additional processing and event forwarding that will increase the latency further.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In general it is not recommended to fire off interrupts at such a rapid rate, as it will burn a lot of CPU clock cycles and lead to higher power consumption.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I would suggest running a separate timer module at a 1 MHz rate, and do a capture operation on the timer every time you need to read the value. Then the state of the timer will be moved into one of the CC (compare/capture) registers, and you can read out the state from there.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At some point you will need to reset the timer, and increment your counter variable, but in principle you don&amp;#39;t have to do it more often than every 2^32/1000000 seconds if you run the timer in 32-bit mode (corresponding to an interrupt every 68 minutes).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>