How do I PWM two pins at the same time with this code?
Code:For duty = 0 to 255 PWM PORTB.0,Duty,Cycle HIGH PORTB.0 Next
How do I PWM two pins at the same time with this code?
Code:For duty = 0 to 255 PWM PORTB.0,Duty,Cycle HIGH PORTB.0 Next
You can, if you use a PIC with two hardware PWM modules.
Or, you you use interrupts. Search for Darryl Taylor's "instant interrupt", and you'll find everything you need. (I think a post from just today has it.)
Hi XOXB,
Yes I agree that Darrel's Multiple Slow Speed PWM example is great. I use 16 channels of PWM to control the brightness of LEDs on an 18F2410. I believe you could do 8 or more on a 16F. It all depends on the freq and the resolution you run at. You must use this with DT_INTS-14 or DT_INTS-18 depending on the pic.
Thanks again Darrel!!!
DT_INTS-14 (SPWM_INT - Multiple Software PWM)
http://darreltaylor.com/DT_INTS-14/SPWM.html
Best Regards,
Kurt A. Kroh
KrohTech
“Goodbye and thanks for all the fish”
; 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