<?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: Time stamp for analogRead() Accuracy</title>
		<link>http://forums.leaflabs.com/topic.php?id=717</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:23:03 +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=717" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Time stamp for analogRead() Accuracy"</title>
			<link>http://forums.leaflabs.com/topic.php?id=717#post-4175</link>
			<pubDate>Wed, 06 Apr 2011 11:57:43 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4175@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;StephenFromNYC -&#60;/p&#62;
&#60;blockquote&#62;
&#60;blockquote&#62;&#60;p&#62;    16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four)&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I do not know how the Arduino resolution was determined for micros().&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;The Arduino millis() timer is driven by the ATmega's Timer/Counter0 peripheral, with is an 8bit timer.&#60;br /&#62;
It is set up to count with a frequency of 16MHz/64, and hence counts at 4 microseconds.&#60;/p&#62;
&#60;p&#62;Timer/Counter0 generates an 'overflow' interrupt which is used to update a millis-count variable used by millis(). It isn't updated by software. Once it is initialised, it just counts from 0 to 255 in hardware.&#60;/p&#62;
&#60;p&#62;micros() uses the millis-count variable and the actual value of the hardware counter in Timer/Counter0 to give a time stamp with 4 microsecond precision.&#60;/p&#62;
&#60;p&#62;The time on the Maple, uses a STM32F hardware timer called &#60;code&#62;sysclock&#60;/code&#62;, intended for timestamps. Like the Arduino's Timer/Counter0, it isn't normally updated in software; once initialised the timer keeps itself going in hardware. I just read the code, and it is counting at 72MHz, so the jitter on it is way smaller than 1 microsecond. &#60;/p&#62;
&#60;p&#62;(I was mistaken about the precision of this time source. The ST documentation suggests counting at a much lower frequency than 72MHz, so I had assumed maplelib did that, but it doesn't.)&#60;/p&#62;
&#60;p&#62;The nice thing about using timers is they don't 'jitter' because they count in hardware, and aren't effected by interrupts.&#60;/p&#62;
&#60;p&#62;The Arduino delayMicroseconds uses a similar 'busy wait' technique to the one in maplelib. Neither Arduino nor Maple use the underlying timers, but instead run some instructions a calculated number of times, so do have jitter caused by interrupts.&#60;/p&#62;
&#60;p&#62;(NB - &#60;code&#62;sysclock&#60;/code&#62; isn't available as a source of triggers to the ADC.)&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of the LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>StephenFromNYC on "Time stamp for analogRead() Accuracy"</title>
			<link>http://forums.leaflabs.com/topic.php?id=717#post-4173</link>
			<pubDate>Wed, 06 Apr 2011 10:15:48 +0000</pubDate>
			<dc:creator>StephenFromNYC</dc:creator>
			<guid isPermaLink="false">4173@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here is an apples:oranges comparison.&#60;/p&#62;
&#60;p&#62;From the arduino web site:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.arduino.cc/en/Reference/Micros&#34; rel=&#34;nofollow&#34;&#62;http://www.arduino.cc/en/Reference/Micros&#60;/a&#62;&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four)
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I do not know how the Arduino resolution was determined for micros().&#60;/p&#62;
&#60;p&#62;Enjoy!&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://forums.leaflabs.com/profile.php?id=843&#34;&#62;Stephen from NYC&#60;/a&#62; (full disclosure: I am not a member of the LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Time stamp for analogRead() Accuracy"</title>
			<link>http://forums.leaflabs.com/topic.php?id=717#post-4163</link>
			<pubDate>Tue, 05 Apr 2011 20:41:56 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4163@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Brian - a DMA solution is a good solution, but if you are willing and able to 'get your hands dirty', a timer channel could be used to trigger the ADC conversion. This is slightly intricate code, but I guess less difficult than writing the DMA code. Even then, you might want to avoid it, but it would give very regular samples.&#60;/p&#62;
&#60;p&#62;You might find that their are several sources of delays:&#60;br /&#62;
1. analogRead takes about 6-7 microseconds; that is set in the source code of analogRead to ensure signals with a relatively high output impedance (eg. a few K ohms) are sampled reasonably faithfully&#60;br /&#62;
2. USB generates interrupts when the host PC polls the Maple, so sometimes those interrupts may happen after the delay(50), and before the analogRead, causing 'jitter' or variability&#60;br /&#62;
3. micros() might not have microsecond precision (I think its precision was a couple of usecs)&#60;br /&#62;
4. delayMicroseconds may suffer a bit from USB interrupts causing some variability too&#60;/p&#62;
&#60;p&#62;(for full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bhclowers on "Time stamp for analogRead() Accuracy"</title>
			<link>http://forums.leaflabs.com/topic.php?id=717#post-4152</link>
			<pubDate>Tue, 05 Apr 2011 10:00:35 +0000</pubDate>
			<dc:creator>bhclowers</dc:creator>
			<guid isPermaLink="false">4152@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks Stephen,&#60;/p&#62;
&#60;p&#62;If your assessment is correct that I'll be happy to wait.  Having explicit control over the acquisition rate would be fantastic.  I'm looking at reads on the order of 50us to fill an array--well within the range of the processor speed.  As for transferring data via USB, that was only used a way to look at the data after it was acquired.  That function should have no bearing on the actual read times.  &#60;/p&#62;
&#60;p&#62;I'll stayed tuned for that next release.  Any ideas on a date?&#60;/p&#62;
&#60;p&#62;Cheers,&#60;/p&#62;
&#60;p&#62;Brian
&#60;/p&#62;</description>
		</item>
		<item>
			<title>StephenFromNYC on "Time stamp for analogRead() Accuracy"</title>
			<link>http://forums.leaflabs.com/topic.php?id=717#post-4150</link>
			<pubDate>Tue, 05 Apr 2011 08:52:22 +0000</pubDate>
			<dc:creator>StephenFromNYC</dc:creator>
			<guid isPermaLink="false">4150@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello-&#60;/p&#62;
&#60;p&#62;Brian, this may not be the quick answer you want, but I am waiting for the DMA functions which will be included with the next software release.&#60;/p&#62;
&#60;p&#62;With DMA the ARM Cortex M3 chip will perform analog reads (ADC) without using the processor (no need to call &#60;code&#62;analogRead()&#60;/code&#62;).  Just set up the required ADC timing and the DMA circuits should do the rest.  I do not know how quickly or how much data can be sent via &#60;code&#62;SerialUSB&#60;/code&#62;.  I do not know how data acquisition by the Maple board and transmitting the data from the Maple board to the host is coordinated if you need high speed data acquisition via ADC.&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://forums.leaflabs.com/profile.php?id=843&#34;&#62;Stephen from NYC&#60;/a&#62; (full disclosure: I am not a member of the LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bhclowers on "Time stamp for analogRead() Accuracy"</title>
			<link>http://forums.leaflabs.com/topic.php?id=717#post-4148</link>
			<pubDate>Mon, 04 Apr 2011 23:14:32 +0000</pubDate>
			<dc:creator>bhclowers</dc:creator>
			<guid isPermaLink="false">4148@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm hoping this is a very easy fix. To start, I'm using Maple IDE 0.0.9 and the maple r5 board.  The sketch I have at present attempts to fill an array with both a time stamp of when the data was acquired and the actual analogRead.  The problem of the output can been seen below.  Despite having a delayMicroseconds(50) there seems to be some sort of variable delay that takes approximately 7-8 microseconds.  While livable, it would be nice to have a reproducible time stamp for the analog reads placed into an array--or any process for that matter.  I tried introducing the noInterrupt() call but that still produced the same result.  Any ideas would be appreciated.&#60;/p&#62;
&#60;p&#62;Cheers.&#60;/p&#62;
&#60;p&#62;Brian&#60;/p&#62;
&#60;p&#62;SerialUSB Output:&#60;br /&#62;
####################################&#60;br /&#62;
Micros  DeltaT AnalogIn&#60;br /&#62;
6152400 ,    , 2370&#60;/p&#62;
&#60;p&#62;6152457 , 57 , 2266&#60;/p&#62;
&#60;p&#62;6152515 , 58 , 2186&#60;/p&#62;
&#60;p&#62;6152573 , 58 , 2129&#60;/p&#62;
&#60;p&#62;6152631 , 58 , 2089&#60;/p&#62;
&#60;p&#62;6152688 , 57 , 2056&#60;/p&#62;
&#60;p&#62;6152746 , 58 , 2033&#60;/p&#62;
&#60;p&#62;6152804 , 58 , 2167&#60;/p&#62;
&#60;p&#62;6152862 , 58 , 2115&#60;/p&#62;
&#60;p&#62;6152920 , 58 , 2076&#60;/p&#62;
&#60;p&#62;6152977 , 57 , 2047&#60;/p&#62;
&#60;p&#62;6153036 , 59 , 2178&#60;/p&#62;
&#60;p&#62;6153093 , 57 , 2120&#60;/p&#62;
&#60;p&#62;6153151 , 58 , 2077&#60;/p&#62;
&#60;p&#62;6153211 , 60 , 2048&#60;/p&#62;
&#60;p&#62;6153268 , 57 , 2027&#60;/p&#62;
&#60;p&#62;6153326 , 58 , 2156&#60;/p&#62;
&#60;p&#62;6153384 , 58 , 2107&#60;/p&#62;
&#60;p&#62;6153442 , 58 , 2074&#60;/p&#62;
&#60;p&#62;6153500 , 58 , 2045&#60;/p&#62;
&#60;p&#62;6153557 , 57 , 2177&#60;/p&#62;
&#60;p&#62;6153615 , 58 , 2119&#60;/p&#62;
&#60;p&#62;6153673 , 58 , 2075&#60;/p&#62;
&#60;p&#62;6153731 , 58 , 2050&#60;/p&#62;
&#60;p&#62;6153788 , 57 , 2029&#60;/p&#62;
&#60;p&#62;#################################&#60;/p&#62;
&#60;p&#62;int analogPin = 0;&#60;br /&#62;
// our array size&#60;br /&#62;
int size=25;&#60;br /&#62;
uint32 time[25];&#60;br /&#62;
uint32 rawdata[25];&#60;/p&#62;
&#60;p&#62; void setup() {&#60;br /&#62;
   pinMode(analogPin, INPUT_ANALOG);&#60;br /&#62;
   SerialUSB.begin();&#60;br /&#62;
 }&#60;/p&#62;
&#60;p&#62; void loop() {&#60;br /&#62;
   //noInterrupts();&#60;br /&#62;
   for (int i=0;i&#38;lt;size;i++) {&#60;br /&#62;
     time[i]=micros();&#60;br /&#62;
     rawdata[i]=analogRead(analogPin);&#60;br /&#62;
     delayMicroseconds(50);&#60;br /&#62;
   }&#60;br /&#62;
   for (int i=0;i&#38;lt;size;i++) {&#60;br /&#62;
     SerialUSB.print(time[i]);&#60;br /&#62;
     SerialUSB.print(&#34; , &#34;);&#60;br /&#62;
     if (i &#38;gt; 0) {&#60;br /&#62;
       SerialUSB.print((time[i]-time[(i-1)]));&#60;br /&#62;
       SerialUSB.print(&#34; , &#34;);&#60;br /&#62;
      }&#60;br /&#62;
     else{&#60;br /&#62;
        SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
        SerialUSB.print(&#34; , &#34;);&#60;br /&#62;
      }&#60;br /&#62;
      SerialUSB.println(rawdata[i]);&#60;br /&#62;
   }&#60;br /&#62;
   SerialUSB.println(&#34;&#34;);&#60;br /&#62;
   delay(3000);&#60;br /&#62;
 }
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
