Wrong values when reading a voltage in a pin with analogRead()

Hi, whenever I read voltages from a pin using analogRead() I get a value that is about 85% of the true voltage. The problem appeared when measuring battery voltages in a circuit, resulting in about 4.40 V for a true 5.1 V voltage (which is reduced to fit the 2V range of the ADC)

I’m using a custom board with the Artemis module, but I mounted a small testing circuit with a RedBoard Artemis Nano, getting the same results. The testing circuit applies a constant, 1V voltage to A0, and analogRead() returns 0.83-0.85 V after conversion.

This is the code:

void setup() {
	Serial.begin(115200);
	delay(10);

	pinMode(A0);
	analogReadResolution(14);
}

void loop() {
	uint16_t meas = analogRead(A0);
	Serial.print(meas); Serial.print(" ");

	float volt = meas * 2.0 / 16384.0;
	Serial.println(volt); 
	delay(1000);
}

The ouput is something like this:

6900 0.84

For 1V input analogRead() should return something near 8192 for a resolution of 14 bits, not values around 6900.

I tested it with Eclipse, the Arduino IDE and PlatformIO, getting the same results. Using other ADC pin doesn’t change anything. The problem persists also when other ADC resolutions are used.

The boards are updated to the last version, 1.1.1 at this moment.

Has anyone encountered the same issue?

Thanks,

David.

As usual, I found the cause after posting. It seems to be related to the impedance difference between the ADC input and my circuitry. Seems that I must improve my measuring interface.

The analogread() is always using ADC slot 0 of the Apollo3 chip, which has an impedance of 720K according to the datasheet. Slot 1 to 7 are not used by design, but they have an impedance 3600M and thus less impact on your circuit. As reference an Arduino has about 100M. You could change the slot in the library file ap3_analog.cpp if you want for test.

Good to know Paul - I haven’t gotten so in-depth with the ADC yet. Thanks for sharing!

You can change the slot in the library file ap3_analog.cpp if you want for test.