User Tools

Site Tools


arduino:divide-by-1023-or-1024

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
arduino:divide-by-1023-or-1024 [2025/06/20 13:16] – [Is it wrong to use 1023?] Ilias Iliopoulosarduino: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 producing an ADC value, do we divide by 1023 or 1024? What do AI engines have to say? =====+===== Finally, to get the voltage from the reading of analogRead(), do we divide by 1023 or 1024? What do AI engines have to say? =====
  
 While I was working lately on a project to build a joystick using salvaged parts from an old RC transmitter https://github.com/fryktoria/arduino_Gaming_Controller which is utilizing the Analog to Digital Converter (ADC) of an Arduino, I once again stumbled upon the age old question:  While I was working lately on a project to build a joystick using salvaged parts from an old RC transmitter https://github.com/fryktoria/arduino_Gaming_Controller which is utilizing the Analog to Digital Converter (ADC) of an Arduino, I once again stumbled upon the age old question: 
Line 7: Line 7:
 Discussion forums hosted several opinions, some purely theoretical, others practical and of course some totally misleading. During the past years, I have not encountered any forum that provided a conclusive response on this question. So, I wanted to check what our Artificial Intelligence friends have to say about that. Discussion forums hosted several opinions, some purely theoretical, others practical and of course some totally misleading. During the past years, I have not encountered any forum that provided a conclusive response on this question. So, I wanted to check what our Artificial Intelligence friends have to say about that.
  
-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 "dictated" by some obscure mathematical theory, 1023 provides more "practical" results, whatever that means.
  
-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. Unfortunately, to understand this subtlenessyou would have to know the correct answer beforehand.+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. This same engine is so indoctrinated with 1023that even after I asked it to summarize this very same articleit still insisted that this article considers 1023 as correct!!! 
  
 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: //"According to ADC theory, the answer is `A*Vref/1024`, and there is no other discussion about it, even if the results are different than we expected"//+  * The purists: //"According to ADC theory, the answer is `A*Vref/1024`, because it is dictated by math"//
   * The believers: //"The manual says `A*Vref/1024`, so there is no need to discuss it further"//   * The believers: //"The manual says `A*Vref/1024`, so there is no need to discuss it further"//
   * 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 regarding comparison of accuracy between the two methods are meaningless, when you try to compare different things. Of course there are issues to discuss about precision and resolutionbut it is pointless for this comparison.+Arguments regarding comparison of accuracy between the two methods are meaningless, when you try to compare different things. Would it be logical to say that 1 Kg is 999 grams, because the difference is very small? Or, would it be logical to say that we make a personal choice to select 1000 grams because it provides more accurate results to the calculations compared to 999 grams? Absolutely not. **This is not a matter of personal opinion**. It is a waste of brain power to discuss about accuracy and precisionwhen the approach is faulty by inception  
  
-Alsofor the "practicality" of some decisionswe should understand the controlling mechanisms, regardless if it is a device or a business process. It is not correct to make an non-educated judgement, because it would not be possible to predict how the system will behave in various unforeseen circumstances.+Yes, of course there are cases where we take decisions to exclude parameters that have a small incluence on our calculations. You will not be crazy to include the Special Theory of Relativity when you design a tachometer for your kid's bicycle. We only take shortcuts when we understand the controlling mechanisms, regardless if it is a device or a business process. The whole point of the simplification is to make things easier to implement, having defined the acceptable error that this simplification will cause.
  
-Induced errors should always be taken into account.  I am certain that most people complaining about getting "bad" readings from an ADC are experiencing problems with unstable power supplies, missing accurate voltage references, bad decoupling, crosstalk, stray inductance and capacitance, as well as several other causes of error lurking in the implementation of an electronic circuit. The ATMega328 manual itself provides several information on how to disable internal MCU functions in order to minimize the noise that would alter the readings of the ADC. Also, there is currently a lot of both scientific and practical/experimental documentation on the design of the cabling and PCB traces. Building a circuit that faces the hardness of the real world goes way beyond writing some lines of code.+Induced errors should always be taken into account.  I am certain that most people complaining about getting "bad" readings from an ADC, which I mentioned as "haters" above, are experiencing problems with unstable power supplies, missing accurate voltage references, bad decoupling, crosstalk, stray inductance and capacitance, as well as several other causes of error lurking in the implementation of an electronic circuit. The ATMega328 manual itself provides several information on how to disable internal MCU functions in order to minimize the noise that would alter the readings of the ADC. Also, there is currently online a lot of both scientific and practical/experimental documentation on the design of the cabling and PCB traces. Building a circuit that faces the hardness of the real world goes way beyond writing some lines of code and consider that the circuit will behave exactly as a well-mannered and predictable software.
  
 ====  Is it wrong to use 1023? ====  ====  Is it wrong to use 1023? ==== 
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.  Whenever I face an unsolvable problem, I remember what my teachers have been telling me: 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.  Whenever I face an unsolvable problem, I remember what my teachers have been telling me:
  
-> __"Go back to the description of the problem"__ +> __"If you cannot find the solution to a problem, read again the description of the problem"__ 
  
-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 the dynamics of the problem, you will have many more chances to solve it.
  
 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.  It seems that AI behaves exactly as the discussion forums they have been trained with. It is a great tool. Let us train it by providing correct data. 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.  It seems that AI behaves exactly as the discussion forums they have been trained with. It is a great tool. Let us train it by providing correct data.
  
 ~~DISQUS~~ ~~DISQUS~~
arduino/divide-by-1023-or-1024.1750414612.txt.gz · Last modified: 2025/06/20 13:16 by Ilias Iliopoulos

Except where otherwise noted, content on this wiki is licensed under the following license: Private License