Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 22nd October 2005, 07:11 AM   (permalink)
Default Special event trigger for ADC sampling

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...
elexhobby is offline   Reply With Quote
Old 22nd October 2005, 08:58 AM   (permalink)
Default

It all looks fine.
The only things I can see that may be wrong are.
IRP <> 0
ADCON1 not set up - but default should be OK
Fosc < 20MHz

The one unusual thing is you read the result before you check CCPR2 and therefore, your first result will be meaningless.

If you find the answer then please let us know as it looks an interesting problem.

Mike.
Pommie is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 05:36 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.