PWM 'channels ...what's that all about then!


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default PWM 'channels ...what's that all about then!

    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.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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.
    Attached Images Attached Images  
    All progress began with an idea

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    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)

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

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

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

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. 16-48 pin Multi slow PWM
    By krohtech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th March 2009, 03:28
  4. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  5. Variable PWM on 2 Channels using software.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2006, 01:34

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts