Voltage Dividers Made Easy !
The maths is made easier if we select exact ratio's,we can use just two common available resistors.
The schematic shows some examples using an AXE132 with a regulator circuit
with transient protection usually good for about 200ma enough for an lcd or other display.
Just enter the correct Vin fullscale in our code ,if the regulator isint quite 5v we can tweak that a bit too.
The maths is made easier if we select exact ratio's,we can use just two common available resistors.
The schematic shows some examples using an AXE132 with a regulator circuit
with transient protection usually good for about 200ma enough for an lcd or other display.
Just enter the correct Vin fullscale in our code ,if the regulator isint quite 5v we can tweak that a bit too.
Code:
#picaxe 18M2
#terminal 19200
SETFREQ M16
SYMBOL ADCvalue = W3
SYMBOL Volts = W4
Main:
ReadADC10 C.0,ADCvalue
ReadADC10 C.0,Volts
IF ADCvalue = Volts THEN ConvertV ' display equal ADCvalues
GOTO main
ConvertV:
Volts = Volts **64064 ' Convert 1023 to 1000 steps (**64064) for 5.00v reference
'Volts = Volts **64333 ' tweaked a little 7805 output actually 5.021v /5.00 *64064
Volts = Volts *16 ' Multiply by Vin (Fullscale 16v)(R1 22K)(R2 10K)
Displaytest:
Sertxd (13,10,"ADCvalue ",#ADCvalue," ",#Volts," Volts ")' 016 resolution
DisplayV:
'Volts = Volts /100
'BinTOASCII Volts, b3,b2,b1 : IF b3 = "0" THEN : b3 = " " : ENDIF' leading zero blanking
'Sertxd (13,10," ",b3,b2,".",b1," Volts") ' 0.1 resolution
PAUSE 1000
GOTO main
Attachments
-
300.1 KB Views: 316
Last edited: