Electrical – Convert ADC value to real voltage

adcmathmicrocontroller

I want to measure the input voltage to my circuit. The input voltage is supposed to be anything between 7 to 35 Volts.

I have a micro-controller with 12bit ADC. I am using a simple voltage divider to connect a fraction of input voltage to the ADC pin.

The voltage divider is simply a R1 = 82k on top and R2 = 5.6k resistor on bottom.

According to my calculation, at 35V I should get (never mind the tolerance):

V_IN = (V_SUPPLY * R2) / (R1 + R2) = (V_SUPPLY * 5k6) / (82k + 5k6) = 2.24

And the same calculation at 7 Volts I should get 0.4V into the ADC pin.

Now the question is, how to convert the raw value of the ADC to a voltage?

If I supply my circuit with 12V and if I did the programming of ADC correct, I am reading the raw value of around 840 out of my ADC.

The ADC reference voltage of controller is 3.3 Volts.

Best Answer

V = (R/4096)Vref(82K + 5.6K)/5.6K

Which gives me about 10.6V, which I suspect is too far off from 12.0V to be explained by even 5% resistor tolerances and a few percent Vref tolerance.