<?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: Micros error been fixed?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1217</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:24:49 +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=1217" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7361</link>
			<pubDate>Thu, 15 Dec 2011 20:14:44 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7361@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bart_dood - An oscilloscope would be very handy, especially if it is a storage scope.&#60;/p&#62;
&#60;p&#62;I did have a an idea.&#60;br /&#62;
Could you just try a dumb test monitoring the lines directly?&#60;br /&#62;
This attempts to count the number of pulses on each line:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;setup() {
     pinMode(10, ...);  // use the same mode as your existing code
     pinMode(11, ...);  // use the same mode as your existing code
     pinMode(12, ...);  // use the same mode as your existing code

     int count10 = 0;
     int count11 = 0;
     int count12 = 0;

     const int* address10 = bb_perip(GPIOA_BASE-&#38;gt;IDR, 4);  // bit band address for pin 10
     const int* address11 = bb_perip(GPIOA_BASE-&#38;gt;IDR, 7);  // bit band address for pin 11
     const int* address12 = bb_perip(GPIOA_BASE-&#38;gt;IDR, 6);  // bit band address for pin 12

     int state10 = *(address10);    // initialise current state
     int state11 = *(address11);
     int state12 = *(address12);

     for (int i=0; i&#38;lt;1000000; ++i) {  // count pulses as fast as practical
         count10 += (*(address10) == state10)? 0 : 1;   // count if pin 10 changed
         count11 += (*(address11) == state11)? 0 : 1;   // count if pin 11 changed
         count12 += (*(address12) == state12)? 0 : 1;   // count if pin 12 changed

         state10 = *(address10);
         state11 = *(address11);
         state12 = *(address12);
      }

      SerialUSB.print(&#38;quot;Pin 10 count = &#38;quot;);  SerialUSB.println(count10);
      SerialUSB.print(&#38;quot;Pin 11 count = &#38;quot;);  SerialUSB.println(count11);
      SerialUSB.print(&#38;quot;Pin 12 count = &#38;quot;);  SerialUSB.println(count12);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I don't know what is happening in your system, but this is a way to remove the event/interrupt mechanism. If the pulses are very fast (sub microsecond, I guess), it might miss some, but otherwise should give numbers which look about right compared to the oscilloscope.&#60;/p&#62;
&#60;p&#62;(WARNING: I haven't compiled or tested that code)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7359</link>
			<pubDate>Thu, 15 Dec 2011 13:36:56 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7359@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm thinking I might hook an Oscope to the pins and take a look at how clean the signals are. I have access to a nice one here.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7358</link>
			<pubDate>Thu, 15 Dec 2011 13:05:40 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7358@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi gbulmer, &#60;/p&#62;
&#60;p&#62;I am pretty confident its nothing to do with USB etc. I ran into this problem before I had any SerialUSB prints at all, I only added one to try and diagnose where the problem is.&#60;br /&#62;
The pins on my test setup here (on my desk at work) are just wires from the arduino to the maple, nothing more.&#60;br /&#62;
I might be able to add some low capacitance caps to ground to iron out signal noise if that is the source of the problem. On the real setup these interrupts are triggered by hall sensors inside a brushless motor.&#60;/p&#62;
&#60;p&#62;How can I tell if the interrupt is level or edge triggered? It would still be good to fix this problem without my workaround as I think it will add a little more complication elsewhere in my code.&#60;/p&#62;
&#60;p&#62;I've noticed the arduino is also very sensitive when an interrupt is set to CHANGE rather than rising etc, they become extremely jumpy.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7353</link>
			<pubDate>Wed, 14 Dec 2011 20:36:12 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7353@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bart_dood - I'm pleased you have a workaround. &#60;/p&#62;
&#60;p&#62;Are you reasonably confident that:&#60;br /&#62;
a. the USB output isn't upsetting things - could you remove that output (maybe just store a few thousand values into an array)&#60;br /&#62;
b. nothing is screwing up the state of the pins - could you put some LEDs on the pins to see what is happeing?&#60;br /&#62;
c. is the interrupt being level triggered, rather than edge triggered - that might explain multiple runs of the interrupt routine
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7350</link>
			<pubDate>Wed, 14 Dec 2011 14:25:55 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7350@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Sorry to keep posting. I've found a work around. &#60;/p&#62;
&#60;p&#62;It seems when I calculate my velocity inside the interrupt function, it for some reason repeats and calculates it again, sometimes once sometimes twice. This leads to errors in the velocity number.&#60;/p&#62;
&#60;p&#62;When I add a flag that only allows one single velocity calc and then this flag gets set false, eventually to be reset elsewhere it does a single velocity calc and no errors.&#60;/p&#62;
&#60;p&#62;I've tested it over lots of different speeds of interrupt and it works, zero errors now. I can't understand why this works exactly or why the code would repeat itself seemingly randomly but for now this is a working fix.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7349</link>
			<pubDate>Wed, 14 Dec 2011 13:02:49 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7349@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, so I have set my maple code to read each interrupt pin after an interrupt on one of them. The other two are set LOW from the arduino.&#60;/p&#62;
&#60;p&#62;Oddly when I read them they are randomly showing HIGH. How can this be? is it some kind of weird cross talk or bounce that is triggering them? They are never set high, always held LOW.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7348</link>
			<pubDate>Wed, 14 Dec 2011 12:48:58 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7348@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Just to add one more thing. If I have one interrupt and I send an ON/OFF signal (from an arduino) to it, it triggers correctly and reports back (via serialUSB) the correct time between pulses, whether change or rising.&#60;/p&#62;
&#60;p&#62;However if I have two interrupts in the maple code, even when I am still only sending a signal to the OTHER pin, it still screws up the time. My serialUSB starts sending out screwy numbers. Considering I'm not even sending out a signal to the other interrupt pin this is head scratching.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7347</link>
			<pubDate>Wed, 14 Dec 2011 12:46:06 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7347@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi gbulmer/all,&#60;/p&#62;
&#60;p&#62;I think I've narrowed the problem down a little. I have 3 external interrupts on pins 10, 11 and 12. They are all set to interrupt on a CHANGE. &#60;/p&#62;
&#60;p&#62;If I just have one of the interrupts it seems to work fine, the problem happens when I have two or three. It starts spitting out errors.&#60;/p&#62;
&#60;p&#62;When I say I fixed the compiler bug I switched around the line that is in the wrong place in the wiring time file. It didn't make any difference to my problem.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7346</link>
			<pubDate>Wed, 14 Dec 2011 08:37:50 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7346@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bart_dood - my intall of 0.0.12 still contains the micros() bug we spotted a while ago:&#60;br /&#62;
&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1098&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1098&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Have you got the corrected code installed?&#60;/p&#62;
&#60;p&#62;When you say &#34;I fixed the compiler bug&#34;  what are you describing?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7343</link>
			<pubDate>Tue, 13 Dec 2011 19:40:24 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7343@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi Folks, I've done some more checking and testing. I fixed the compiler bug and it didn't make any difference.&#60;br /&#62;
I looked at my code more and it seems to be related to the 'CHANGE' on the interrupt, when I have it as 'RISING' the calculation works. I need to figure out whats happening but I think its code related.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7341</link>
			<pubDate>Tue, 13 Dec 2011 17:24:44 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7341@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I just checked wirish/wirish_time.h on my workstation here at work and the micros() bug is there, I'll fix the bug when I get home and see if it fixes my problem.&#60;/p&#62;
&#60;p&#62;I'll report back if it does.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Micros error been fixed?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1217#post-7339</link>
			<pubDate>Tue, 13 Dec 2011 16:36:32 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7339@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi folks,&#60;/p&#62;
&#60;p&#62;I am working on some firmware that has external interrupts which then times how long between interrupts.&#60;br /&#62;
My interrupt function just subtracts the previous micros() time from the current micros() time to calculate the difference. It sets a flag high and thats all.&#60;/p&#62;
&#60;p&#62;I've tested this under different speeds (times) and for example it will work with 60 millisecond cycles and outputs the right time difference (around 60,000 microseconds). But then when I slow things down or speed things up, I'll get these weird values, like 900 microseconds on one cycle and then like 40000000 on the next? &#60;/p&#62;
&#60;p&#62;I've stripped everything else out my code and it still does this. Is this related to the bug in micros that someone discovered a while back? I'm on version 0.0.12&#60;/p&#62;
&#60;p&#62;My variables are all unsigned integers and I don't think I'm having problems with the values rolling over or going negative.&#60;br /&#62;
Just can't figure out whats going on....(scratches head).&#60;/p&#62;
&#60;p&#62;Thanks for the help
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
