arduino:divide-by-1023-or-1024
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
arduino:divide-by-1023-or-1024 [2025/06/20 13:14] – [So, why some people are in favor of 1023?] Ilias Iliopoulos | arduino:divide-by-1023-or-1024 [2025/06/21 11:56] (current) – [Finally, to get the voltage from the reading of analogRead(), do we divide by 1023 or 1024? What do AI engines have to say?] Ilias Iliopoulos | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Finally, to get the voltage | + | ===== Finally, to get the voltage |
While I was working lately on a project to build a joystick using salvaged parts from an old RC transmitter https:// | While I was working lately on a project to build a joystick using salvaged parts from an old RC transmitter https:// | ||
Line 7: | Line 7: | ||
Discussion forums hosted several opinions, some purely theoretical, | Discussion forums hosted several opinions, some purely theoretical, | ||
- | As expected, AI machines are trained by the information they find online. One was in favor of 1024, explaining that this is the correct value, because it is consistent to the theory of the operation of Analog to Digital Converters. It also considered 1024 as the value that provides the highest precision, making this approach more applicable to operations that require high accuracy. Yet, asking the machine why some people are in favor of 1023, it took an neutral position, stating that the results do not differ so much. | + | As expected, AI machines are trained by the information they find online. One was in favor of 1024, explaining that this is the correct value, because it is consistent to the theory of the operation of Analog to Digital Converters. It also considered 1024 as the value that provides the highest precision, making this approach more applicable to operations that require high accuracy. Yet, asking the machine why some people are in favor of 1023, it took an neutral position, stating that the results do not differ so much and that although 1024 is " |
- | Another AI engine was absolutely and without any doubt in favor of 1023. After I insisted that 1024 would be a better option, it explained that the difference is subtle and provided a more detailed explanation. | + | Another AI engine was absolutely and without any doubt in favor of 1023. After I insisted that 1024 would be a better option, it explained that the difference is subtle and provided a more detailed explanation. |
So, if our fellow colleagues of the future would like to be informed on our final verdict, would they consider that it is just a matter of personal opinion? At the time that scientists are arguing on quantum mechanics, how can we leave such a trivial issue without a clear and precise answer? | So, if our fellow colleagues of the future would like to be informed on our final verdict, would they consider that it is just a matter of personal opinion? At the time that scientists are arguing on quantum mechanics, how can we leave such a trivial issue without a clear and precise answer? | ||
Line 16: | Line 16: | ||
Several schools of thought crossed their swords: | Several schools of thought crossed their swords: | ||
- | * The purists: //" | + | * The purists: //" |
* The believers: //"The manual says `A*Vref/ | * The believers: //"The manual says `A*Vref/ | ||
* The practical thinkers: //"The difference is so small that we should not bother"// | * The practical thinkers: //"The difference is so small that we should not bother"// | ||
Line 82: | Line 82: | ||
==== Any comments on the various arguments in the online discussions? | ==== Any comments on the various arguments in the online discussions? | ||
- | It seems that arguments | + | Arguments |
- | Also, for the " | + | Yes, of course there are cases where we take decisions |
- | Induced errors should always be taken into account. | + | Induced errors should always be taken into account. |
==== Is it wrong to use 1023? ==== | ==== Is it wrong to use 1023? ==== | ||
- | It always depends on what exactly you want to do. If for example, your intention is to present your data to your user as a slider that goes from 0% to 100%, then it is a mapping problem and the proper value to use is 1023. But if you care about absolute values, why use 1023 when you know that the correct value is 1024? It is true that the difference between the results obtained using 1023 or 1024 is quite small. Actually, the practical thinkers would be happy to know that the value obtained using 1023 falls within the 1 LSB range between two successive ADC readings, so that actual difference is lower than the +-2 LSB absolute accuracy that the ADC provides. Yet, the small difference is not an excuse to knowingly do something wrong. | + | It always depends on what exactly you want to do. If for example, your intention is to present your data to your user as a slider that goes from 0% to 100%, then it is a mapping problem and the proper value to use is 1023 and not 1024. But if you care about absolute values, why use 1023 when you know that the correct value is 1024? It is true that the difference between the results obtained using 1023 or 1024 is quite small. Actually, the practical thinkers would be happy to know that the value obtained using 1023 falls within the 1 LSB range between two successive ADC readings, so that actual difference is lower than the +-2 LSB absolute accuracy that the ADC provides. |
In conclusion, you need to analyze your problem and most important, to define your acceptable margins of error. If your display presents a value that is not stable at the second decimal point, this does not mean that your ADC is crap. It is your responsibility to inform the users on what exactly they are observing. | In conclusion, you need to analyze your problem and most important, to define your acceptable margins of error. If your display presents a value that is not stable at the second decimal point, this does not mean that your ADC is crap. It is your responsibility to inform the users on what exactly they are observing. | ||
Line 96: | Line 96: | ||
Going back to the Arduino '' | Going back to the Arduino '' | ||
- | I would also like to point out that there are other mapping functions that you can use in your application, If you do not care about going to the extremes of 0% and 100% of the scale, you may consider the '' | + | I would also like to point out that there are other mapping functions that you can use in your application. If you do not care about going to the extremes of 0% and 100% of the scale, you may consider the '' |
==== So, is AI both right and wrong? ==== | ==== So, is AI both right and wrong? ==== | ||
Line 102: | Line 102: | ||
I believe that it has been proven beyond doubt at the discussion above, that you get correct answers only if you ask the right questions. | I believe that it has been proven beyond doubt at the discussion above, that you get correct answers only if you ask the right questions. | ||
- | > __"Go back to the description of the problem" | + | > __"If you cannot find the solution |
- | If you obtain a better understanding of the nature of the problem and even re-phrase it in a way that the new expression exposes the parameters that govern the problem, you will have many more chances to solve it. | + | If you obtain a better understanding of the nature of the problem and even re-phrase it in a way that the new expression exposes the parameters that govern |
Same with AI. I purposely did not present here the questions I submitted to the AI engines and their exact answers, since the phrasing of the question produced a totally different result. | Same with AI. I purposely did not present here the questions I submitted to the AI engines and their exact answers, since the phrasing of the question produced a totally different result. | ||
~~DISQUS~~ | ~~DISQUS~~ |
arduino/divide-by-1023-or-1024.1750414455.txt.gz · Last modified: 2025/06/20 13:14 by Ilias Iliopoulos