<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Is there a bug in micros()?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1098</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:58 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1098" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "Is there a bug in micros()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1098#post-6923</link>
			<pubDate>Thu, 20 Oct 2011 22:06:27 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6923@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;looks like &#34;someone&#34; indeed made a stupid mistake. sorry about that; and thanks for the fix (again).&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/f7e384a5eaa1e1f9f6bf315a8860d9d61284edc3&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/f7e384a5eaa1e1f9f6bf315a8860d9d61284edc3&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "Is there a bug in micros()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1098#post-6803</link>
			<pubDate>Sun, 09 Oct 2011 20:32:48 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">6803@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Right, that is buggy. I ment it like I posted it at &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=756#post-4462&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=756#post-4462&#60;/a&#62;. Looks like someone did not cut&#38;amp;paste my code, so the current version is buggy :(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Is there a bug in micros()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1098#post-6793</link>
			<pubDate>Sat, 08 Oct 2011 20:09:59 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6793@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;To help a user, I ended up looking at the source of micros()&#60;br /&#62;
&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1082&#38;amp;page=2#post-6792&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1082&#38;amp;page=2#post-6792&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;To save folks some time, here is the source of micros() again:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;static inline uint32 micros(void) {
    uint32 ms;
    uint32 cycle_cnt;
    uint32 res;

    do {
        cycle_cnt = systick_get_count();
        ms = millis();
    } while (ms != millis());

    /* SYSTICK_RELOAD_VAL is 1 less than the number of cycles it
       actually takes to complete a SysTick reload */
    res = (ms * US_PER_MS) +
        (SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND;

    return res;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I think there is a bug.&#60;br /&#62;
I think&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;do {
        cycle_cnt = systick_get_count();
        ms = millis();
    } while (ms != millis());&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;should be&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;do {
        ms = millis();
        cycle_cnt = systick_get_count();
    } while (ms != millis());&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I think the idea is to detect if systick has wrapped around, and hence incremented millis(), hence the second one would be right.&#60;br /&#62;
What do you think?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
