Hi Tenaja,here is my code for the A/D part of my project. I have tried it and find that accuracy is better the further away from 0V the input voltage is.
INCLUDE "modedefs.bas"
@ DEVICE pic16F88, INTRC_OSC_NOCLKOUT ' system clock options
SI VAR PORTB.1 ' Serial output pin
SO VAR PORTB.2 ' Serial Input pin
dig_num var word
x var word
num var word
remain var word
TRISA = %00000001 'bit 0 (AN/0) is input
TRISB = %10000010 'bit 7 (AN6) is input bit 1 is serial in
OSCCON = %01101000 '4MHz clock
ANSEL = %01000001 'AN0 and AN6 are analog
ADCON0 = %11110001 'channel 6 is selected
ADCON1 = %01000000 'Ref is Vdd and Vss
OPTION_REG.7=1 'dissable weak pull-ups on portB?
pause 2000 'let power supply settle
sens_in:
serout2 SO,813,["Hello",13,10] 'test serial connection
'see if all registers are set OK
serout2 SO,813,["ADCON0 = ",#ADCON0,13,10]
serout2 SO,813,["ADCON1 = ",#ADCON1,13,10]
serout2 SO,813,["ANSEL = ",#ANSEL,13,10]
serout2 SO,813,["OSCCON = ",#OSCCON,13,10]
serout2 SO,813,["OPTION_REG = ",#OPTION_REG,13,10]
serout2 SO,813,["Before A/D in",13,10]
'check digital value of A/D before conversion
serout2 SO,813,["Digital num = ",#dig_num,13,10]
pause 5000
ADCIN 6, dig_num 'use chanel 6 (RB7/AN6) as A/D input dig_num is digital result
while ADCON0.2=1:WEND ' Check to make sure ADC conversion finished..
pause 250
serout2 SO,813,["After A/D in",13,10] 'let meknow A/D is finished
x = dig_num*39
num = x/1000
remain = (x//1000)/100
serout2 SO,813,["dig_num = ",#dig_num,13,10]
serout2 SO,813,["x = ",#x,13,10]
serout2 SO,813,["Result = ",#num,".",#remain,13,10]
pause 5000
goto sens_in
end
An open input results in a 10V reading. I have looked thru the D/S again as you suggested, but cannot find any ref. to internal pull-ups other than setting OPTION_REG.7, though measurement indicates that they exist.
Sometimes though you see what you expect to and my reg. settings may well be wrong.
Thanks for the help
Steve
Bookmarks