Adjusting Vref+ on 18M2

InvaderZim

Senior Member
Hi all, quick one about ADC math:

When using the 5V power supply, I'd thought a readadc10 value could be converted to voltage by the equation:
volts = 5*value/1023
where 'value' is the ADC reading, a number from 0-1023.

Therefore, the highest value read would be 5*1023/1023 = 5.000V, assuming a perfect 5V supply. Each 'count' is equal to 5/1023 = 4.89mV.

*Is this correct to this point?*

Using FVRsetup, you can change the reference to 1.024V, which makes the equation 1.024*value/1023, and therefore the highest reading is 1.024V. Each count is 1.024/1023 = (a little over 1mV).

If these equations are correct, why is it a 1.024V reference and not a 1.023V reference? It seems the math would be easier if it were simply 1mV per count. Perhaps it is too small a difference to matter; or perhaps I just have the math wrong.

Thanks!
 

Technical

Technical Support
Staff member
0-1023 actually gives 1024 different readings or "steps", so divide by 1024
However a 1.024 to 1.023V difference is indeed too small a difference to matter anyway.
 

InvaderZim

Senior Member
Thanks! So to summarize, for 10-bit ADC:

With a 5V ref, you get a range of 0-4.995V, or about 4.88mV per count.

With a 1.024V ref you get a range of 0-1.023V, and exactly 1mV per count.

Volts = Ref*Reading/1024
 

hippy

Ex-Staff (retired)
Unless I've misunderstood the Microchip datasheets READADC will always return a value of between 0 and 255, READADC10 a value between 0 and 1023. The maximum value ( 255 or 1023 ) will be returned when the input equals Vref.

So if using READADC10 and the normal 5V supply as VRef; 0=0V, 1023=5V, each step is 5V/1023. For a 1.024 Vref, 0=0V, 1023=1.024V, each step is 1.024V/1023.
 

InvaderZim

Senior Member
Hence my confusion! :)

I'd thought there were "1024 levels" but only 1023 "steps" or "increments," hence divide by 1023. But then there's the question: is it 1mV per step, or is it 1.024V full scale? It can't be both! And if it's the former, why do all the VRef makers sell 1.024V (or 2.048, or 4.096) references when you really want 1.023?

I say we arm wrestle for it.
 

Technical

Technical Support
Staff member
Imagine a flight of steps with 1024 steps. There are actually 1023 uprights, but 1024 flats.

So the left hand side of the bottom flat is 0, and the right hand side of the top flat is 1023. But a value slightly below 5V is still on the top step, and a value slightly above 0V is still on the bottom step.

So as there are 1023 uprights, we stand corrected in that you do divide by 1023.

But in terms of voltage you will still get a 1023 reading even if the voltage is anything between (5V - 1 step) and 5V.

1.024V is just easier to make than 1.023V. However the level of accuracy means it doesn't matter, as the tolerances on ADC readings and voltage reference cancel it all out anyway.
 
Top