; adjust duty 50%
; period of on state ,Tduty
; (CCPR2L with T2CON.5.4) = Tduty / (Tosc x T2prescale)
freq1 con $41 ; adjust for duty cycle
freq0 con $00 ; very low duty cycle for no output
ccpr2l = freq1 ; adjust Duty cycle
; adjust carrier frequency
; period of PWM ,Tpwm
; Tpwm = (PR2+1)x(4Tosc) x T2prescale
pr2 = 130
ccp2con = %00111111 ;MSB>> 2xNone..2xDuty2bitLSB..4xPWM mode >>LSB
t2con =%00010000 ; MSB>>1x None..4x PostScale....1xEnable..2xPrescale >>LSB
tmr2 =$00 ; clear timer2 register
t2con.2 =1 ; enable timer2 module
'------------ Variables ---------------
index1 var byte ; for loop count
goto test1
'-----------------------------------
test1:
;start freq
if portb.7=0 then
ccpr2l =freq1
endif
;stop freq
if portb.6=0 then
ccpr2l =freq0
endif
goto test1
Bookmarks