Arduino Due analogRead() repeats itself

Hello All,

I am working on a school engineering project and we are attempting to use a Due for our project. We chose the due for the reasons that it is a Cortex M-3 and it has a double precision floating point unit which the math we need to do requires. In an attempt to implement the control system, I got some strange results from the ADC.

The problem is that the due will read an analog pin once, then reads a second pin, then it reads the first pin again once the loop is restarted. When the first pin is read again, it reports the value read at the second pin almost as if the ADC multiplexer did not switch back to the first pin and rather read the second pin again. Then adding a second pin made things interesting. First A2 was read and that is correct going off a multimeter. Then A8 is read which is also correct. Finally A0 is incorrect simply mirroring A2's value. Then A8 takes over fully and all channels are what A8 has.

I have attached some code with things that I have tried commented out since they changed nothing. I also tried reading a third analog pin to no avail. Attached you will find my code and a log output of its run.

Anyone have any thoughts other than stepping down to C and handling the reads manually? Thank you.

Code:

void setup() {
  Serial.begin(9600);
  pinMode(A2, INPUT);
  pinMode(A8, INPUT);
}

void loop() {
  // When commented, A3 works properly
  int a = analogRead(A2);
  Serial.print(a);

  Serial.print("\t");
  // delay(250); // Does not fix the problem

  // When commented, A2 works properly, switching to A8 does not fix the problem
  int b = analogRead(A8);
  Serial.print(b);
  
  Serial.print("\t");
  
  // adding a third pin did not make things better
  int c = analogRead(A0);
  Serial.println(c);

  // When both uncommented, A2 takes precedent and A3 echos it
}

Log Output (Only the first few lines are of interest):

Reset
808 137 809
137 136 136
136 133 136
137 133 134

I figured out what the problem was and those who are working on the Arduino software already knew about the issue and fixed it in the source code available at github. I explained my understanding of the problem in the link.

http://forum.arduino.cc/index.php?topic=214925.msg1675861#msg1675861

The short version of the solution is to download the latest source from github and build it yourself.

We chose the due for the reasons that it is a Cortex M-3 and it has a double precision floating point unit

Does it? First I've heard of it.


Rob