Electronic – What value to use to convert ADC value to voltage

adcconversionmicrocontroller

While working on my project, I got to a point where I don't know the answer. I have a 10-bit ADC (the one incorporated in the ATMEGA328P) and it returns values up to 1023 (210 – 1).

The official documentation states that the equation to convert the values from the ADC to the corresponding voltage is:

$$
V = \frac{V_{in} \cdot ADC}{2^{10}}
$$

But, if the values go up to 1023, then wouldn't it be better to replace the 210 by 210 – 1?

Thanks.

Best Answer

Ignoring the harsh reality of the performance of ADCs which can be cheaply built into MCUs, in the ideal case each output count represents a possible well-defined range of input voltages.

Here is an ideal (according to Atmel's definition) 3-bit ADC.

enter image description here

There are \$2^N\$ steps. In the above example, that is 8. With an ideal unipolar ADC, an input of lower than \$\frac{V_{REF}}{2^{N+1}}\$ will give an output of 0- as you can see above, below 1/16 of the 2V reference voltage the output code will be 0.

Between \$\frac{V_{REF}}{16}\$ and \$\frac{V_{REF}}{16}+\frac{V_{REF}}{8}\$ the output count will be 1 and so on, with each step the same.

When you get up to the top of the range, a count of \$2^N-1\$ (maximum count) will represent a voltage greater than \$V_{REF}\cdot \frac {13}{16}\$.

So- the best guess (minimizing error) for a given count x (where \$ 0 \lt x \lt 2^{N-1}\$) is \$ x \frac{ V_{REF}}{2^{N}}\$, as given in the original question.


Usually MCU ADCs will saturate so ideally in the special case of x=0 you can say the input voltage is less than \$0.5 V_{REF}\cdot \frac{1}{2^N}\$ = \$V_{REF}\cdot \frac{1}{2^{N+1}}\$ and if x = \$2^{N-1}\$ then the input voltage is greater than \$V_{REF}\cdot\frac{ 2^{N+1}-3}{2^{N+1}}\$


Of course with a typical MCU of 10 bits or greater, the ADC error and noise will usually exceed 1 LSB, and Vref will usually not be accurate to 1 LSB either so it doesn't matter that much.


TL;DR

Use the original equation.