<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-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>About the use of timer</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/87640/about-the-use-of-timer</link><description>I want to use the timer to measure the interval between two signals, which requires an accuracy of 1us. But in Timer mode, I don&amp;#39;t find a register that can read the current counter value, just like the counter register of RTC. So I want to ask, is there</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Thu, 12 May 2022 01:00:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/87640/about-the-use-of-timer" /><item><title>RE: About the use of timer</title><link>https://test-devzone.nordicsemi.com/thread/367499?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 01:00:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbfbd793-2c0d-4fab-994a-6c9697b9f363</guid><dc:creator>user102536</dc:creator><description>&lt;p&gt;This is a great technical support!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: About the use of timer</title><link>https://test-devzone.nordicsemi.com/thread/366677?ContentTypeID=1</link><pubDate>Fri, 06 May 2022 10:36:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e57d1e5-2911-4128-af6c-c9bf65c2dc7a</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The only peripheral that can give you the resolution you need, is the TIMER as you have found. There is no COUNT register&amp;nbsp;available from software there, but there are several capture registers with tasks associated with them. To time something, you trigger capture and the internal counter value is&amp;nbsp;copied to the capture register. There are several ways to do this. For instance,&amp;nbsp; you can start the timer on the first signal (either via PPI or SW), and then capture it on the second signal&amp;nbsp;&lt;span&gt;(either via PPI or SW). Alternatively, you can let the timer run and use two capture registers and capture the counter by both signals and&amp;nbsp;calculate the difference (remember to handle the special case where the counter wraps around). This is an example of the second approach:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void test_timer(void)
{
    uint32_t sample_1;
    uint32_t sample_2;
    // Configure and start timer:
    NRF_TIMER3-&amp;gt;BITMODE     = TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos;
    NRF_TIMER3-&amp;gt;MODE        = TIMER_MODE_MODE_Timer &amp;lt;&amp;lt; TIMER_MODE_MODE_Pos;
    NRF_TIMER3-&amp;gt;PRESCALER   = 0;
    NRF_TIMER3-&amp;gt;TASKS_START = 1;

    NRF_TIMER3-&amp;gt;TASKS_CAPTURE[0] = 1;   // Take first timestamp
    test_function();                    // Measuring the time of this...
    NRF_TIMER3-&amp;gt;TASKS_CAPTURE[1] = 1;   // Take second timestamp

    sample_1 = NRF_TIMER3-&amp;gt;CC[0];       // Read out first timestamp
    sample_2 = NRF_TIMER3-&amp;gt;CC[1];       // Read out second timestamp

    uint32_t diff_time = sample_2 - sample_1;   // Calculate diff

    LOG_INF(&amp;quot;test_timer used %d ticks.&amp;quot;, diff_time);    // Note that clock ticks at 16 000 000 Hz
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>