AWOL:
So you've got 0 to 1023 for 0V to 5V.
And you read 10235 x 1023 / 1024 = 4.995
Hmmmm, gotta fix that
No, you've got to accept that.
Imagine a one bit ADC, with a one volt reference.
You apply 750mV.
What's the voltage on the pin?Answer: the voltage is at least 500mV
Suppose you had a tall narrow bookcase with 8 zero-thinkness shelves and a top.
You stack books on each shelf until it's full and only then do you put books on the next shelf.
The bottom shelf is shelf 0 and every book on shelf 0 is named 0.
The top shelf is shelf 7 and every book on shelf 7 is named 7.
I can get 8 feet of books into the shelves, and none of them will be named 8 or 7.5.
ADC 0 is anything from 0 to VREF/1024
ADC 1023 is anything from VREF x 1023/1024 to VREF
When you use meter sticks and scales, do you account that any measurement is +/- .5 units as it can be between the marks on the scale and get marked as if it were one or the other. That's what the ADC values are, step numbers.
But you know... 1024 does allow near-instant integer division by a 10 bit right shift. And a rounded-down result.
There could be 4.995V to 5V and it's 1023. 1023 represents 4.995V to 5V.
That's a 5 mV gap that works the same at 0-5mV is all 0. 0 represents 0-5mV and a tiny bit more. Not 0V.
So what does the output represent? It should be a series, .5, 1.5, etc, 1022.5, 1023.5, with all measures +/- .5 inclusive. But we go by the marks on our rulers and call the difference error.
I mean, if you want to get technical.
Divide the output by 1023 and it gets mapped to whatever you scale it to, because sometimes it is VREF and what if it's 100 mV more? Still 1023.
What it is? It's a scale 1024 units long with no top mark that rounds every data point down like int() on float.
The output is a representation, not the reality.
I just divide by the number of divisions which is what the output actually counts because they start at 0.