ADC: dividing by 1024 or 1023?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
chip overclock
 
Posts: 5
Joined: Mon Jan 30, 2012 11:36 am

ADC: dividing by 1024 or 1023?

Post by chip overclock »

I know I'm just being my usual anal-retentive/obsessive-compulsive self here, but in this line of work those things are virtues. Searching both this forum and others, I see some folks using 1024 and others 1023 as the scaling factor for the analog-digital convertor on the AVR. Since the output of the ADC is a 10 bit value, 0x00 - 0x3ff, I don't see how the divisor can be anything but 1023, since that's the maximum value. So with a 5V reference, the formula would be something like VOLTS = (ADC * 5.0) / 1023.0, the idea being (ADC * 1023.0) can be thought of as a fractional percentage of the reference voltage, the maximum percentage being 1.0. Reading the Atmel data sheet does not disabuse me of this notion. But my usual rule when I'm the only guy that says BAR and everyone says FOO is I'm probably wrong. What am I missing?

- Chip Overclock

User avatar
chip overclock
 
Posts: 5
Joined: Mon Jan 30, 2012 11:36 am

Re: ADC: dividing by 1024 or 1023?

Post by chip overclock »

Sorry, I obviously meant "(ADC / 1023.0) can be thought of as a fractional percentage)". Senior moment.

User avatar
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 6:59 pm

Re: ADC: dividing by 1024 or 1023?

Post by philba »

This come about because 10 bits can only count up to 1023 (0x3FF in hex). 1024 requires 11 bits to represent. Also, 10 bits can hold 1024 different values of which 0 is one of them.

Note that the literature is often imprecise but I believe that an ADC can never actually return the value of its reference. 0x3FF indicates that the actual input voltage is between 1023/1024 *Vref and Vref. Since we are talking about <.1% error maximum, it's not a big deal.

User avatar
chip overclock
 
Posts: 5
Joined: Mon Jan 30, 2012 11:36 am

Re: ADC: dividing by 1024 or 1023?

Post by chip overclock »

I agree that the difference isn't a big deal. But the key phrase for me is "an ADC can never actually return the value of its reference". Thanks.

User avatar
sblock
 
Posts: 2
Joined: Fri Oct 30, 2015 9:51 pm

Re: ADC: dividing by 1024 or 1023?

Post by sblock »

The CORRECT number to divide by is 1024 -- NOT 1023! There is a whole lot of discussion about this point on the web, because a great number of people simply got this wrong.

The proper formula for converting ADC to volts is : volts = (ADC*Vref)/1024, where both volts and Vref are floating point variables, and Vref is the analog reference voltage. This reference is most often 5.0V on the Arduino UNO, but it can also be 3.3V on some Arduino family boards -- or even 1.1V, whenever the analog reference is set to 1.1V by calling the Arduino function analogReference(INTERNAL).

The A/D converter divides the voltage range into 1024 equal parts (10 bits' worth), not into 1023 parts!! It's true that the A/D can never return a value of more than 1023, but the value of 1023 is associated with the highest bin (that's the 1024th bin, not the 1023rd!!), which covers the range up to AND INCLUDING the value of Vref (usually 5V). The A/D converter therefore rounds the voltage DOWN to the bottom of each bin. That's 0V at the low end, and about +4.995V at the high end. Any voltage between 4.995 and 5 volts gives 1023.

By the way, the error in the Arduino ADC is about +/- 2 bits, so even if you use the wrong formula (which will introduce a bias error!), that probably won't be the dominant error in your measurement, anyway! :-)

To repeat: You will find a lot of discussion about this in the web. Nearly half of it gets this point wrong, so beware. Divide by 1024.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC: dividing by 1024 or 1023?

Post by adafruit_support_bill »

The CORRECT number to divide by is 1024 -- NOT 1023
That is correct. Although the full-scale value is 1023, the resolution is 2^10 or 1024 discrete steps.
I believe that an ADC can never actually return the value of its reference.
Not quite sure what is meant by that. But it certainly can return a full-scale value. if you connect your analog input pin to your AREF pin, it will read the full-scale value of 1023.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”