madderscience
New Member
Hi all-
I'm relatively new to PIC processors, and like some previous posters I am building what is essentially a voltmeter (eventually to become part of a data acquisition system for my electric car).
However the problem I seem to be having doesn't match what is described anywhere else I can find on this forum, so I'll post this and let you guys tell me what presumably dumb thing I am doing.
My problem is that after finishing an ADC sample cycle, I cannot get ADRESL to read back anything other than Zero. However I am getting sane values from ADRESH. If I left justify the adc results, I get 8 bits of good data from ADRESH, but always zero from ADRESL. If I right justify the results, I get two bits of good data from ADRESH, but ADRESL still reads zero. Yes, I am using bank bits. I am transmitting my results off of the PIC via rs232 on an unused pin, so I can see what I am getting on a remote computer terminal.
Here are the (relevant) portions of my code: (comments may be truncated)
one-time-setup:
InitIO BANKSEL GPIO ; select bank containing GPIO (bank 0)
clrf GPIO ; clear contents of GPIO
clrf CMCON0 ; CMCON0 set GP0, GP1 to analog input, GP2 to I/O and
BANKSEL ANSEL ; select bank containing ANSEL register (bank 1)
movlw 0x33 ; set up ADC for dedicated clock and input on AN0
movwf ANSEL ; and write to ANSEL register.
movlw 0x03 ; set up tristate control buffer for input on GP0 and GP1
movwf TRISIO ; GP5,4,2 all outputs. GP3 is always a
BANKSEL GPIO ; go back to bank 0
return
sample routine, called periodically:
(ADCON0 is set to 0x0 before calling (Vdd reference, left justify, channel zero), the "Delay" routine sets up a variable duration watchdog timer wake-from-sleep based on the contents of W, and is known working)
Sample bsf ADCON0, 0 ; turn on adc.
movlw 0x0
call Delay ; wait 1/8s (way longer) than acquisition tim
bsf ADCON0, 1 ; GO!
btfsc ADCON0, 1 ; are we really done???
goto $-1
; store the result in program memory.
movfw ADRESH
movwf sampleH ; <<<< WORKS FINE, GETTING SANE DATA
BANKSEL ADRESL
movfw ADRESL
movwf sampleL ; <<<< ALWAYS ZERO!! GRRR!!!!!!
BANKSEL PIR1
bcf ADCON0, 0 ; turn off adc. isr should have done this, but
return ; and done,
I can do without the two least significant bits, but I'd like to have them if possible.
Thanks to all.
Brian
I'm relatively new to PIC processors, and like some previous posters I am building what is essentially a voltmeter (eventually to become part of a data acquisition system for my electric car).
However the problem I seem to be having doesn't match what is described anywhere else I can find on this forum, so I'll post this and let you guys tell me what presumably dumb thing I am doing.
My problem is that after finishing an ADC sample cycle, I cannot get ADRESL to read back anything other than Zero. However I am getting sane values from ADRESH. If I left justify the adc results, I get 8 bits of good data from ADRESH, but always zero from ADRESL. If I right justify the results, I get two bits of good data from ADRESH, but ADRESL still reads zero. Yes, I am using bank bits. I am transmitting my results off of the PIC via rs232 on an unused pin, so I can see what I am getting on a remote computer terminal.
Here are the (relevant) portions of my code: (comments may be truncated)
one-time-setup:
InitIO BANKSEL GPIO ; select bank containing GPIO (bank 0)
clrf GPIO ; clear contents of GPIO
clrf CMCON0 ; CMCON0 set GP0, GP1 to analog input, GP2 to I/O and
BANKSEL ANSEL ; select bank containing ANSEL register (bank 1)
movlw 0x33 ; set up ADC for dedicated clock and input on AN0
movwf ANSEL ; and write to ANSEL register.
movlw 0x03 ; set up tristate control buffer for input on GP0 and GP1
movwf TRISIO ; GP5,4,2 all outputs. GP3 is always a
BANKSEL GPIO ; go back to bank 0
return
sample routine, called periodically:
(ADCON0 is set to 0x0 before calling (Vdd reference, left justify, channel zero), the "Delay" routine sets up a variable duration watchdog timer wake-from-sleep based on the contents of W, and is known working)
Sample bsf ADCON0, 0 ; turn on adc.
movlw 0x0
call Delay ; wait 1/8s (way longer) than acquisition tim
bsf ADCON0, 1 ; GO!
btfsc ADCON0, 1 ; are we really done???
goto $-1
; store the result in program memory.
movfw ADRESH
movwf sampleH ; <<<< WORKS FINE, GETTING SANE DATA
BANKSEL ADRESL
movfw ADRESL
movwf sampleL ; <<<< ALWAYS ZERO!! GRRR!!!!!!
BANKSEL PIR1
bcf ADCON0, 0 ; turn off adc. isr should have done this, but
return ; and done,
I can do without the two least significant bits, but I'd like to have them if possible.
Thanks to all.
Brian