-
adcin issues with 16f676
For some reason I can't seem to get this working, have played around for a couple of hours now and still no joy - I know it'll be in my setup somewhere - just cant find that vital point.
Many thanks in advance for any input (I only know half of what I'm doing when I set up these registers)
@ DEVICE PIC16F676, XT_OSC, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF
Define OSCCAL_1K 1
DEFINE OSC 4
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 50
TRISA = %000000
TRISC = %101100
ADCON0 = %10000001
ADCON1 = %00010000
ANSEL = %10000000 'enable ch7 analog
VRCON = %10000000 ' A/D Voltage reference
CMCON = 7 'Disable comparitor
red var PortA.2
green var PortC.0
PDWN var PortC.1
DAT var PortC.2
pwr var PortC.4
Switch var PortC.5
batt var byte
timeset var byte
display var byte
timer var word
b0 var byte
b1 var bit
b2 var byte
b3 var word
clear
timeset = 1
PortA = 0
PortC = 0
Begin: 'start sequence
adcin 7,batt
red = 1 'turn red led on
if batt > 10 then green = 1 'turn green led on
if batt > 50 then red = 0 'turn red off
pause 500
goto begin
-
This reply is how I read the ADC in a 16F876A. I guess the registers and the reading would be the same in the 16F676, but I haven't read the datasheet and can't vouch for it.
Code:
Scanspeed var word ' this is where we read the ADC value
ADCON0.2 = 1 ' Start conversion
while ADCON0.2 ' wait till conversion is done
wend
ScanSpeed.HighByte = ADRESH
ScanSpeed.LowByte = ADRESL
Also, you need to heed this warning (from the PBP manual)
Code:
Before ADCIN can be used, the appropriate TRIS register must be set to
make the desired pins inputs. ADCON1 also needs to be set to assign
the desired pins to analog inputs and in some cases to set the result
format and clock source.
Hope this helps
Jerson
-
Hey thanks for that - but i ended up deleting my adcon and vrcon registers and let pbp do it for me and it all worked yay