nickagian
Member level 4
- Joined
- Mar 19, 2009
- Messages
- 71
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,288
- Location
- Zurich, Switzerland
- Activity points
- 2,001
Hi there! I'm using the PIC16F819 MCU for some home projects. I'm still in my first steps and the ADC keeps confusing me.
The problem is that after doing the conversions, the ADRESL register is always read as h'FF' no matter what input there is at the analog channel I'm using. I have checked -among others- to connect the input to the ground but the result remains the same, the ADRESL is always h'FF'
Does anyone have any idea of what's wrong?
I thought that it may be a problem of the Tad, because it seems to me as if the result is not properly shifted to the result registers. However, I'm using the RC clock for the ADC and as it is stated in the datasheet that by using the RC clock the required Tad timings are achieved.
Below is my ADC_RUN function, which I call for the conversion
Moreover, below is the part of the code that I use for the initialization of the ADC
The result is displayed in a LCD (the LCD and the functions displaying to it are working correctly)
Thanks for your help!
The problem is that after doing the conversions, the ADRESL register is always read as h'FF' no matter what input there is at the analog channel I'm using. I have checked -among others- to connect the input to the ground but the result remains the same, the ADRESL is always h'FF'
Does anyone have any idea of what's wrong?
I thought that it may be a problem of the Tad, because it seems to me as if the result is not properly shifted to the result registers. However, I'm using the RC clock for the ADC and as it is stated in the datasheet that by using the RC clock the required Tad timings are achieved.
Below is my ADC_RUN function, which I call for the conversion
Code:
ADC_RUN
BSF STATUS, RP0 ; Select Bank1
;**BSF PIE1, ADIE ; Enable A/D interrupts.
BCF PIE1, ADIE ; Disable A/D interrupts.
CLRF ADRESL
BCF STATUS, RP0 ; Select Bank0
MOVLW 0xC1 ; RC Clock, A/D is on, Channel 0 is selected
MOVWF ADCON0 ; Sampling time started
CLRF ADRESH
CALL Delay100
;
; Ensure that the required sampling time for the selected input
; channel has elapsed. Then the conversion may be started.
;
BSF ADCON0, GO ; Start A/D Conversion
; The ADIF bit will be set and the GO/DONE
; bit is cleared upon completion of the
; A/D Conversion.
ADC_END_WAIT
BTFSC ADCON0, GO ; Check the GO/DONE bit
GOTO ADC_END_WAIT ; ADC conversion not completed yet
BCF PIR1, ADIF ; Clear A/D interrupt flag bit
RETURN
Moreover, below is the part of the code that I use for the initialization of the ADC
Code:
; Port Initialisations
BSF STATUS, RP0 ; Select Bank1
CLRF LCD_TRIS ; configure PORTB as all outputs
MOVLW 0x21
MOVWF TRISA ; Configure PORTA : only RA0 is input
; Configuration for the A/D inputs :
; RA0 is set as analog, RA1-RA4 set as digital,
; VREF+ = VDD, VREF- = VSS
; and LSB of result put in ADRESL
MOVLW 0x8E
MOVWF ADCON1
BCF STATUS, RP0 ; Select Bank
The result is displayed in a LCD (the LCD and the functions displaying to it are working correctly)
Thanks for your help!