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

PWM

ArchiverArchiver Posts: 46,084
edited 2004-06-01 20:19 in General Discussion
I need help to a project where I need to have a stamp capable to generate 3
square wave frequencies:
20Hz, 150 Hz and 5 KHz with duty cycle 50% .I did the inputs part but I can
not have the frequencies
at 50% duty cycle. I have the right pulse ON but the OFF period between the
pulses is very short, which make like 90% duty cycle and not 50%.
Help please
Thank you
Ion

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-19 01:00
    OK.... I am trying to figure a daamn simple code.....

    I have BS2p. Tryyed an alternate code to make a dc gearhead go first one
    way for 120 degrees, pause, then return to its spot, pause, ectc....

    Willlater incorpoarate sensor code..... but I digress

    I am using an h brdige from HVW technologies.............
    (L298, i believe)

    any who......i wrote a code that was non, PWM, and I don't think it worked,

    So I have pin 0 as grnd
    pin 1 as forward
    and pin 2 as backward..
    how in the hellena do i write this code????

    johnny be stupid
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-23 14:33
    hi,
    why with an hbridge motor contoller,
    if i use the following instruction PWM 0,16,25 it slow down my motor,
    and if i had this intruction PWM 2,16,25 then boths motors go back
    to high speed, i'm using an BS2
    surely there's something that i dont understand about PWM

    thanks

    John
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-23 16:33
    In a message dated 6/23/2003 6:36:16 AM Pacific Daylight Time,
    johneck790@s... writes:

    > hi,
    > why with an hbridge motor contoller,
    > if i use the following instruction PWM 0,16,25 it slow down my motor,
    > and if i had this intruction PWM 2,16,25 then boths motors go back
    > to high speed, i'm using an BS2
    > surely there's something that i dont understand about PWM
    >
    > thanks
    >
    > John

    I did not see your original post but.....

    An H bridge is a convenient way to reverse the motor direction (polarity of
    voltage applied to motor)
    I don't know if you are driving the motor directly with the stamp or
    not....but the H bridge will also use less "drive" current from the stamp.

    The H bridge is not needed if the motor direction will always be the same.

    H bridge or not, it is always a good idea to drive the motor with a MOSFET of
    some kind to reduce the current needed by the stamp to drive the motor...


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-23 20:14
    Thanks,

    my hbridge works fine, the problem is how to program the BS2 to make it work

    motor by motor PWM works, it's when i try both motors at the same time that
    doesnt!

    rightfwd con 0
    leftfwd con 2

    rightbck =0
    leftbck =0
    pwm rightfwd, 16,25
    pwm leftfwd, 16,25

    what's wrong with this program?

    John

    Original Message

    From: basicstamps@yahoogroups.com
    Date: June 23, 2003 11:43:23 AM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] PWM

    In a message dated 6/23/2003 6:36:16 AM Pacific Daylight Time,
    johneck790@s... writes:

    > hi,
    > why with an hbridge motor contoller,
    > if i use the following instruction PWM 0,16,25 it slow down my motor,
    > and if i had this intruction PWM 2,16,25 then boths motors go back
    > to high speed, i'm using an BS2
    > surely there's something that i dont understand about PWM
    >
    > thanks
    >
    > John

    I did not see your original post but.....

    An H bridge is a convenient way to reverse the motor direction (polarity of
    voltage applied to motor)
    I don't know if you are driving the motor directly with the stamp or
    not....but the H bridge will also use less "drive" current from the stamp.

    The H bridge is not needed if the motor direction will always be the same.

    H bridge or not, it is always a good idea to drive the motor with a MOSFET
    of
    some kind to reduce the current needed by the stamp to drive the motor...


    [noparse][[/noparse]Non-text portions of this message have been removed]


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


    .

    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-23 20:27
    The Stamp's PWM command is NOT designed for motor control; it is designed to
    generate an analog voltage through an RC filter. We will be releasing an
    accessory module called the PWMPAL that mounts under the Stamp and will let you
    create (background) PWM streams (up to four) that can run motors.

    -- Jon Williams
    -- Parallax

    In a message dated 6/23/2003 2:15:52 PM Central Standard Time,
    johneck790@s... writes:

    > Thanks,
    >
    > my hbridge works fine, the problem is how to program the BS2 to make it work
    >
    > motor by motor PWM works, it's when i try both motors at the same time that
    > doesnt!
    >
    > rightfwd con 0
    > leftfwd con 2
    >
    > rightbck =0
    > leftbck =0
    > pwm rightfwd, 16,25
    > pwm leftfwd, 16,25
    >
    > what's wrong with this program?
    >
    > John
    >



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-23 20:34
    It depends on your H-bridge. Many bridges have a PWM input. Can you be
    specific about what kind of bridge circuit you are using?

    Keep in mind that the Stamp's PWM command only generates PWM for a fixed
    duration. If you want up to 8 continuous PWM outputs, have a look at
    http://www.al-williams.com/pak5.htm

    Al Williams
    AWC
    * Floating point A/D
    http://www.al-williams.com/awce/pak9.htm



    >
    Original Message
    > From: John Courtney [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=g_mwCyt3-tGim60KJit6StiN0vMprn8srmw2eMhIs2Al3xC4olE2XUCgd2IuTHibVuYWWqVlh0_hsosMtC-vMANm]johneck790@s...[/url
    > Sent: Monday, June 23, 2003 2:14 PM
    > To: basicstamps@yahoogroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] PWM
    >
    >
    > Thanks,
    >
    >
    >
    > my hbridge works fine, the problem is how to program the BS2
    > to make it work
    >
    >
    > motor by motor PWM works, it's when i try both motors at the
    > same time that doesnt!
    >
    >
    >
    > rightfwd con 0
    >
    > leftfwd con 2
    >
    >
    >
    > rightbck =0
    >
    > leftbck =0
    >
    > pwm rightfwd, 16,25
    >
    > pwm leftfwd, 16,25
    >
    >
    >
    > what's wrong with this program?
    >
    >
    >
    > John
    >
    >
    >
    >
    Original Message
    >
    >
    >
    > From: basicstamps@yahoogroups.com
    >
    > Date: June 23, 2003 11:43:23 AM
    >
    > To: basicstamps@yahoogroups.com
    >
    > Subject: Re: [noparse][[/noparse]basicstamps] PWM
    >
    >
    >
    > In a message dated 6/23/2003 6:36:16 AM Pacific Daylight Time,
    >
    > johneck790@s... writes:
    >
    >
    >
    > > hi,
    >
    > > why with an hbridge motor contoller,
    >
    > > if i use the following instruction PWM 0,16,25 it slow down
    > my motor,
    >
    > > and if i had this intruction PWM 2,16,25 then boths motors go back
    >
    > > to high speed, i'm using an BS2
    >
    > > surely there's something that i dont understand about PWM
    >
    > >
    >
    > > thanks
    >
    > >
    >
    > > John
    >
    >
    >
    > I did not see your original post but.....
    >
    >
    >
    > An H bridge is a convenient way to reverse the motor
    > direction (polarity of
    >
    > voltage applied to motor)
    >
    > I don't know if you are driving the motor directly with the stamp or
    >
    > not....but the H bridge will also use less "drive" current
    > from the stamp.
    >
    >
    >
    > The H bridge is not needed if the motor direction will always
    > be the same.
    >
    >
    >
    > H bridge or not, it is always a good idea to drive the motor
    > with a MOSFET of
    >
    > some kind to reduce the current needed by the stamp to drive
    > the motor...
    >
    >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    >
    > basicstamps-unsubscribe@yahoogroups.com
    >
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/





    .

    [noparse][[/noparse]Non-text portions of this message have been removed]


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-23 23:33
    Hello,

    Soon is right now. The PWMPAL is in stock and ready for shipment. The
    product ships with printed documentation that will help you get familiar
    with this new device. It requires a BASIC Stamp of the 24 pin variety
    (sold separately).

    For more information please visit the PWMPAL product page at this link -
    http://www.parallax.com/detail.asp?product_id=28020

    Sincerely,

    Erik Wood
    ewood@p...
    Parallax, Inc.
    599 Menlo Dr., Suite #100
    Rocklin, CA 95765
    (916) 624-8003 Fax
    (888) 512-1024 Sales

    http://www.parallax.com

    Check out our BASIC Stamp Courses!
    http://www.parallax.com/html_pages/edu/courses/registration.asp

    Original Message
    From: Jon Williams (AOL)
    Sent: Monday, June 23, 2003 12:27 PM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] PWM


    The Stamp's PWM command is NOT designed for motor control; it is
    designed to
    generate an analog voltage through an RC filter. We will be releasing
    an
    accessory module called the PWMPAL that mounts under the Stamp and will
    let you
    create (background) PWM streams (up to four) that can run motors.

    -- Jon Williams
    -- Parallax

    In a message dated 6/23/2003 2:15:52 PM Central Standard Time,
    johneck790@s... writes:

    > Thanks,
    >
    > my hbridge works fine, the problem is how to program the BS2 to make
    > it work
    >
    > motor by motor PWM works, it's when i try both motors at the same time

    > that doesnt!
    >
    > rightfwd con 0
    > leftfwd con 2
    >
    > rightbck =0
    > leftbck =0
    > pwm rightfwd, 16,25
    > pwm leftfwd, 16,25
    >
    > what's wrong with this program?
    >
    > John
    >



    [noparse][[/noparse]Non-text portions of this message have been removed]


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-01 10:45
    Who can explain me how the PWM command works?

    Thx.
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-01 14:16
    There is an eplenation in the manual and help file. The PWM command is
    designed to be filtered in order to create an analog output. It is
    different from PWM outputs that are used to drive DC motors.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: alexetouioui3 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ID4JQ6toPzVal09nbFniiIPnoRluWFiC6h3UoctoiC6pNFLf2Vs8CXJShY-UmUPWJQCqTeVjazUiY-noX-H01G_d]alexetouioui@h...[/url
    Sent: Tuesday, June 01, 2004 4:45 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] PWM


    Who can explain me how the PWM command works?

    Thx.
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-01 15:39
    >Who can explain me how the PWM command works?
    >
    >Thx.

    There is an extra explanation at <http://www.emesys.com/BS2PWM.htm>.
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-01 17:20
    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > >Who can explain me how the PWM command works?
    > >
    > >Thx.
    >
    > There is an extra explanation at < http://www.emesys.com/BS2PWM.htm >.


    Good write up. The old manual under Basic Stamp 1 App notes, says
    that using the circuit, they got up to about 15 minutes of an output
    for a single burst of PWM. Your notes say seconds.

    Any idea why the difference ?

    does changing the pin state after a burst have any effect on the
    duration of the sigal ?

    Dave
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-01 17:43
    It depends on the load placed on the circuit. We recommend using an
    opamp buffer as shown on Tracy's web site.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: Dave Mucha [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=F6mMxJGJTjZmEK9YLq491E8fLbVoyaAsPZR9tQ1UT0wGvfHYuwUdd099QmD3363bsX3taCalCW3uvyV3]davemucha@j...[/url
    Sent: Tuesday, June 01, 2004 11:21 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: PWM


    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > >Who can explain me how the PWM command works?
    > >
    > >Thx.
    >
    > There is an extra explanation at < http://www.emesys.com/BS2PWM.htm >.


    Good write up. The old manual under Basic Stamp 1 App notes, says
    that using the circuit, they got up to about 15 minutes of an output
    for a single burst of PWM. Your notes say seconds.

    Any idea why the difference ?

    does changing the pin state after a burst have any effect on the
    duration of the sigal ?

    Dave





    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.

    Yahoo! Groups Links







    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-01 20:19
    Hi Dave,

    With a good CMOS input op-amp, the hold time can indeed be minutes.
    There is a leakage current which depends on the op-amp, the BASIC
    Stamp input, the capacitor and also on how clean and dry your circuit
    board is.

    The falloff in voltage with time is usually called "droop" and it
    might be millivolts per second. If it only needs to hold within 0.1
    volt, the acceptable time will be much longer than if it needs to
    hold within 1 millivolt. You can easily measure it with a voltmeter
    on the output of the op amp.

    Pay attention to the business mentioned in my web writeup, about
    interaction (clock feedthrough) between adjacent channels. PWM to
    p0 and then PWM to p1, the value on p0 will change under some
    conditions. The web page write-up shows how to get around that by
    using a snubber capacitor.

    Also you have to be aware that a PWM value that holds a voltage near
    the Stamp input switching threshold will cause the Stamp to draw
    excess current. That is in the nature of the CMOS digital input,
    which is not really designed to be used in the linear mode near that
    threshold. (It is great! that it works though). The excess current
    will be about 1.5 milliamps per pin held near 1.5 volts.
    You can see this spike of current on a millamp-meter monitoring the
    Stamp current as it sweeps filtered PWM through the threshold.

    Any command that addresses the same 8-bit port on which PWM is
    operating, may cause the PWM value to shift slightly. For example,
    if you have PWM output on p0 and p1, and you have a shiftout command
    on p3 to p5 on the same 8-bit port, that will cause the PWM values
    held on p0 and p1 to shift slightly. There is the clock feedthrough
    effect mentioned above that can be snubbed, but also there is another
    effect when p0 or p1 are held near the switching threshold. It is as
    if the pins briefly become outputs during the read-modify-write cycle
    on the port. I can not be too clear about that, because I don't
    understand exactly what is going on. But it is one of those little
    things that might surprise you if you are not expecting any
    interaction at all. Those effects can make the PWM'd value to droop
    or increase, depending...

    -- best regards,
    Tracy


    >--- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    >> >Who can explain me how the PWM command works?
    >> >
    >> >Thx.
    >>
    >> There is an extra explanation at < http://www.emesys.com/BS2PWM.htm >.
    >
    >
    >Good write up. The old manual under Basic Stamp 1 App notes, says
    >that using the circuit, they got up to about 15 minutes of an output
    >for a single burst of PWM. Your notes say seconds.
    >
    >Any idea why the difference ?
    >
    >does changing the pin state after a burst have any effect on the
    >duration of the sigal ?
    >
    >Dave
    >
Sign In or Register to comment.