Go Down

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

#### TolpuddleSartre

#30
##### Mar 28, 2018, 09:15 pm
I'll just leave this here.
(Drops mic)

#### GoForSmoke

#31
##### Mar 28, 2018, 09:46 pm
If you can't answer points, imply everything comes down to a single issue.

With a 1.024V ref I can work the 10 bits of the ADC ladder value as factors of 1 mV, knowing instrument error from specs.
Please understand that doing so does not involve conversion to volts and treats the ADC value as a range.

If you fixate on hardware details you may lose signt of the what you're doing with them part. Or you're a EE.
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

#### Robin2

#32
##### Mar 28, 2018, 10:35 pm
Do you mean?
Look back at the 0-5 example in Reply #21

Quote
At least work to the ADC value where possible, it's the conversion of ranges to values that forces errors.
I agree 100%. I am just pursuing this Thread for intellectual fun.

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

#### GoForSmoke

#33
##### Mar 28, 2018, 10:55 pm
The fun part is that with a 1.024V Vref, just going by 1mV x ADC the most you get is 1.023mV.

AVR has a built-in 1.1V Vref for 1.074mV steps x highest possible read 1023 = 1.099V.

If that 1.1V could be voltage divided to a 1.023Vref (perfect world), that would be conversion-friendly IF you're into converting.
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

#### Budvar10

#34
##### Mar 29, 2018, 10:20 am

Let say we have just 1 bit ADC, 0 or 5V. Just two possible values. Should be /0 used?

And here is for n=5:
Code: [Select]
`First *x/(n-1) math:                                                              input voltage   ADC value   ADC*x/(n-1)   result   average error   output4.00-4.99       4           *5/4          5.00     +0.50           5          3.00-3.99       3           *5/4          3.75     +0.25           32.00-2.99       2           *5/4          2.50      0.00           21.00-1.99       1           *5/4          1.25     -0.25           10.00-0.99       0           *5/4          0.00     -0.50           0Note that for the 5 possible ADC values, the output scale now has 6 values (0-5)and the value 4 can never occur! And although the average error might look to benicely distributed +/- the centre of scale, the actual output result proves to bemuch uglier. For slowly increasing voltage, the ADC would read; 0, 1, 2, 3, 5!!!The maximum error in real world use is 2V, because that very tiny change of3.999V - 4.001V would cause an output change of 3V -> 5V or a change of 2V!Correct scaling math *x/n: input voltage   ADC value   ADC*x/n       result   average error   output   4.00-4.99       4           *5/5          4.00     -0.50           4           3.00-3.99       3           *5/5          3.00     -0.50           3           2.00-2.99       2           *5/5          2.00     -0.50           2           1.00-1.99       1           *5/5          1.00     -0.50           1           0.00-0.99       0           *5/5          0.00     -0.50           0                                                                                            #All output values are properly scaled and all are represented. The average erroris never greater than 0.5 (no more average error than the /(n-1) example),      the average error is always one fixed value (-0.5) making it very easyto compensate. The maximum error at any time is 1V, this is half the max error ofthe /(n-1) example, which can introduce extra error up to 1 in high value ADCreadings`
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

#### Robin2

#35
##### Mar 29, 2018, 10:41 amLast Edit: Mar 29, 2018, 10:43 am by Robin2

I think the assumption that 4.00 to 4.99 gives 4 and 3.00 to 3.99 gives 3 is incorrect. I would expect 4.5 to 4.99 to give 5 and 3.5 to 4.49 to give 4

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

#### TolpuddleSartre

#36
##### Mar 29, 2018, 10:49 amLast Edit: Mar 29, 2018, 04:49 pm by TolpuddleSartre
Oh, the humanity!

Quote
Let say we have just 1 bit ADC, 0 or 5V. Just two possible values. Should be /0 used?
No, because 21 is 2, so by GoForSmoke's logic, we would divide by 1.

#### Robin2

#37
##### Mar 29, 2018, 10:55 am
Maybe it is time to move it to Bar Sport ?

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

#### lastchancename

#38
##### Mar 29, 2018, 01:33 pm
...and this thread explains why binary logic wins!
We don't need no stinkin' analog!

Zero or One - none of this warm, fuzzy stuff. It just confuses things.

Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

#### GolamMostafa

#39
##### Mar 29, 2018, 05:40 pmLast Edit: Mar 29, 2018, 05:42 pm by GolamMostafa
Quote
Maybe it is time to move it to Bar Sport ?
It's very interesting that the OP has not yet made any comment; but, you want move to the Bar Sport leaving him behind?

#### lastchancename

#40
##### Mar 29, 2018, 05:45 pm
Bar Sport is Probably better than TUTORIALS.
Maybe Programming Questions?
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

#### Robin2

#41
##### Mar 29, 2018, 06:16 pm
It's very interesting that the OP has not yet made any comment; but, you want move to the Bar Sport leaving him behind?
No. He must come with us.

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

#### GoForSmoke

#42
##### Mar 29, 2018, 07:44 pmLast Edit: Mar 29, 2018, 09:12 pm by GoForSmoke

Let say we have just 1 bit ADC, 0 or 5V. Just two possible values. Should be /0 used?

And here is for n=5:
Code: [Select]
`First *x/(n-1) math:                                                              input voltage   ADC value   ADC*x/(n-1)   result   average error   output4.00-4.99       4           *5/4          5.00     +0.50           5          3.00-3.99       3           *5/4          3.75     +0.25           32.00-2.99       2           *5/4          2.50      0.00           21.00-1.99       1           *5/4          1.25     -0.25           10.00-0.99       0           *5/4          0.00     -0.50           0Note that for the 5 possible ADC values, the output scale now has 6 values (0-5)and the value 4 can never occur! And although the average error might look to benicely distributed +/- the centre of scale, the actual output result proves to bemuch uglier. For slowly increasing voltage, the ADC would read; 0, 1, 2, 3, 5!!!The maximum error in real world use is 2V, because that very tiny change of3.999V - 4.001V would cause an output change of 3V -> 5V or a change of 2V!Correct scaling math *x/n: input voltage   ADC value   ADC*x/n       result   average error   output   4.00-4.99       4           *5/5          4.00     -0.50           4           3.00-3.99       3           *5/5          3.00     -0.50           3           2.00-2.99       2           *5/5          2.00     -0.50           2           1.00-1.99       1           *5/5          1.00     -0.50           1           0.00-0.99       0           *5/5          0.00     -0.50           0                                                                                            #All output values are properly scaled and all are represented. The average erroris never greater than 0.5 (no more average error than the /(n-1) example),      the average error is always one fixed value (-0.5) making it very easyto compensate. The maximum error at any time is 1V, this is half the max error ofthe /(n-1) example, which can introduce extra error up to 1 in high value ADCreadings`

Oh, the humanity!
No, because 21 is 2, so by GoForSmoke's logic, we would divide by 1.
These are rather poor strawmen.

TS, how do YOU convert a single bit into voltage with any more accuracy than what you think to ridicule?
Oh? What? You can't?

Bud, if you measure only 5 steps, the CONVERSION error is no longer 3 orders of magnitude below instrument error.
The error diminishes at n(n-1) rate. I argue on practicalities that do not scale freely. Please at least stay in the ballpark!

I gave clear reasons that you don't address at all and instead erect these pre-broken strawmen.
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

#### TolpuddleSartre

#43

#44
##### Mar 29, 2018, 07:51 pmLast Edit: Mar 29, 2018, 07:52 pm by Coding Badly
Let say we have just 1 bit ADC, 0 or 5V.
That is not how the AVR analog-to-digital converter works.  A one bit successive approximation converter with a reference of 5 volts makes just a single comparison: Is the voltage less than 2.5 volts?  If the answer is "yes" then the converted value is zero.  If the answer is "no" then the converted value is one.

Go Up