11

Let's say I have a 12-bit Analog to Digital Converter (4096 bins). And let's say I have a signal from 0 to 5 Volts.

What is the proper conversion formula to convert ADC bins into Volts?

V = ADC / 4096 * 5

or

V = ADC / 4095 * 5

Do I divide by 4096 because there are 4096 bins in the ADC?

Or do I divide by 4095 because that is the highest value that the ADC returns?

Isaac Waller
  • 32,709
  • 29
  • 96
  • 107
Robert Deml
  • 12,390
  • 20
  • 65
  • 92
  • 1
    Your ADC reference voltage is likely to be wobbling all over the place, unless yo have an extremely good regulator and very wide tracks everywhere, so I doubt it matters what you do; the error will be insignificant! – James Feb 15 '10 at 22:21
  • Note that other than for display purposes, there's actually no big point in calculating the actual voltage. All of your internal calculations should be calculated in ADC increments for precision. Only when you want to display or otherwise send the "real" value to human eyes you should transpose into voltage. – tofro Jun 16 '17 at 12:17

5 Answers5

6

V = ADC / 4096 * 5

is the correct formula for converting the digital value back to (an approximation of) the analog voltage.

This is according to The Data Conversion Handbook, edited by Walt Kester (Newnes, 2005), and available at (as of 2018/10/18) at:

https://www.analog.com/en/education/education-library/data-conversion-handbook.html

See in particular Figures 2.4 and 2.5 in Chapter 2: Figures 2.4 and 2.5 from Data Conversion Handbook

In your case, FS would be 5 V. (And of course you're using a 12-bit ADC, not a 3-bit one.) Note that even if the ADC value is the maximum possible value (4095 in your case), the corresponding analog voltage will be slightly less than the "full-scale" voltage (5 V in your case).

Adam L. Taylor
  • 351
  • 2
  • 7
3

Brian's suggestion about checking ADC datasheet is ideal. BUT! Assuming your maximum voltage (5V) equates to the maximum ADC input (12-bits = 4095), the following conversion should work for you:

const float maxAdcBits = 4095.0f; // Using Float for clarity
const float maxVolts = 5.0f;      // Using Float for clarity
const float voltsPerBit = (maxVolts / maxAdcBits);

float yourVoltage = ADCReading * voltsPerBit;

A quick inspection of the math with Excel leads me to believe this is correct.

Nate
  • 18,892
  • 27
  • 70
  • 93
  • 1
    ... but using floats can be expensive too. – Nate May 21 '09 at 15:49
  • 3
    Use fixed-point arithmetic and bit shifts instead of divides. Or better, don't convert to voltage at all and just work with the 12 bit value from the ADC and when you need to compare it to a voltage just translate the voltage to the same value on the 12-bit scale. – Stephen Friederichs May 23 '09 at 15:25
2

How picky do you want to get? If you want to really get picky, then you should also consider that each "bin" represents a small range of values (about 1.2 mV in your case). So when you convert to a voltage value, do you want to return the voltage value of the middle of the bin, or the lower edge of the bin? That is, do you want to effectively "truncate" or "round" in the value you report?

Also, the ADC's steps are probably even (linear), but take care as to what the ADC does with the bins at the two extremities of the range. Those bins may be possibly half the width of the others. It depends on the ADC, so check the spec.

Whether this concern matters at all depends on your application.

Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
1

The spec for the ADC should identify how 5V is represented in terms of your 12 bits.

I would suspect that 4095 corresponds to 5V and thus your second solution is correct. Otherwise you would never be able to identify a signal of 5V correctly.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
1

For a 12-bit value the maximum representable value is 4095, but of course there are 4096 values total (including zero). Assuming that your ADC is linear then yes, 4095 is equivalent to full scale. This is not necessarily 5V but whatever your reference voltage is equivalent to OR a value exceeding that voltage (of course).

Stephen Friederichs
  • 1,029
  • 6
  • 12