PIC16f1829 ADC question...
I am not fully understanding the setup for the ADC, and therefor, I am missing something. With the following code I get my readout on the LCD, but I get 0 99.9% of the pot travel, and 255 @ POT WOT. Anyone see my problem?
Code:
#CONFIG
__config _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF
#ENDCONFIG
DEFINE OSC 20
Define ADC_BITS 8
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 50
Define LCD_DREG PORTC
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTC
Define LCD_EBIT 6
TRISA = %11111111
ADCON1 = %00000100
adval1 var word
adval2 var word
ADCON0 = 0
ANSELA = 1
ANSELB = 0
ANSELC = 0
adval1 = 0
Temp:
adcin 0, adval1
Lcdout $fe, 1
Lcdout "Value: ", DEC adval1 ' Display the decimal value
Pause 100
goto temp
Re: PIC16f1829 ADC question...
I think you have the adc turned off.
Try adcon0 = %00000001 or adcon0.0 = 1
Re: PIC16f1829 ADC question...
ADCON1 = %00000100 will set adc reference to external , is that what you want ? have you provided an ext reference ?
I assume you have the pot connected to an0 of course
Re: PIC16f1829 ADC question...
Thanks for the input! Yea it was the VREF- set external... I was reading the bits left to right... in other words, I had my head solidly in brown town....