Dividing by 1023 or 1024? The final verdict on analogRead

If it does not work in theory, it will never work in practice. If it works in theory, it may not be working in practice; to make it work, a lot of polishing works are required that are the jobs of the Engineers?

GolamMostafa:
If it does not work in theory, it will never work in practice.

It is possible to know how to do something in practice without knowing the theory. The method by which aircraft wings generate lift is a good example.

...R

GoForSmoke:
Say hello to best fit.

Say hello to your personal definition of "best fit".

For everyone else, "best fit" happens when ADC counts are interpreted as being at the midpoint in a bucket.

If the ADC outputs 0 counts for 0V, at what voltage does it output 1 count? (given Vref=5V and a 10 bit ADC)

adwsystems:
If the ADC outputs 0 counts for 0V...

Incorrect. Given that is the assumption for the question there is no point trying to answer.

An ideal successive approximation analog-to-digital converter ("the ADC") outputs 0 for an input voltage range.

...at what voltage does it output 1 count?

Over what range does the ADC output 1? Is that what you meant to ask?

Not at all. I meant to ask what I asked. Perhaps more a more explicit question. What is the lowest voltage (in microvolts) that will produce an output of 1 count from the ADC?

P.S. Based on the project work last night, an Arduino UNO ADC outputs 0 count when the ADC input is connected to 0V (ground), I'm not sure how that can be incorrect.

adwsystems:
What is the lowest voltage (in microvolts) that will produce an output of 1 count from the ADC?

The width of each "box" will be 5v / 1023 (or 5v / 1024 - take your pick)

So if the bottom point is 0v the next point will be 4.44876 millivolts. And the change-over point should be half of that. Give or take.

...R

What would happen if a series if statements was written to do the conversion from A to D.

If (0 <= Vin < 2.441) then output = 0
If (2.441 <= Vin < 7.323) then output = 1
...
If (4997.559 <= Vin < 5) then output =1023

There are 1024 possible values.

But does 5/1023 or 5/1024 result in the same list of values the if statements would need?

I am using thresholds of 5/1024 in the if statements, only because I have not refreshed my memory on the internals of ADCs to know what the actual (correct?) threshold is.

For someone with the right equipment and environment (I used to have access at a previous job but don't now or in my basement), should be able to ramp the microvolt input into the ADC and see when it changes over. Is it at 1/2 of 4.88768 or at 1/2 of 4.88281?

Robin2:
The width of each "box" will be 5v / 1023 (or 5v / 1024 - take your pick)

There is no "take your pick". By design the cutoff points for the buckets are Vref / (2^bits). That is just the way a successive approximation converter works.

Is there agreement that from 0 to (Vref / (2^bits)) / 2 the output is 0 and the output changes to a 1 at (Vref / (2^bits)) / 2 + 1uV? Or does the output change to 1 at Vref / (2^bits) + 1uV

adwsystems:
Is there agreement that from 0 to (Vref / (2^bits)) / 2 the output is 0

That is not how they work. That is also not what I wrote.

I know that is not what you wrote. That would be what I wrote in the question. I also noticed you have skirted answering three times.

How the cutoffs are defined...
http://forum.arduino.cc/index.php?topic=537413.msg3670319#msg3670319

How the cutoffs are applied...
http://forum.arduino.cc/index.php?topic=537413.msg3668726#msg3668726

So your answer is B: The output changes to 1 at Vref / (2^bits) + 1uV.

Which make my thresholds in post #68 (very) wrong.

adwsystems:
So your answer is B: The output changes to 1 at Vref / (2^bits) + 1uV.

Ugh. Neither post includes "1uV". The answer is no, the output does not change to 1 at Vref / (2^bits) + 1uV.

Cutoff = Vref / (2^bits)

For your example...

Vref = 5 volts
bits = 10

So...

Cutoff = 5 / (2^10) = 0.0048828125

Which means...

For input voltages less than 1 * 0.0048828125 volts, a successive approximation analog-to-digital converter returns a zero.

For input voltages greater than or equal to 1 * 0.0048828125 volts and less than 2 * 0.0048828125 volts the ADC returns a one.

For input voltages greater than or equal to 2 * 0.0048828125 volts and less than 3 * 0.0048828125 volts the ADC returns a two.

Etcetera.

It would have been less typing to just say: C-neither - Vref / (2^bits)

Which I did not derive from either of the posts that you recently linked.

If you wanted to expound, the ADC stays 0 until Vref / (2^bits) -1uV.

You are welcome.

Oh. Wait. You don't appear to be grateful. Never mind.

Sure, transistor tolerances just like all manufacturing tolerances and standardization are my personal definition, uhuh.

added:
This must be why there's a thread on denying the utility of dividing by 1023. Because of me. Everyone else knows better. This just gets funnier.

added:
Just because your calculator spits out a string of digits, reality only matches so many in a row.
The ADC step is almost 5mV wide with 5Vref, you can stop at 2 decimal places.

That seems to be a very helpful way of expressing it, and I believe it is correct.

However, in one sense it is a lot more crude than I had expected, and in another way it answers a doubt that was in my mind when I wrote Reply #67.

If you imagine a 2-bit ADC - which can return values 0, 1, 2,and 3 and if you imagine that Vref is 4v. Then the cutoff will be 4 / (2^2) = 1. Which means that the changeover points will be 1, 2, and 3. The reason I see that as crude is that anything up to 0.999v will be reported as 0. And the answer to my doubt is that, by not having the changeover points at the half-way points there is no need to figure out how the first and last half divisions need to be figured (for example 0.5 and 3.5 in the simple example).

Now, what does that tell us about the process that started this Thread - how to convert the ADC value back to the voltage from which it was derived.

If the simple ADC produces a value of (say) 3 we can convert it back to a voltage either with Vref / 2^n * ADC (the equivalent to using 1024) or Vref / (2^n) - 1 (equivalent to using 1023 - the number of intervals)
4 / 2^2 * 3 = 3 and 4 / (2^2) - 1 = 4
Which is the correct answer?

The ADC would have produced 3 for an input voltage between 3v and 3.999v and we cannot know any closer than that what actually happened. So, in a sense, neither answer is correct and a better answer would the average of them - 3.5v.

Which I think can reasonably be extrapolated to the real 10bit ADC by saying that either calculation will be close enough.

...R

It's not like anyone is being forced to only convert to volts one way... yet. But the holy warriors have been triggered.