Thanks everybody. Got the bug. ADRESL is in Bank1, whereas the temporary register (TempA_Lo) was in Bank0. So the zeroes in TempA_Lo. -----Original Message----- From: pic microcontroller discussion list Sent: Tuesday, October 07, 2003 7:46 PM To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: ADC trouble Hello, In the ADC I'm doing using a PIC16F870, the ADRESL register does not 'work' properly. When I left justify the results, the ADRESH gives me a proper reading, but there is 0x00 in ADRESL (so 8 bit ADC). Now, when I right justify the results, the ADRESL has again all zeroes, while the ADRESH gives a reading (so now 2 bit ADC). The BANKs, ADCON0, ADCON1 are set properly (because there IS an AD conversion always, 8 bit / 2 bit). I've used 3 or 4 different PICs (all 16F870s), but they have the same problem. I've also changed Fosc/32 to Fosc/8, but still same. The ADC code is inline below. Searching archives has not been fruitful. This may sound far-fetched, but is it just possible that the PICs are defective? Please advise. Thanks, Mohit. ;=CODE=========================================== ; PIC16F870 @ 20 MHz ;Initialisation for ADC BANKSEL ADCON1 movlw b'00001110' ; Left justified (ADRESL=xx000000), AN0=Analog, Rest Digital. movwf ADCON1 movlw B'00001111' ; Initialise PortA movwf TRISA ; -do- BANKSEL PORTA ADsample BANKSEL ADCON1 clrf ADRESL ; movlw b'10001110' ; Right justified (ADRESH=000000xx), AN0=Analog. Gives 8 bit ADC. movlw b'00001110' ; Left justified (ADRESL=xx000000), AN0=Analog. Gives 2 bit ADC. movwf ADCON1 BANKSEL ADCON0 clrf ADRESH movlw b'10000000' ; Fosc/32 clock, Ch0 (PortA,0), AD module is off movwf ADCON0 movlw 1 ; Wait a bit (1 msec), call wait_n_msec ; -do-. bsf ADCON0,ADON ; Turn ON AD module. call wait_1_msec ; Acquisition wait, >20 us. We wait 1 msec. bsf ADCON0,GO_DONE ; Start A/D conversion. AD_Conv_Wait btfsc ADCON0,GO_DONE ; Wait for conversion to finish. goto AD_Conv_Wait BANKSEL ADRESL ; Store results in the alloted registers for later use movfw ADRESL movwf TempA_Lo BANKSEL ADRESH movfw ADRESH movwf TempA_Hi return ;============================================= -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body