I have a DUE test board where I use most of the analog inputs. For that test setup, I have written an automated test that reads the analog inputs and compares it with expected values.
When compiling with IDE 1.5.4, all runs fine. Compiling the same sketch with 1.5.5, I get mostly wrong analogRead results. I suspect a problem with the ADC initialization change that was introduced with 1.5.5. While appreciating a higher speed for A/D conversion, for sure no such problem must result from that change.
Please find below a few lines of code that I use.
I do not know if that could be important, but I apply the test voltages via 10kOhm series resistors (which should not be a problem since the analog inputs have a very high impedance). And another detail: I use an external 2.5V reference.
For now, I will revert to IDE 1.5.4, hopefully a solution will be found for 1.5.6.
Can anyone meanwhile confirm the bug, and is there a patch possible in the libraries of IDE 1.5.5?
#define A_U_IN 11
static const unsigned char AinPins[] = {
0,1,2,3,4,5,6,7
};
unsigned short Ain[sizeof(AinPins)];
unsigned short Apower;
boolean AinOk[sizeof(AinPins)];
boolean ApowerOk;
// Note: external reference voltage is 2.5V
static const unsigned short AinTest[] = {
1870, 1900, //=DAC0, set to value 1800, at A0
2130, 2170, //=DAC1, set to value 2200, at A1
795, 843, //=0.50V at Ain2
1203, 1255, //=0.75V at Ain3
1610, 1667, //=1.00V at Ain4
2018, 2078, //=1.25V at Ain5
2425, 2490, //=1.50V at Ain6
2833, 2902 //=1.75V at Ain7
};
// Following code is in a loop:
// Read the analog inputs and compare with pre-defined values
for (i = 0; i < MIN(sizeof(AinPins), 8); i++) {
Ain = analogRead(AinPins*);*
AinOk = (Ain >= AinTest[i << 1] && Ain <= AinTest[(i << 1) + 1]);
* }*
* Apower = analogRead(A_U_IN);
_ ApowerOk = (Apower >= 2701 && Apower <= 3243);
// ... other I/O and text output via USB*_