Shop OBEX P1 Docs P2 Docs Learn Events
PWM help — Parallax Forums

PWM help

clloydclloyd Posts: 31
edited 2008-10-25 23:42 in BASIC Stamp
The PWM function has the parameters: Pin, duty cycle, and "duration". I clearly understand the duty cycle and the pin in which you want to output it through however i dont understand this "duration" parameter. If say I wanted to output a 50% duty cycle through pin 9 at a 1 kHz output would i then use an RC value of 1/(5*R*C) being equal to 1000 with the circuit that is shown in the index for PWM? Just not sure what the relevance of the RC component is just assumed you could set the frequency on the output and nothing else would be necessary.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-10-25 19:56
    The duration is the amount of time the desired PWM is output. The BASIC Stamp doesn't have a background PWM, where you set it and it keeps outputting pulses. After the selected duration has passed, output stops, and the pin is switched to an input so the cap won't discharge (except via leakage). The strategy here is that you output a burst of PWM, go do other stuff, output another burst of PWM, continue with other stuff, etc. The occasional bursts are necessary to keep the capacitor refreshed with the desired voltage or to change the voltage to a new value.

    -Phil
  • clloydclloyd Posts: 31
    edited 2008-10-25 20:07
    Ok so how often do you have to output the "burst" of PWM? Is this dependent on how long it takes your program to run and get back to the PWM call to do this output. Example lets say it takes 2 seconds for your entire program to run, how long would i set the duration in order to maintain a 1 kHz frequency to the output and which RC values would I choose if this were the situation and why? Thanks for your help
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-10-25 20:54
    You won't be able to maintain any frequency on the output. Once the duration time is over, the pulse outputs stop, and your program continues with the statement after the PWM. While the PWM burst is being output, your program does nothing else but wait for the PWM to finish. (PBASIC is single-tasking. It can do only one thing at a time.) The principal reason to use the PWM output is to charge a capacitor to a certain voltage, and then move on.

    -Phil
  • clloydclloyd Posts: 31
    edited 2008-10-25 21:15
    Ok, so it cant run multiple things at once, I am still confused about the PWM function if you are unable to actually do PWM, so I guess my question would be is it possible to do a constant PWM by setting some RC value and calling the PWM every so often and by setting a certain duration parameter. Basically is it possible for me to have an output PWM of around 1 kHz over a period of say 2 seconds(how long it takes my program to cycle) so I can then recall the PWM function to do another 2 seconds, so on and so forth.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-10-25 23:14
    No. The behavior you describe is not possible with a BASIC Stamp. Ongoing PWM is possible with either a MoBoStamp-pe or any of the Propeller products, including the Spin Stamp.

    What is your ultimate objective? There's usually more than one way to get from A to B.

    -Phil
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-10-25 23:33
    clloyd -

    You may also want to take a look at the PWMPal which Parallex sells:
    http://www.parallax.com/Store/Accessories/MotorServoControllers/tabid/160/ProductID/67/List/1/Default.aspx?SortField=ProductName,ProductName

    The PWMPal fits underneath the Stamp so it really needs no PCB real estate of its own.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • clloydclloyd Posts: 31
    edited 2008-10-25 23:42
    That PWMPal seems to be exactly what we need for our project, didn't read the datasheet fully but it seems to do the job we need perfectly.· We are just trying to control DC brushed motors but the PWM is constantly changing so the PWM pal seems to be something we are going to look into, thanks a lot for the help
Sign In or Register to comment.