12 posts / 0 new
Author
Message

let's consider an atmega8

set ADC accurancy to 10bit, so that my ADC data register will return values from 0x0000 to 0x03FF i.e. 0 to 1023, i will have 1024 values

if i would like to get a voltage for a pin, i should read ADC value for the analog pin, solve this formula

Vin = ADC * Vref / CONVVAL

now my question, ADC can have a minimum value of 0 (0x0000), and a maximum value of 1023 (2^10-1, 0x03FF), i do not understand why CONVVAL is 1024 from datasheed and not 1023, also i've found some source code using 1023 and other 1024.

anyone can clarify this to me?
thanks ;)

The total number of steps is 1024

Quote:

The total number of steps is 1024

IOW 0 counts as a valid reading. 1..1023 is 1023 steps and plus 0 that makes 1024.

1024 is 0x0400. That takes 11 bits to represent.

So, in a 10 bit system, the largest possible number is 0x03ff.

As far as CONVAL, that is the result of the design of the ADC. With these ADCs, that is the way it is designed. End of question.

So, correctly, you will not be able to correctly read an input that is exactly equal to Vref. You will always be limited to a maximum input that is 1 bit below Vref.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

so if i consider Vref = 5
i will have max value for ADC = 1023
max value for Vin = 1023 * 5 / 1024 = 4.995V
not 5.
this sound strange, but correct?

ka7ehk wrote:

So, correctly, you will not be able to correctly read an input that is exactly equal to Vref. You will always be limited to a maximum input that is 1 bit below Vref.

ok, now is clear :)

thank you both!!

Isnt it better to think of 1023 'spaces' between the 1024 quantization steps, so a reading of 0 is somewhere between 0 and 5mv, 1 is 5-10, and 1023 would be between 4.995 and 5.000? Like a line draw. Pixel 0 is in the space just to the right of 0 and before 1?

Imagecraft compiler user

Digging in the old Matlab folder. One looks better than the other.

If you do a calibration then you will most likely not come up with 1/1023 or 1/1024 anyway.

Attachment(s):

@bobgardner
thanks for this "visualization" tip

@snigelen
to me "looks better" 1023, but 1024 is right :)

Quote:
to me "looks better" 1023, but 1024 is right
That depends on what you mean by "right" and what you need the output for. If you want the equivalent voltage for each value, then neither is "right", since, as Bod said, each value represents a range, not a specific value. In general, using 1023 is likely more useful. For values less than 512, the result will be on average slightly low, and for values > 512 the result will be on average slightly high.

Regards,
Steve A.

The Board helps those that help themselves.