You're not reading 20v directly on the ADC input are you? 0 - Vcc on the pin (Vcc max is 5 volts). A simple voltage divider, A 10k resistor between the 20v and the ADC input then a 3.3k to ground will do the trick.. At 20v you'll have about 4.92v on the pin, digitally this should be around 1000 bits
Take two readings, add together and hey presto 2000 bits artificially stick in the decimal place and you have 20.00 volts
I'm only using 8-bit on the ADC. I read voltage, but my voltmeter does not red the same as my LCD. What formula should I ue to calculate the display voltage?
I'm only using 8-bit on the ADC. I read voltage, but my voltmeter does not red the same as my LCD. What formula should I ue to calculate the display voltage?
Neglecting the required voltage divider for a moment, the decimal value of the ADC reading will be integer(Vin*256/Vdd).
Suppose Vin = 3.000V and Vref=Vdd=5.100V, the ADC value returned will be integer((3.000*256/5.100) = int(150.588) = 150 = 0x96.
Suppose your ADC reading is 240 (0xF0). The input voltage corresponding to that would be (ADC*Vref)/256 = 240*5.100/256 = 4.78V
Note that you have to know what the ADC reference voltage is. If it changes, so will the ADC reading. Also note that in the 8 bit mode, the ADC can resolve a minimum change of Vref/256 ≈ 20mV.
The ADC input cannot go any higher than Vref (Vdd); that is why you must use a voltage divider.
You are (without knowing it) using fixed point arithmetic. Your advalue will contain 0 to 200 you are printing 20.0 therefore 200/10 = "20" and 200 modulus 10 yields the decimal place" .0".
Example advalue = 136 so: 136 / 10 = "13" and then the point "." and then the decimal 136 % 10 = "6"
Most people end up using fixed point arithmetic, as floating point does tend to use a lot of resources and processing power.
Cheers Ian
You need to display up to 20 volts right! ADRESH contains 0 to 255 so 20v on ADC input after the divider should be approx 5v or 255 bits Your original equation ((ADRESH * 5) / 256)
would yield just 5, you need 20 if you take ADRESH and multiply by 50 then / 255 this would yield 50 BUT as you need 200 and 50 is a 1/4 0f 200!!! 64 is a quarter of 255.. So I used 50 (to get 1 decimal place) and 64 (which is a quarter of 255) so the result would be (256 / 64) ie.. 4 x 50 = 200..
Is this too long winded?
Cheers Ian
Oh! and by the way I have a maths degree and sometimes go over board.