PDA

View Full Version : Pwm



xobx
- 10th February 2008, 15:07
How do I PWM two pins at the same time with this code?



For duty = 0 to 255
PWM PORTB.0,Duty,Cycle
HIGH PORTB.0
Next

tenaja
- 10th February 2008, 15:54
With the PWM command, you can not.

xobx
- 10th February 2008, 15:58
Is there anyway you can PWM to pins at the same time?

tenaja
- 10th February 2008, 16:00
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.)

krohtech
- 10th February 2008, 18:40
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

paul borgmeier
- 11th February 2008, 06:15
Is there anyway you can PWM to pins at the same time?

Do they need to be at the same frequency?

Are the duty cycles related (e.g., 1/2 or double of the other)?

grich
- 11th February 2008, 06:33
; 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