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?
ADC has a resolution of one part in 4,096, where 212 = 4,096. Thus, a 12-bit ADC with a maximum input of 10 VDC can resolve the measurement into 10 VDC/4096 = 0.00244 VDC = 2.44 mV. Similarly, for the same 0 to 10 VDC range, a 16-bit ADC resolution is 10/216 = 10/65,536 = 0.153 mV.
Relating ADC Value to VoltageThe ADC reports a ratiometric value. This means that the ADC assumes 5V is 1023 and anything less than 5V will be a ratio between 5V and 1023. If your system is 3.3V, you simply change 5V out with 3.3V in the equation.
ADCs follow a sequence when converting analog signals to digital. They first sample the signal, then quantify it to determine the resolution of the signal, and finally set binary values and send it to the system to read the digital signal. Two important aspects of the ADC are its sampling rate and resolution.
The resolution defines the smallest voltage change that can be measured by the ADC. As mentioned earlier, the resolution is the same as the smallest step size, and can be calculated by dividing the reference voltage by the number of possible conversion values.
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.
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:
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With