<?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>NRF5 SDK Timer HAL: How can I get the actual value of the Timer?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69800/nrf5-sdk-timer-hal-how-can-i-get-the-actual-value-of-the-timer</link><description>Dear All, 
 
 I need a high frequency clock in order to measure the time between a couple of events. In the RTC HAL there are functions that allow to retrieve the counter value and based on the used prescaler the time elapsed can be calculated. But I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Dec 2020 13:07:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69800/nrf5-sdk-timer-hal-how-can-i-get-the-actual-value-of-the-timer" /><item><title>RE: NRF5 SDK Timer HAL: How can I get the actual value of the Timer?</title><link>https://devzone.nordicsemi.com/thread/286461?ContentTypeID=1</link><pubDate>Wed, 23 Dec 2020 13:07:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2b4000a-937d-4530-8799-382218e61308</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The capture function shown in the code snippet below can be used to read out the TIMER counter register using the driver APIs, or you can call&amp;nbsp; &lt;span&gt;&lt;a title="nrf_timer_cc_get" href="https://infocenter.nordicsemi.com/topic/drivers_nrfx_v2.4.0/group__nrf__timer__hal.html?cp=8_0_3_0_42_1_15#ga237a16bb2596cc350a15f741665b7e75"&gt;nrf_timer_cc_get() &lt;/a&gt;&lt;/span&gt;&lt;span&gt;if you are working directly with the HAL.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const nrf_drv_timer_t timestamp_timer = NRF_DRV_TIMER_INSTANCE(1); // Selecting TIMER1. Make sure it&amp;#39;s enabled in sdk_config.h    

/* Driver requires callback even if timer interrupts are not enabled */
void timer_event_handler(nrf_timer_event_t event_type, void* p_context)
{}

uint32_t timer_timestamp_get(void)
{
    return nrf_drv_timer_capture(&amp;amp;timestamp_timer, &amp;lt;CC register index&amp;gt;);
}
    
void timer_init(void)
{
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&amp;amp;timestamp_timer, &amp;amp;timer_cfg, timer_event_handler);
    APP_ERROR_CHECK(err_code);
} &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Note: for high accuracy measurements you may want to start the more accurate &lt;span&gt;&lt;a title="64 MHz crystal oscillator (HFXO)" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/clock.html?cp=4_0_0_4_3_0_0#concept_rmw_c5y_2q"&gt;64 MHz crystal oscillator (HFXO) &lt;/a&gt;&lt;/span&gt;&lt;span&gt;clock. The system defaults to the HFINT clock.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vidar&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>