<?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: More accurate analog reads</title>
		<link>http://forums.leaflabs.com/topic.php?id=260</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:19:54 +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=260" rel="self" type="application/rss+xml" />

		<item>
			<title>poslathian on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1993</link>
			<pubDate>Mon, 25 Oct 2010 19:22:10 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">1993@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Weve been using the tlv274 opamp, which has good rail to rail performance. Im not sure what its high bandwidth specs are, but its been giving us very good performance with 50KHz audio.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1988</link>
			<pubDate>Mon, 25 Oct 2010 18:50:11 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1988@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;If I had room on my board, I'd implement an opamp. As it is, I think the Maple has sufficient speed.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1977</link>
			<pubDate>Mon, 25 Oct 2010 11:30:47 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1977@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yes - Sorry, I forgot to mention an opamp. &#60;/p&#62;
&#60;p&#62;Right now, a big piece of time used in analogRead is the sample time.&#60;br /&#62;
It doesn't matter what fancy code is written, sample time will eventually dominate.&#60;/p&#62;
&#60;p&#62;I was thinking of Amdahl's Law (in another thread), and meant to add that reducing the ADC sample time would speed analogRead, and maybe the whole program, by maybe 500%.&#60;br /&#62;
All it might take is a $1 (£0.63 GBP :-) opamp in between the ADC pin and the analogue source.&#60;/p&#62;
&#60;p&#62;perry - I assume an opamp would need:&#60;br /&#62;
- reasonable bandwidth, i.e. 20MHz+,&#60;br /&#62;
- reasonable slew-rate, i.e. better than 10V/uS, and&#60;br /&#62;
- rail to rail&#60;br /&#62;
is that all?&#60;/p&#62;
&#60;p&#62;It might be helpful if you folks could recommend a reasonable cost part that you have tried, and been happy with.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>perry on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1974</link>
			<pubDate>Mon, 25 Oct 2010 10:48:33 +0000</pubDate>
			<dc:creator>perry</dc:creator>
			<guid isPermaLink="false">1974@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hi there,&#60;/p&#62;
&#60;p&#62;Yes, the current analogRead() implementation is pretty slow and calibrated for &#38;lt;40K input impedance. If you want faster sample times, you can put an opamp buffer or something similar on the front (theoretically has zero input impedance) and achieve about a 1us sample time.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1966</link>
			<pubDate>Sun, 24 Oct 2010 22:30:57 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1966@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, sounds good.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1962</link>
			<pubDate>Sun, 24 Oct 2010 18:07:46 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1962@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The engineering 'heuristic' (rule of thumb) I was taught says allow a factor of 2 headroom, so if the comment in analogRead is accurate, I'd try to stay under 20K. (I suspect that 40K might be fine, but I probably would do an experiment to convince myself.)&#60;/p&#62;
&#60;p&#62;Capacitors do add a bit of resistance, but reasonably quality parts should be &#60;em&#62;way&#60;/em&#62; under 10% of significant (2nd rule of thumb, stuff under 10% is safe :-)&#60;br /&#62;
A reasonable quality capacitor will also have a spec. sheet which gives an upper bound, so it may be practical to confirm that.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1958</link>
			<pubDate>Sun, 24 Oct 2010 13:54:50 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1958@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;It is 10K. Thanks so much!&#60;/p&#62;
&#60;p&#62;EDIT: This also means that as long as the total resistance in the sensor circuit is less than 40K, I should be fine, right? The reason I ask is because I have to use a couple of trimpots here and there as voltage dividers. This means I have 10K overhead already. Do capacitors add resistance?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1954</link>
			<pubDate>Sun, 24 Oct 2010 06:10:56 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1954@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;Basically, you are saying I am fine without needing to sample, delay, then sample again, right?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Yes!-)&#60;br /&#62;
Sorry for my prolix, but inconclusive answer ;-)&#60;/p&#62;
&#60;p&#62;The amount of current flowing through the potentiometer depends on the resitance of the potentiometer. The Maple power supply will give it as much as it will conduct (unless it is an extremly low value potentiometer, in which case you have a different problem).&#60;/p&#62;
&#60;p&#62;So, if the potentiometer is, say 10K, it will conduct 3.3V/10,000 = 0.0003 = 0.3mA&#60;br /&#62;
which wil be okay with one analogRead (I believe the comment in the analogRead code says the sample time is good for 40K or less),&#60;br /&#62;
but if the potentiometer is 1M, it will conduct 3.3V/1,000,000 = 0.000003 = 3uA&#60;br /&#62;
which would benefit from a longer sample time.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1950</link>
			<pubDate>Sat, 23 Oct 2010 19:38:17 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1950@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok... I think I got all that. Basically, you are saying I am fine without needing to sample, delay, then sample again, right? &#60;/p&#62;
&#60;p&#62;I do like the idea of using both ADCs but I am still relatively new to code, especially with the Maple, so messing with base code is a project for another day.&#60;/p&#62;
&#60;p&#62;I know that one sensor is a potentiometer (not really a sensor), so the current is just whatever the Maple decides to give it. The second has a max of 5mA, but a min of 400uA. The third has a a range of 7-10 mA.&#60;/p&#62;
&#60;p&#62;Anyway, not having to employ a sample, delay, sample code would be good. I like to keep overhead and instructions to a minimum.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1940</link>
			<pubDate>Sat, 23 Oct 2010 13:25:19 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1940@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I don't think the ADC is 'cooling down'. I think the two reads may be for a different purpose. &#60;/p&#62;
&#60;p&#62;There is only one ADC on an Arduino, and part of analogRead's job is to choose which pin to sample. &#60;/p&#62;
&#60;p&#62;The ADC has a 'sample and hold' circuit, which holds the voltage steady while the ADC is calculating its value.  You can likely imagine that it might be a problem if the input voltage is wiggling around while the ADC attempts to measure it, and the sample &#38;amp; hold circuit avoids that problem. (The input voltage wiggling around is even worse a problem than it might appear as the ADC does multiple estimates, and by successively improving on its previous approximation, it calculate the digital value of the input voltage.) &#60;/p&#62;
&#60;p&#62;The sample and hold circuit uses a capacitor (think rechargeable battery) which needs some time to match the input voltage, just like it takes time to recharge a battery. How long it takes depends on how much current the thing being sampled can supply. If it can't supply much current, the ADC might start measuring the sample &#38;amp; hold circuit before the sample and hold has matched the external voltage being measured. Reading the value twice, with a delay between, should get the sample &#38;amp; hold closer to the external voltage, and hence the second value should be a bit more accurate.&#60;/p&#62;
&#60;p&#62;So, I think the two successive analoReads may to get the input voltage stable on the sample and hold.&#60;/p&#62;
&#60;p&#62;There is a further complication. I seem to recall the very &#60;em&#62;first&#60;/em&#62; ADC reading on an Arduino takes longer than normal, while it is stabilising, and self-calibrating. So it may be someone wants to ensure that is dealt with.&#60;/p&#62;
&#60;p&#62;The most significant time for the Maple's ADC is not necessarily the 'conversion time', i.e. the time the ADC uses to convert an analog voltage into a number, it can do that in a microsecond if need be. The time which may dominate is the sample &#38;amp; hold time, i.e. the time it takes for the sample &#38;amp; hold circuitry voltage to come to match the external voltage. Have you any control over the external electronics? Do you know approximately what its output impedance is (its ability to supply current)?&#60;/p&#62;
&#60;p&#62;The other point to note is, the STM32F103RB on the Maple has two Analog to Digital Converters. So it is theoretically capable of converting at upto 2,000,000 samples/second. The current Maple library only uses one of the ADC's, but there is nothing to stop you using the other. &#60;/p&#62;
&#60;p&#62;The current Maple library allows the sample &#38;amp; hold circuit to charge for almost 5us.&#60;br /&#62;
If the input circuit can supply current fast enough, this could be reduced significantly.&#60;/p&#62;
&#60;p&#62;Summary. 16ms is so long a time, it isn't an issue. The two analogReads are either to get a consistent read time (having got past the initial stabilisation time), or to get the sample &#38;amp; hold charged and stable.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "More accurate analog reads"</title>
			<link>http://forums.leaflabs.com/topic.php?id=260#post-1936</link>
			<pubDate>Sat, 23 Oct 2010 00:55:33 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1936@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have about 3 analog sensors that are read for one of my projects. The Arduino (which I originally wrote my code for) can have trouble with accurate readings when analog reads are taken in close temporal succession. I think this was due to there being only 1 ADC. How many ADCs does the Maple have, because a lot of the pins have analog capability. Either way, a solution I ran across was to use the code:&#60;/p&#62;
&#60;p&#62;analogRead(pin);&#60;br /&#62;
delay(10);&#60;br /&#62;
var= analogRead(pin);&#60;/p&#62;
&#60;p&#62;What do the experts think? The idea was that the ADC takes time to &#34;cool down&#34; between reads and to stabilize it for successive reads of the same sensor, a &#34;decoy&#34; read is used and then the real read is done. For my purposes, I can't have a 10ms delay because I need the code to be able to run within 16ms. Still, how is the concept? When I am able to test it I will try to post some numbers based on the delay timing.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
