For good results using A/D Converters make sure you always include BY-PASS Capacitors,
without them power supply noise may well eliminate any chance of precision. Ideally they
should be found at the power supply and all devices you have populated your board with .
The smaller capacitors closest to the device pins and lead length kept as short as possible.
on the 18M2 Board I am using it has a 47uF Tantalum nearby with a 0.1uF at the picaxe
supply pins. I also have an 0.01uF capacitor which Microchip sometimes recommends
with the lowest values closest to the device.
without them power supply noise may well eliminate any chance of precision. Ideally they
should be found at the power supply and all devices you have populated your board with .
The smaller capacitors closest to the device pins and lead length kept as short as possible.
on the 18M2 Board I am using it has a 47uF Tantalum nearby with a 0.1uF at the picaxe
supply pins. I also have an 0.01uF capacitor which Microchip sometimes recommends
with the lowest values closest to the device.
Code:
#picaxe 18m2 ' AXE132 8Bit marks
#no_data
#terminal 19200
SETFREQ M16
dirsB = %11111111
dirsC = %11001111
' DB7 = B.7
' DB6 = B.6
' DB5 = B.5
' DB4 = B.4
' DB3 = B.3
' DB2 = B.2
' DB1 = B.1
' DB0 = B.0
SYMBOL E = C.6
SYMBOL RS = C.7
SYMBOL senddata = pinsb
SYMBOL index = b0 : SYMBOL avr = b0
SYMBOL CALIB_ADC10 = W1
SYMBOL Supply = W2 : SYMBOL Value = W2
SYMBOL D0 = b7
SYMBOL D1 = b8
SYMBOL D2 = b9
InitialiseLCD:
FOR index = 0 to 6
LOOKUP index, ($38,$38,$38,$0C,$01,$02,$06),senddata : PULSOUT E,1 ' Initialise LCD/OLED
'(8bit/2line/5x8)*3(Display On)(Clear Display)(Return Home)(Entry Mode Set)
NEXT index : PAUSE 10
Main: ' Steps x Vref / Vsup = CALIBABC10
CALIB_ADC10 = 0 ' 1023 x 1.024v /5.000 = (209)
FOR avr = 1 TO 5 ' 1023 x 1.024v /4.096 = (255)
CALIBADC10 Value : CALIB_ADC10 = CALIB_ADC10 +Value ' 1023 x 1.024v /3.300 = (317)
NEXT avr ' 1023 x 1.024v /2.048 = (511)
CALIB_ADC10 = CALIB_ADC10 /5 ' just averages 5 readings which probably is not required
Supply = 20951 / CALIB_ADC10 *5 ' 1023 steps x 1024 mV = 1047552 / 50 = 20951
Sertxd("ADC10 = ",#CALIB_ADC10)
BinToAscii Supply ,D2,D1,D0 : Sertxd(" LCD Supply ",D2,".",D1,D0," V",cr,lf) ' 5.05 V resolution 05
DisplaySupplyLCD:
LOW RS :senddata = 128 : PULSOUT E,1
HIGH RS
FOR index = 0 TO 15
LOOKUP index,("LCD Supply ",D2,".",D1,D0,"V"),senddata
pinsB = senddata : PULSOUT E,1 ' sending characters to line one
NEXT index
Pause 2000
GOTO Main