• Home
  • Prakash
    • R and D
    • Smart Home
  • Basics
    • Capacitors
      • Color codeing Disc Capacitor Capacitor characterstics Polarity Non Polarity Series Connection Parallel Connection
    • Diodes
      • Zener Diode Light Emitting Diode Signal Diode Photo Diode
    • Inductors
    • Transistor
      • Silicon Germenium NPN PNP MOSFET SCR
    • Resistors
      • Color codeing 4-Band 5-Band Series Parallel Potential Meter
    • Logics
      • Analog Logic
      • Digital Logic
      • Hexa Decimal Numbers
      • Octal Numbers
      • Binary Fraction
      • Binay to Decimal
    • OP-Amplifiers
      • Basics
      • Oscillators
      • Transistor Switch
      • 555 IC circuits
      • Waveform Generators
      • 741 IC Circuits
    • Power supply
      • Transformer
      • Halfwave Rectifier
      • Fullwave Rectifier
      • Bridge Rectifier
      • 78xx Series
      • 0 to 30v Regulator
  • Modules
    • H-Bridge
      • L293D Bridge
      • Relay Bridge
    • RF 434MHz Modules
    • Relay Modules
    • Push to ON switch
    • Push to OFF switch
  • Sensors
    • Analog sensors List-1
      • LDR Photo Diode Solar Cell Transducers Temperature Humidity Sensor Soil Moisture Ranger Sensor Range Detection
    • Analog sensors List-2
      • Flame Sensor Force Sensor Flex Sensor Ambient Sensor Motion Sensor Vibration Sensor Sound Sensor UltraSonic Sensor GrayScale Sensor
    • Digital Sensors
      • Touch Sensor Tilt Sensor Signal
    • 3-Axis Sensor
    • Gyro Sensor
  • Projects
    • Embedded
      • Mini Projects 8051 Arduino NodeMCU MSP430 Raspberry IOT ARM
    • C #
      • Visual Basic Visual Studio
    • Matlab
    • VLSI
    • PHP-HTML
    • Contribute
  • Downloads
  • Technology

Refer ADC

Why ADC/1024 is correct, and ADC/1023 is just plain wrong!

It's common to need to scale a microcontroller ADC result to give a value in some other scale. One example is to scale the ADC to read in actual volts like read from 0.00v -> 5.00v.

People sometimes use ADC *500 /1023 as this gives a reading of 500 (5.00v) for the top ADC value of 1023.

Doing that math; *x/(n-1) or *x/1023 does perform a kind of rounding function, but it "fudges" the rounding and gives both scaling and rounding errors.

The correct scaling math; *x/n or *x/1024 correctly scales all the output data in size, but gives an average rounding error of 0.5 ADC counts (always rounding down).

To magnify and show the errors caused by *x/(n-1) this table shows a simple ADC that has 5 values. (This is just like a PIC ADC but has 5 possible ADC values, not 1024).


        Code ( (Unknown Language)):
  1. [b]First the incorrect *x/(n-1) math;[/b]
  2. input       ADC math        result  average     output
  3. voltage     value   ADC*x/(n-1)     error       result
  4. 4.00-4.99   4   *5 /4       5.00    +0.50       5
  5. 3.00-3.99   3   *5 /4       3.75    +0.25       3
  6. 2.00-2.99   2   *5 /4       2.50     0.00       2
  7. 1.00-1.99   1   *5 /4       1.25    -0.25       1
  8. 0.00-0.99   0   *5 /4       0.00    -0.50       0


Note 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 be nicely distributed +/- the centre of scale, the actual output result proves to be much uglier. 

So if you had a 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 of 3.999v - 4.001v would cause an output change of 3v -> 5v or a change of 2v!

Code ( (Unknown Language)):
  1. [b]Here is the correct scaling math *x/n;[/b]
  2. input       ADC math        result  average     output
  3. voltage     value   ADC*x/n         error       result
  4. 4.00-4.99   4   *5 /5       4.00    -0.50       4
  5. 3.00-3.99   3   *5 /5       3.00    -0.50       3
  6. 2.00-2.99   2   *5 /5       2.00    -0.50       2
  7. 1.00-1.99   1   *5 /5       1.00    -0.50       1
  8. 0.00-0.99   0   *5 /5       0.00    -0.50       0
All output values are properly scaled and all are represented. The average error is never greater than 0.5 (no more average error than the /(n-1) example), and the average error is always one fixed value (-0.5) making it very easy to compensate (see below).

The maximum error at any time is 1v, this is half the max error of the /(n-1) example, which can introduce extra error up to 1 in high value ADC readings.

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Terms and Conditions -
Privacy Policy -

Contact Us

Name

Email *

Message *