adc simple question about ADC conversion to voltage

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i've a simple question about ADC conversion to voltage

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

where ADC is the ADC value read on the pin, Vref is the ADC reference voltage

reading atmega datasheet (ADC Conversion Result pag 199) CONVVAL is 1024

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 ;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The total number of steps is 1024

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@bobgardner
thanks for this "visualization" tip

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

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If my voltmeter says AREF is 5.000V, and the a/d is reading 1023, I want to print out 5.000V. To do this, I multiply by 5.0/1023.0 and I'm happy as can be.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Koshchi wrote:
That depends on what you mean by "right"

right because it is written on avr datasheet :)
anyway, for my next project i will chose the datasheet 1024 suggested value, but if i need something like a multimeter i will chose 1023.