At 11:06 PM 4/7/03 +0600, David Strickland wrote: >I'm having a problem with the A/D convertor in the chip. It seems to >always return 0x13 no matter if the input voltage is 5V or 0V. >I've used interrupt driven and polling, both return the same result. >I'm reading the results from PORTB and PORTD with a multimeter (limited >parts availability in the lab, ie no leds). > >; Set TRISA for analog input. > bsf STATUS, RP0 ; switch to bank1 > movlw 0x3f ; Set bits 5-0 as 1 > movwf TRISA ; Sets PORTA<5:0> as inputs. >: > >; Set up the A/D convertor. > bcf STATUS, RP0 > bcf STATUS, RP1 ; Switch to bank0. > clrf ADCON0 ; Clear ADCON0. > ; Selects channel 0 (AN0) > ; Turns the A/D off. > ; Clears GO flag. > bsf ADCON0,ADCS1 ; Set ADSC1 and ADSC0 since we > ; are going to > bsf ADCON0,ADCS0 ; Use A/D's internal RC for its > ; clock source. > > bsf STATUS, RP0 > bcf STATUS, RP1 ; Switch to bank1. > clrf ADCON1 ; Clear ADCON1 > bsf ADCON1, ADFM ; Right justify 10 bits in > ; ADRESH and ADRESL > bsf ADCON1, PCFG1 ; ADCON1<3:0> = 0010 > ; Set AN7-AN5 as Digital. > ; Set AN4-AN0 as Analog inputs. > ; Use AVDD/AVSS (internal) as > ; reference voltages. You are still in Bank 1 here - wrong! >; Do a test A/D conversion. > bcf ADCON0, CHS0 ; Select Channel 0 (AN0). > bcf ADCON0, CHS1 ; > bcf ADCON0, CHS2 ; > bsf ADCON0, ADON ; Turn A/D on. > > > movlw d'31' ; 23 us/0.25 us = 92 total > ; clocks > ; since loop has 3 > ; instructions... 92/3 = 30.67 > ; -> 31 > ; 23 us is worst case, 10k ohm > ; impedance and 100 deg C. > ; 1/4MHz = 0.25 us > bcf STATUS, Z ; Make sure Zero flag is off. >addaq1 > addlw -1 ; W=W-1 > btfss STATUS, Z ; Is W = 0? > goto addaq1 ; NO, loop again. > > bsf ADCON0, GO ; Begin A/D conversion. >loop btfsc ADCON0, GO > goto loop > > bcf STATUS, RP0 > bcf STATUS, RP1 ; switch to bank0 to access > ; ADRESH. You had to be in Bank 0 to talk to ADCON0 > movf ADRESH, W > movwf adsaveh ; copy upper portion of A/D > ; result. > bsf STATUS, RP0 ; switch to bank1 to access > ; ADRESL. > movf ADRESL, W Opps - still in Bank 1 > movwf adsavel ; copy lower potion of A/D > ; result. > > bcf STATUS, RP0 > bcf STATUS, RP1 ; switch to bank0 to access > ; PORTB. > movf adsavel, W > movwf PORTB > movf adsaveh, W > movwf PORTD Bottom line: appears to be Banking issues. dwayne -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics