A/D routine

Started by VIBHA RAVINDRAN August 7, 2003
Hi All!

I am using PIC16F877 and am programming in the MPLAB environment.
The A/D subroutine in my program is as follows. However When I read the values
later, I figure that the A/D conversion hasnt taken place and the value stored
in the corresponding register is 0x00.

I would really appreciate any kind of input, esply since I am working against a
deadline!

Thanks,
Vibha

MOVLW 0x0F
; Set PORTA as ANALOG I/O WITH Vref+ and Vref- LEFT JUSTIFIED
MOVWF ADCON1 BCF STATUS, RP0 ; Go back to Bank 0
MOVLW 0x81
; 1000 0001 FOSC/32 set, Channel 1 (RA0), A/D on
MOVWF ADCON0

BSF ADCON0, 2
;SET GO/DONE BIT TO GO

CHK_AD
;POLLS GO/DONE BIT TO FIND WHEN A/D DONE
BTFSC ADCON0,2
GOTO CHK_AD

MOVF ADRESH, W
MOVWF CF_DATA



Hi All!

I am using PIC16F877 and am programming in the MPLAB environment.
The A/D subroutine in my program is as follows. However When I read the values
later, I figure that the A/D conversion hasnt taken place and the value stored
in the corresponding register is CF_DATA.

I would really appreciate any kind of input, esply since I am working against a
deadline!

Thanks,
Vibha

BSF STATUS, RP0 ; Bank 1
MOVLW 0x0F
; Set PORTA as ANALOG I/O WITH Vref+ and Vref- LEFT JUSTIFIED
MOVWF ADCON1 BCF STATUS, RP0 ; Go back to Bank 0
MOVLW 0x81
; 1000 0001 FOSC/32 set, Channel 1 (RA0), A/D on
MOVWF ADCON0

BSF ADCON0, 2
;SET GO/DONE BIT TO GO

CHK_AD
;POLLS GO/DONE BIT TO FIND WHEN A/D DONE
BTFSC ADCON0,2
GOTO CHK_AD

MOVF ADRESH, W
MOVWF CF_DATA



What voltages are you putting on the reference pins? What is the
input voltage?

--- In , "VIBHA RAVINDRAN" <vibhar@p...> wrote:
> Hi All!
>
> I am using PIC16F877 and am programming in the MPLAB environment.
> The A/D subroutine in my program is as follows. However When I read
the values
> later, I figure that the A/D conversion hasnt taken place and the
value stored
> in the corresponding register is CF_DATA.
>
> I would really appreciate any kind of input, esply since I am
working against a
> deadline!
>
> Thanks,
> Vibha
>
> BSF STATUS, RP0 ; Bank 1
> MOVLW 0x0F
> ; Set PORTA as ANALOG I/O WITH Vref+ and Vref- LEFT JUSTIFIED
> MOVWF ADCON1 > BCF STATUS, RP0 ; Go back to Bank 0
> MOVLW 0x81
> ; 1000 0001 FOSC/32 set, Channel 1 (RA0), A/D on
> MOVWF ADCON0
>
> BSF ADCON0, 2
> ;SET GO/DONE BIT TO GO
>
> CHK_AD
> ;POLLS GO/DONE BIT TO FIND WHEN A/D DONE
> BTFSC ADCON0,2
> GOTO CHK_AD
>
> MOVF ADRESH, W
> MOVWF CF_DATA




Hi!

The voltage on my reference pin ( Vref+) is about 3V and (Vref-)is grounded.

Thanks for your interest :)

Vibha

On Thu, 07 Aug 2003 21:58:59 +0000, "rtstofer" wrote:

> What voltages are you putting on the reference pins? What is the
> input voltage?
>
> --- In , "VIBHA RAVINDRAN" <vibhar@p...> wrote:
> > Hi All!
> >
> > I am using PIC16F877 and am programming in the MPLAB environment.
> > The A/D subroutine in my program is as follows. However When I read
> the values
> > later, I figure that the A/D conversion hasnt taken place and the
> value stored
> > in the corresponding register is CF_DATA.
> >
> > I would really appreciate any kind of input, esply since I am
> working against a
> > deadline!
> >
> > Thanks,
> > Vibha
> >
> > BSF STATUS, RP0 ; Bank 1
> > MOVLW 0x0F
> > ; Set PORTA as ANALOG I/O WITH Vref+ and Vref- LEFT JUSTIFIED
> > MOVWF ADCON1
> >
> >
> > BCF STATUS, RP0 ; Go back to Bank 0
> > MOVLW 0x81
> > ; 1000 0001 FOSC/32 set, Channel 1 (RA0), A/D on
> > MOVWF ADCON0
> >
> > BSF ADCON0, 2
> > ;SET GO/DONE BIT TO GO
> >
> > CHK_AD
> > ;POLLS GO/DONE BIT TO FIND WHEN A/D DONE
> > BTFSC ADCON0,2
> > GOTO CHK_AD
> >
> > MOVF ADRESH, W
> > MOVWF CF_DATA >
> to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
>
> ">http://docs.yahoo.com/info/terms/ >
>


Hi Vibha,

Obvious issues are:

1. Ensure bank 1 for MOVWF ADCON1
2. Ensure that RA0, RA2, and RA3 are configured as inputs.
3. Ensure that you have +ref on RA3 and -ref(Gnd) on RA2.

Chad

--- In , "VIBHA RAVINDRAN" <vibhar@p...> wrote:
> Hi All!
>
> I am using PIC16F877 and am programming in the MPLAB environment.
> The A/D subroutine in my program is as follows. However When I read
the values
> later, I figure that the A/D conversion hasnt taken place and the
value stored
> in the corresponding register is 0x00.
>
> I would really appreciate any kind of input, esply since I am
working against a
> deadline!
>
> Thanks,
> Vibha
>
> MOVLW 0x0F
> ; Set PORTA as ANALOG I/O WITH Vref+ and Vref- LEFT JUSTIFIED
> MOVWF ADCON1 > BCF STATUS, RP0 ; Go back to Bank 0
> MOVLW 0x81
> ; 1000 0001 FOSC/32 set, Channel 1 (RA0), A/D on
> MOVWF ADCON0
>
> BSF ADCON0, 2
> ;SET GO/DONE BIT TO GO
>
> CHK_AD
> ;POLLS GO/DONE BIT TO FIND WHEN A/D DONE
> BTFSC ADCON0,2
> GOTO CHK_AD
>
> MOVF ADRESH, W
> MOVWF CF_DATA