Got this AD routine working ok, but i have to select AN1 i/p when i am using AN0, and it wont select any other input on the AN0-12 channels.
I have a pot wired to AN0 (pin2) but i have to set the ADCON0 to select AN1,(00000001) otherwise it wont work,
yet if i put the pot onto AN1 (pin3) and select AN1 (00000001) or AN0 (00000000) it wont work? is it possible the pic is at fault?
I can get it to work on another pic (different model number) on all An0-10 no problem, never experienced this fault before!!!
Here is my set up if its any help, i have ordered a new pic in the meantime,
I have a pot wired to AN0 (pin2) but i have to set the ADCON0 to select AN1,(00000001) otherwise it wont work,
yet if i put the pot onto AN1 (pin3) and select AN1 (00000001) or AN0 (00000000) it wont work? is it possible the pic is at fault?
I can get it to work on another pic (different model number) on all An0-10 no problem, never experienced this fault before!!!
Here is my set up if its any help, i have ordered a new pic in the meantime,
Rich (BB code):
Main: setup ports
movlw b'01110111' ; osc ferequency 8mhz
movwf OSCCON
movlw b'00000001' ;set digital i/o portA
movwf ADCON1 ;set all to digital I/O
clrf PORTA
clrf LATA
movlw b'00001111' ; set porta,0,1 to input, rest outputs
movwf TRISA
MOVLW 07h
MOVWF CMCON ; comparators off
clrf PORTB
clrf LATB
clrf TRISB ; ALL B/C PORTS TO OUTPUTS .
clrf PORTC ; PORTA,0 INPUT. A1-7 OUTPUTS.
clrf LATC
clrf TRISC
;************************************
; speed routine
MOVLW b'00000001' ; AN0 source input =1(bit 0)
MOVWF ADCON0 ; set file configs
MOVLW b'00001100' ; set up vref internal, ( Vref bits 4,5,) AN0-AN2 i/ps
MOVWF ADCON1 ; set up reg
MOVLW B'00101011' ; SET CLOCK FREQ FRC, TAD 12bits,LEFT justified bit7=0,
MOVWF ADCON2 ; do it
Call Delay ; wait 50ms
BSF ADCON0,GO ;Start conversion
wait
BTFSC ADCON0,GO ;Is conversion done?
GOTO wait ;No, test again
MOVFF ADRESH,RESULTHI ; store upper 2 bits in resulthi
MOVFF ADRESL,RESULTLO ; store lower 8 bits in resultlo
return
Last edited: