I give up Whandall. Believe what you want. Do you have anything useful to contribute, or just vague hints that are nothing more than handwaving?
Not nice. If you don't like what he offers, simply ignore it.
No, the ADC value is 0x3FF for anything equal or above VREF minus one LSB,
that's not the 1024 of the formula.
This discussion about 1023/1024 is as religious as delay/no delay, Strings/cstrings,
I'm quite tired to argue.
Good luck with your project.
Hold on...lemme go get some popcorn ![]()
The formula is a typo. Try it yourself, you will never get more than 1023 (0x3FF) out of the A/D.
Its kind of like a zero based array.
Let me ask it this way....
The first "value" is 0, the 2nd value is 1 ......... the 1024th value is 1023.
The formula describes the relation between ADC, VREF and VIN.
If you want to compute a value, put in the two others and resolve,
that's pure math and there is no 1023 involved, but a 1024.
So you will never see the full VREF, because the result is always one LSB below the real value.
So if your input = Vref then with your equation the output will be:
output = Vref/Vref *1024 = 1 * 1024 = 1024.
Ok now I challenge you to get any condition where the two A/D output registers will total 1024. It won't happen.
See this post by Nick Gammon
You simply don't get it, and I seem to fail with my arguments.
Have a nice day.
Please read the post I linked in #29. It has this exact same discussion. I think you will find which one of us is correct there.
Regards
John
Read the whole discussion summaries, maybe even all the discussions, here
Ahhhh.... I think I understand your position. I apparently did not pick it up from the earlier posts (which I only glanced over).
I think we are in agreement ![]()
Each step is the Vref / 1024. However the output is similar to a zero based array [0 to 1023]
So:
ADCH * 256 + ADCL will have a range of 0 to 1023. So to get a real voltage level the calculation would have to be
ADCH * 256 + ADCL +1 * Vref /1024
If I really wanted to be as exact as possible, I would use the gammon conclusion

I see what you are saying but isn't that assuming the unknown voltage is exactly between steps?
Quite honestly I hadn't investigated the 328 A/D in depth enough to be sure but my belief is the the steps are incremented like a bunch of comparators. There is no rounding in the quantization. This of course would be in a perfect noise free world.
@JohnRob the ADC advanced to the next step as the input signal reaches that level. When the ADC outputs 0, then it is actually somewhere between 0 and 1. So the average is 0.5
There is always noise. When the average is calculated with integers (so no bits gets lost) and the result with float (to get more resolution than 10 bits) then I get: averageRead.ino
Let's say that each step is 5mV.
The ADC outputs 0 for a voltage between 0V (inclusive) and 5mV (exclusive).
The ADC outputs 1 for a voltage between 5mV and 10mV.
and so on.
When reading a value of 1 with analogRead(), then the input is between 5mV and 10V, so it is 7.5mV (average).
The value to describe a range is - at least for me - the center of the range.
The raw value gives the lower bound, your suggested +1 version gives the upper bound.
Well now, if we convert seconds to minutes, do we divide by 59 or 60?
Depends on how fast you are moving.
Don't laugh, I think he's serious ![]()

