
ADC value divide by 1024 or 1023
#1
Posted 27 July 2011 - 09:56 PM
I'm using an ADC port to measure voltage (of a solar charged battery). I use the standard 3.3V Aref and the default 0-1023 range. With a voltage divider (5k6 + 30k) I'm able to measure just over 20V.
Logic tells me (as well as some examples I found) I should calculate the actual voltage by dividing by the number of steps (float actualVoltage = (float)adcValue / 1024 * 3.3). Except it doesn't match the voltage I'm measuring with my DVM. If I use 1023 (float actualVoltage = (float)adcValue / 1023 * 3.3) the voltages match perfectly. I first missed the mismatch when measuring the voltage directly at the port, since it's much smaller there. At the solarpanel/battery the difference is more noticeable.
Now, simplifying the problem, connecting the ADC port directly to 3.3V gives me 3.2968 when dividing by 1024 and exactly 3.3000 when dividing by 1023.
Can anyone tell me, what the logic is behind this? Or am I missing the logic here completely? Thanks in advance!
#2
Posted 28 July 2011 - 04:34 AM
#3
Posted 28 July 2011 - 08:07 AM


#4
Posted 28 July 2011 - 11:35 AM
#5
Posted 28 July 2011 - 11:55 AM
To be precise, the ADC has 1024 quantization levels, the value of zero corresponds to any analog input in range <0, Aref/1024), the value of one represents any analog input in range <Aref/1024, 2*Aref/1024) etc., the last value represents <1023*Aref/1024, Aref). Thus, the trick here is the interpretation of the measured value.so ADC value of zero corresponds to 0v and ADC value 1023 corresponds to 3.3v
#6
Posted 28 July 2011 - 12:00 PM
The ADC returns a value from 0 to 1023 not 0 to 1024.
0 to 1023 is 1024 different values because zero is a value too.
so ADC value of zero corresponds to 0v and ADC value 1023 corresponds to 3.3v
That is why you divide by 1023 and not 1024.
Not exactly.
Consider the nominal "width" of the ADC reading: it is 1024. That is strictly related to Vref (typically 3.3V).
Now we must slice that segment in many smaller parts: in total are 1024 "tiles" (if you like numbered from 0 to 1023).
By the way, this number is the index of the tile, *NOT* the distance from the origin of the given range.
Let's depict it:
0 1 2 1022 1023 |-------|-------|----- - - - ---|-------| 0 3.3mV 6.6mV 3.297V 3.3V
So, when you read "1" from the ADC, the actual value will fall within the segment spanning from 3.3mV and 6.6mV. Since there's no way to know what's the exact point where the voltage is in, you must take in account that the ADC leaks of an accuracy of 1/2 LSB (i.e. half tile).
FYI, there are some trick to improve "artificially" the precision.
If you add some white noise to the input signal, your ADC readings will fall within a range centered to the real one. When you perform a good average on the samples, you may gain some bit more than the declared accuracy of the ADC.
However that's is much like a math trick, because there are other errors involved in the A/D conversion, and all that work won't have any benefit.
Cheers
#7
Posted 28 July 2011 - 12:26 PM
#8
Posted 28 July 2011 - 12:26 PM
#9
Posted 28 July 2011 - 12:38 PM
For Codeblack, that's right about the decimals. If you have to measure you height having just a 1-meter long stick, how can you give your height precise at centimeter-level?
Anyway, I'd not throw away the project. There's some guy expanding the Netduino with an external ADC chip. As usual, the specialized chips work much better than a bunch of logic doing a bit of all.
The Netduino embedded ADCs are good for a rough reading, such as 1%-accuracy position/voltage (e.g. potmeter, level, etc).
Otherwise why some brands like Analog Devices would create high precision ADC chips?
Cheers
#10
Posted 02 February 2014 - 01:54 PM
Dear Guys,
I cant measure 0.0mV even I put the analog pin to Gnd. it's still read as 3.3 - 6.4mV.... I'm using RTC on A4/A5. If I remove this RTC and undeclare it on the code, I can reach 0.0mV, but impossible while RTC is plug in.
It's annoying... Most My sensor has sensitivity on millivolts range. Does anyone have the same experience? any way out?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users