Pardon me from being such a noob on this field. Just wanna ask regarding on the value of voltage when using analogRead. As mentioned on this article http://arduino.cc/en/Tutorial/ReadAnalogVoltage. The maximum voltage 5volts that will be out on the potentiometer will represent a value of 1023 on the MC
What is the basis of this value or how did it acquire this number?
Seems right to me, too. The maximum reading is 1023, which corresponds to 5.0 (nominally) volts. So, reading * 5.0 / 1023 would, when reading is 1023, result in 5.0. reading * 5.0 / 1024 would result in 4.995.
Seems right to me, too. The maximum reading is 1023, which corresponds to 5.0 (nominally) volts. So, reading * 5.0 / 1023 would, when reading is 1023, result in 5.0. reading * 5.0 / 1024 would result in 4.995.
Section 23.7 of the datasheet explicitly says 1024.
No question that the analogRead() returns ADC count values ranging from 0 to 1023, so 1024 possible values. Now if one should use 1023 or 1024 as the scaling value in any remapping of the value is a topic that always seems to keep coming up, with proponents for both values that claim it's a no brainer as to the correct value. I have no clue as to which is correct, but am surprised that it doesn't have a definitive mathematical provable answer.
Come on software gurus, put this topic to bed once and for all.
Coming at it from a hardware guy I have a more practical 'answer', it doesn't really matter at all because as far as it effecting the accuracy of the remapping calculation as the 0.1% difference probably pails in comparison of the raw accuracy specification of the ADC and basing the calculation assumption that the Avcc reference voltage being exactly +5.000000 vdc, which is probably never the case.
After a bit of head scratching, I have come to agree with Coding Badly. 1024 is the correct value.
As far as I understand it, the issue is that the value of 1023 represents a range of voltage values so the question is: what value within that range do you want the calculation to return? If you want the lowest value, dividing by 1024 gives you that. If you want the highest value, adding one and dividing by 1024 gives you that. If you want the median value, adding 0.5 and dividing by 1024 gives you that.
Come on software gurus, put this topic to bed once and for all. smiley-wink
No head-scratching required.
It's 1024.
We could go into a long argument, with already-posted reductio ad absurdum arguments, but there's a much simpler, compelling argument - Ask yourself - Why else would NatSemi and all the others invest all that money in producing voltage references with strange, non-integer outputs like 1.024V, 2.048V etc?
MarkT:
To be precise the best estimate of input voltage is...
What I remember is that the overall error is the same. The end result being that adding an offset does not accomplish anything mathematically useful. In some cases adding an offset would wreak havoc (e.g. certain PID strategies).
A much better way to improve the estimate is to buy a better ADC. (Or over-sample.)
23.7 ADC Conversion Result
After the conversion is complete (ADIF is high
), the conversion result can be found in the ADC
Result Registers (ADCL, ADCH).
For single ended conversion, the result is
where V
IN
is the voltage on the selected input pin and V
REF
the selected voltage reference (see
Table 23-3 on page 262
and
Table 23-4 on page 263
). 0x000 represents analog ground, and
0x3FF represents the selected reference voltage minus one LSB
0x3FF represents the selected reference voltage ---->minus one LSB<----
1024 - 1 = 1023