<?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/"><channel><title>Using millis() like in Arduino.</title><link>/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><description>Here are two simple functions to use when you want to use timestamps for time measurement.
uint32_t millis(void)
{
 return(app_timer_cnt_get() / 32.768);
}

and for comperison of current with given timestamp with rollover correction (thanks to.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Thu, 12 Oct 2017 06:51:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>schef</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Aha..i had problems yesterday thank God i connect the buzzer to beep on every startup and it was beeping every 8 minutes :)&lt;/p&gt;
&lt;p&gt;The use-case was:&lt;/p&gt;
&lt;pre&gt;#define MINUTE 60*1000

uint32 millisPassed(uint32_t localMillis)
{
    return(compareMillis(localMillis, millis()));
}
&lt;/pre&gt;
&lt;p&gt;This is what i used for help and the requirement was:&lt;/p&gt;
&lt;pre&gt;if(millisPassed(lastMessage) &amp;gt; 15 * MINUTE)
{
    sd_nvic_SystemReset();
}
&lt;/pre&gt;
&lt;p&gt;Is there another solution for the OVERFLOW without using hardcoded number but the PRESCALER?&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Wed, 11 Oct 2017 14:19:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>Nicolas Brunner</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I made an error, the overflow should be #define OVERFLOW ((uint32_t)(0xFFFFFF/32.768)) because the app_timer_cnt_get() use the RTC who is a 24 bits counter.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Wed, 11 Oct 2017 14:12:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>Nicolas Brunner</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;You won&amp;#39;t be able to measure millisecond with a prescaler of 32768&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Wed, 11 Oct 2017 13:48:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>schef</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I had some more ploblems with #define OVERFLOW ((uint32_t)(0xFFFFFFFF/32.768)).
It should have been something like #define OVERFLOW ((uint32_t)((512*32768)/32.768)) because of PRESCALER which is 32768.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Tue, 03 Oct 2017 11:32:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>schef</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;You are right. I will edit the post.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Mon, 02 Oct 2017 13:35:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>Nicolas Brunner</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;millisPassed() is bugged because millis() doesn&amp;#39;t overflow after 0xFFFFFFFF but after 0xFFFFFFFF/32.768. Here is my proposition (not tested):&lt;/p&gt;
&lt;pre&gt;#define OVERFLOW ((uint32_t)(0xFFFFFFFF/32.768))

uint32_t millisPassed(uint32_t localMillis) {
  uint32_t currentMillis = millis();
  if (currentMillis &amp;lt; localMillis) {
    return currentMillis + OVERFLOW + 1 - localMillis;
  } else {
    return currentMillis - localMillis;
  }
}
&lt;/pre&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Fri, 29 Sep 2017 18:41:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>Julie H</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Not actually using milliseconds, but run a 1024Hz time-base. The time error isn&amp;#39;t all that bad, there&amp;#39;s no weirdness caused by imprecision and you&amp;#39;re not using floating point on a part that may not include an FPU.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Thu, 28 Sep 2017 07:03:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>schef</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;What would be you solution to this idea then?&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Wed, 27 Sep 2017 16:03:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>Julie H</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Please keep in mind that 1,000 does not go evenly into 32,768. The above solution can misbehave if the application expects each of the values modulo 1000 to be returned once, and only once, every wall-clock 1 millisecond.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Using millis() like in Arduino.</title><link>https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/using-millis-like-in-arduino</link><pubDate>Tue, 19 Sep 2017 02:39:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1c2f757-dbce-4a44-acad-24a4fccb69af</guid><dc:creator>Mahesh Venkitachalam</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Nice! Might be good to also show how the timer is started and stopped. Also app_timer_cnt_diff_compute can compute the diff taking overflow into account.&lt;/p&gt;
&lt;img src="https://devzone.nordicsemi.com/aggbug?PostID=1060&amp;AppID=4&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>