I am using the PIC16F877A uC.
I wanted to do sampling at a fixed rate.
The special event trigger simplifies matters since, when TMR1 count matches CCPR2, A/D conversion should automatically begin according to the data sheet.
But in my program that is not happening. :cry: I have switched on the A/D module.
I wanted to know do we have to manually start the A/D conversion by setting the GO/nDONE in ADCON0
Here's the relevant code:
movlw B'00000000' ;Timer1 set for internal clock with 1:1 prescale value & ensured that it is off
movwf T1CON
clrf TMR1H ;clear Timer1H & Timer1L registers
clrf TMR1L
clrf CCPR2H
movlw B'00001011' ;Special event trigger mode for ADC sampling at fixed rate
movwf CCP2CON
Pulse1 ;To ensure interrupts are disabled
bcf INTCON,GIE
btfsc INTCON,GIE
goto Pulse1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
movlw H'9E' ;ADRESL - Low byte storage of A/D result
movwf FSR
movlw B'10000001' ;Fosc/32 for 1.6us T-AD, AN0 as i/p channel, A/D module made on
movwf ADCON0
movlw H'C8' ;40uS sampling time
movwf CCPR2L
bsf T1CON,TMR1ON
REPEAT
bcf PIR2,0 ;Clear CCP2IF flag
movf INDF,W
movwf PORTB ;portB o/ps 8 LSBs
movf ADRESH,W
movwf PORTD ;PortD's 2 LSBs contain 2 MSB's of digital outputs
BACK
btfss PIR2,0 ;Wait for CCP2IF flag to be set.
goto BACK
NOTOVER
btfsc ADCON0,2
goto NOTOVER ;Polls to see whether conversion over
goto REPEAT
Kindly check & let me know the flaw in the program.
Thanks in advance...