<?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>Issue on get ms on zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119826/issue-on-get-ms-on-zephyr</link><description>Hello, 
 
 I’m trying to obtain millisecond precision on nRF Connect using the MCU’s internal RTC. 
 
 My code: 
 
 After 131000 ms, a got: 
 
 Could someone help me find where my error is?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 14 Mar 2025 11:58:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119826/issue-on-get-ms-on-zephyr" /><item><title>RE: Issue on get ms on zephyr</title><link>https://devzone.nordicsemi.com/thread/527359?ContentTypeID=1</link><pubDate>Fri, 14 Mar 2025 11:58:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eacff04b-279f-473d-b06e-07ec178cc763</guid><dc:creator>Luis Santos</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I encountered an overflow issue when converting ticks to milliseconds using the operation:&lt;/p&gt;
&lt;p&gt;uint32_t ms = (total_ticks * 1000UL) / freq;&lt;/p&gt;
&lt;p data-start="229" data-end="275"&gt;To resolve it, I modified the code as follows:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;uint64_t ms = ((uint64_t)total_ticks * 1000UL) / freq;&lt;br /&gt;LOG_INF(&amp;quot;ticks: %u, wrap_counter: %u, total_ticks: %u, ms: %u&amp;quot;, ticks, wrap1, total_ticks, ms);&lt;br /&gt;return (uint32_t)ms;&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;&lt;br /&gt;This change prevents the overflow, but I&amp;rsquo;m not entirely convinced it&amp;rsquo;s the optimal solution. Could please advise on the best or recommended way to obtain milliseconds from the RTC on Zephyr?&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>