PDA

View Full Version : PWM 'channels ...what's that all about then!



HankMcSpank
- 23rd April 2009, 11:32
So there I am in my simple little world, using the PWM command to vary the DC level on an output pin (using a LPF). I need to do this on six output (ie differeing PWM duty cycles on six different oupt pins).

It came as a bit of a shock to find out last night that there's the concept of PWM 'channels'...could someone please explain brifley why we need different 'channels' & how we control them?

For example, here's a little bit of my code...

Increase_PWM:
pause 5
DEBUG "Increasing PWM........... DC IN = ",DEC DC_In, " DutyCycle = ", dec dutycycle, 13,10
IF dutycycle < duty_upper_limit THEN
dutyCycle = dutycycle +4
pwm RC0pin16, dutycycle , dutyCycle_Repeat
ENDIF
goto Decide_Gain
pwm RC0pin16, dutyCycle, dutyCycle_Repeat
GoTo Decide_Gain

ie...I simplyI alter the PWM duty cycle, depending on the incoming DC level - I didn't have to specify a PWM 'channel'. I just said essentially "slap some PWM output on pin RC0pin16" ...when would I need seperate channels - can't I just send the PWM to another output pin? 9if I need channels, how do I address them?)



Also (to save starting a new thread)...what's a good command to have an "IF" condition along the lines of "if DC_In = Optimum plus or minus 3" (where Optimum was set earlier i the program & DC_IN is a bog standard variable that changes with the D Ccoming in to a ADC pin).

At the minute, I'm having to use two concurrent IFs...

"if DC_In < Optimum +3 then blah"

followed by

"if DC_In > Optimum -3 then blah"

(I tried googling for al the above - to no avail!)

thanks,
Hank.

Melanie
- 23rd April 2009, 14:03
Whilst your program is executing your PWM command it is stuck there at that command... ie it can't do anything else unless you roll your own with a whole heap of clever interrupt processing.

Many PICs have HARDWARE PWM. That's great because you set it and forget it. It'll continue to run in background whilst you go and play Tetris on your LCD display or whatever. See HPWM Command.

Some PICs have more than one PWM Channel... Hence Channel 1 or Channel 2 etc... you might have a problem finding six.

Give a Guy an inch or two and he'll want six... typical!


You can always make your IF statements a little more complex...

if (DC_In < Optimum +3) or (DC_In > Optimum -3) then blah

... but you might find it uses more code than two seperate statements.

aratti
- 23rd April 2009, 15:15
using the PWM command to vary the DC level on an output pin (using a LPF). I need to do this on six output (ie differeing PWM duty cycles on six different oupt pins)

Hank, using a pic with one CCP channel you can obtain as many PWM outs as you like, simply with an extra logic gate. See the schematic attached, it should explain by itself how it works.

Al.

HankMcSpank
- 23rd April 2009, 15:59
Thanks for the explanation Melanie...I only want six becuase some idiot went & designed a guitar with six strings (I reckon every instrument should be created using the banjo model ....then it's be a doddle to use my humble PIC16F690 with it!)

aratti, thanks for the info...i'm not sure that'll be helpful in my scenario, as I need to vary the PWM duty cycle per pin output (whereas that schematic uses one common PIC PWM output stream & then just 'ands' it to suit)

Bruce
- 23rd April 2009, 16:46
The 18F2331/2341/4331/4431 have a lot of PWM outputs.

See this thread http://www.picbasic.co.uk/forum/showthread.php?t=7095

Bruce
- 23rd April 2009, 16:49
No edit, bummer..;o}


The 18F2331/2341/4331/4431 have a lot of PWM outputs.


Should be; The 18F2331/2431/4331/4431 have a lot of PWM outputs.