ccp1if problem

Status
Not open for further replies.

kvrajasekar

New Member
Hi,

I am trying to use ccp in compare mode,i tried to set the out high on match,I got the output on timer1 and ccp register match,but i didnt get the cc1pif interrupt.and also it gets increment every instruction...

my code is follows,

list p=16f72 ;PIC16f72 is the target processor
INCLUDE "P16f72.INC"
;------------------------------------------------------------------------------------
__CONFIG _PWRTE_ON & _XT_OSC & _WDT_OFF ; configuration switches

org 0x00
goto main

org 0x04
btfsc PIR1,CCP1IF
goto pwm_loop

main bsf STATUS, RP0 ;Bank1
movlw b'00101111' ;Defining input and output pins
movwf TRISA ;Writing to TRISA register
movlw b'00001111' ;Defining input and output pins
movwf TRISB ;Writing to TRISB register 1-input,0-output
movlw b'00000000'
movwf TRISC
movlw 0x00
movwf ADCON1
bcf STATUS, RP0 ;Bank0
clrf PORTA ;potra,portb initially set to low
clrf PORTB
clrf PORTC
clrf CCP1CON

bsf INTCON,PEIE
clrf PIR1

bsf PIE1,CCP1IE

bsf INTCON,GIE ;Enbles interrupt.
bcf T1CON,TMR1ON
movlw d'8'
movwf CCP1CON
movlw 20
movwf CCPR1L
movlw 30
movwf CCPR1H
clrf TMR1H
clrf TMR1L
bsf T1CON,TMR1ON

wait goto wait //waiting for match
pwm_loop
end


please correct me if any wrong coding...


Regards,
Raja.
 
Your code is not going to work for a couple of reasons,
PIE1 is in bank 1 - not bank 0.
Your interrupt is going to jump to the end of the code and execute random memory.

If you want to wait for the match then poll the CCP1IF to see when it completes.
Code:
		list	p=16f72		;PIC16f72 is the target processor 
		INCLUDE	"P16f72.INC"  
;------------------------------------------------------------------------------------   
		__config _PWRTE_ON&_XT_OSC & _WDT_OFF  ; configuration switches 

		org	0x00 

main		bsf	STATUS,RP0	;Bank1 
		movlw	b'00101111'	;Defining input and output pins 
		movwf	TRISA		;Writing to TRISA register 
		movlw	b'00001111'	;Defining input and output pins 
		movwf	TRISB		;Writing to TRISB register 1-input,0-output 
		movlw	b'00000000' 
		movwf	TRISC 
		movlw	0x00 
		movwf	ADCON1 
		bcf	STATUS,RP0	;Bank0 
		clrf	PORTA		;potra,portb initially set to low 
		clrf	PORTB 
		clrf	PORTC 
		clrf	CCP1CON 

;removed interrupt bits

		bcf	T1CON,TMR1ON 
		movlw	d'8' 
		movwf	CCP1CON 
		movlw	20 
		movwf	CCPR1L 
		movlw	30 
		movwf	CCPR1H 
		clrf	TMR1H 
		clrf	TMR1L 
		bsf	T1CON,TMR1ON 

wait		btfss	PIR1,CCP1IF	;wait until TMR1=CCPR1
		goto	wait

;will get to here when match occurs

		bcf	PIR1,CCP1IF	;clear the flag


Hang		goto	Hang

		end

Mike.
 
Last edited:
Thank you very much mr.Mike.

Now my program works fine.

Can i use CCP in compare mode to generate sine pwm?.



-Raja.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…