Go Down

Topic: Due: analogRead() value affects next analogRead() value. ADC settling issue? (Read 3582 times) previous topic - next topic

clone45

Hello,

I've noticed that the values of my analogRead()s seem to be influencing each other on the Arduino Due.  For example, given a small sketch like this:

Code: [Select]

uint16_t a;
uint16_t b;
uint16_t c;

void setup()
{
 analogReadResolution(12);  
 Serial.begin(9600);
 Serial.println("Starting..");
}

void loop()
{
a = analogRead(0);
b = analogRead(1);
c = analogRead(5);

Serial.print(a);
Serial.print(", ");
Serial.print(b);
Serial.print(", ");
Serial.println(c);
}


Adjusting input "a" affects the value read at input "b".  Adjusting the input "b" affects input "c".  And so on...

Here's some example output.  I'm only changing the voltage at input "a".  I'm not adjusting the voltage at input "b", but you can see that it is affected by input "a"'s value:

1865, 37, 392
1853, 37, 392
1840, 37, 392
1806, 38, 392
1709, 39, 392
1634, 40, 392
1554, 41, 392
1472, 42, 392
1369, 43, 393
1260, 44, 392
1129, 45, 392
982, 46, 393
875, 47, 392
723, 48, 392
624, 49, 392
534, 49, 393
486, 50, 392
439, 49, 391
392, 50, 392
353, 50, 392

Here are column #1 and column #2 graphed:
(sorry, my images aren't showing up.  Please see attachment ec_adacs.png)

I don't believe that this is a side effect of my circuitry.  I believe it's something specific to the Arduino Due.  Besides my own Due product, I tested the analog inputs to the nw2s:b, which is a Due based project with an open architecture and got the same results.

In my experiment using the nw2s::b, I left analog input #1 and #3 untouched as I adjusted analog input #2.  Here are my findings:

(sorry, my images aren't showing up.  Please see attachment nws2_adacs.png)

Analog input #1: Stays relatively constant.  It's got some noise, but it's staying between 1425 and 1430.

Analog input #2: This is the input which I'm adjusting using the knob.

Analog input #3: This input is not being modified.  But it's being influenced by analog input #2.  The extremity of the influence seems to be related to the input voltages.

I have noticed that if I read an analog input three times in succession, I can get a clean reading.  For example:

a = analogRead(0);
b = analogRead(1);  <== influenced by the previous analogRead
b = analogRead(1);  <== less influenced
b = analogRead(1);  <== not influenced.  Nice, independent reading.

These experiments are very easy to replicate.  Adding delay() instructions doesn't seem to help.  Is this some sort of ADC settling issue?

Thanks,
Bret



Hackscribble

Hi Bret

There is one ADC which is multiplexed between the analog input pins.  Especially with high impedance sources, this leads to the effect you are seeing.

A typical workaround is to read each value multiple times, as you have seen: discard the first readings and use the last one. 

What do you have connected to the inputs?

Regards

Ray
Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

clone45

Ah, thanks Ray.  Both my project and the nw2s::b have potentiometers on the inputs, as well as a control voltage inputs.

Cheers,
Bret

MarkT

Just for completeness can you confirm you're using v1.5.7 or later?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

MarkT

BTW I've tested this on 1.5.6, full range of input voltage on one pin affects
the next pin by 2 counts at most.  The second pin read was connected to a
voltage divider made of 2 18k resistors between 3V3 and GND, so a nominal
9k impedance.

I think either you are running on an older version (known bugs in analogRead()
or your circuit is higher impedance than 10k - hence the sensitivity.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

clone45

Hi Mark,

I was using a nightly build, but just switched over the v1.5.7.  The issue, for me, is still very pronounced.  I'm seeing one pin reading affect the next by 20 counts (at 12 bit read resolution).  Maybe it is an impedance thing.  I didn't design the PCB - I'm the code guy - but I can ask.

In the meantime, I'm just reading each input 3 times.   :D

Thanks,
Bret

MarkT

Ah, I was using default 10 bit resolution, so seeing 2 LSBs there = 8 LSBs at
12 bit...   Will check properly when back with my Due.

You didn't say what impedance your sources are.

Section 46.7 of the datasheet goes into a lot of detail about the source impedance
v. ADC clock and tracking time.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

clone45

Hi Mark,

I've asked my analog circuitry guy about impedance and will hopefully have an update with that information soon.

Cheers,
Bret

MarkT

I get a variation of 4 LSB counts in 12bit mode (reading A2 directly after
A1 (pot on A1, divider on A2 - my A0 pin is already wired up to some other circuitry).

From what I can see the Due default to maximum ADC clock (20MHz) with appropriate
tracking time.  A 10k impedance ought to be low enough for that, but I think what is
happening is that when channel switching there's some extra settling time needed to
allow for the programmable gain/offset circuitry to settle (even if all the channels
have the same gain/offset programmed).

I suspect you have a higher impedance.  From what I observe I'd say keep source
impedance at/below 5k for an unexciting life!
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up