Go Down

### Topic: Dividing by 1023 or 1024? The final verdict on analogRead (Read 12423 times)previous topic - next topic

#### Robin2

#60
##### Mar 30, 2018, 03:48 pm
Turning a range of values into a single value leaves correct behind. Say hello to best fit.
I only intended the word "correct" in the context of whether 1023 or 1024 is mathematically correct for the purpose of converting an ADC reading to the voltage it represents.

I am well aware that the theoretical mathematically derived value is not a precise representation of the actual voltage value that gave rise to the number produced by the ADC. Most of the time it is sufficient to use the ADC value without any conversion.

For the real world, none of the discussion in this Thread matters.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### GolamMostafa

#61
##### Mar 30, 2018, 04:00 pmLast Edit: Mar 30, 2018, 05:30 pm by GolamMostafa
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?

#### Robin2

#62
##### Mar 30, 2018, 05:44 pm
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
Two or three hours spent thinking and reading documentation solves most programming problems.

#63
##### Mar 30, 2018, 07:17 pm
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.

#64
##### Mar 30, 2018, 07:24 pmLast Edit: Mar 30, 2018, 07:25 pm by adwsystems
If the ADC outputs 0 counts for 0V, at what voltage does it output 1 count? (given Vref=5V and a 10 bit ADC)

#65
##### Mar 30, 2018, 07:41 pm
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.

Quote
...at what voltage does it output 1 count?
Over what range does the ADC output 1?  Is that what you meant to ask?

#66
##### Mar 30, 2018, 07:50 pmLast Edit: Mar 30, 2018, 07:50 pm by adwsystems
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.

#### Robin2

#67
##### Mar 30, 2018, 07:59 pm
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
Two or three hours spent thinking and reading documentation solves most programming problems.

#68
##### Mar 30, 2018, 08:16 pmLast Edit: Mar 30, 2018, 08:33 pm by adwsystems
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?

#69
##### Mar 30, 2018, 08:37 pm
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.

#70
##### Mar 30, 2018, 08:44 pm
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

#71
##### Mar 30, 2018, 08:49 pm
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.

#72
##### Mar 30, 2018, 08:54 pmLast Edit: Mar 30, 2018, 08:55 pm by adwsystems
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.