View Full Version : PWM with H Bridge

02-28-2007, 09:36 PM
Hi all.

Just a question to make sure.

Is it posible to control·the speed of a motor with H bridge·by using·PWM or just use Hi/Low command?

Thanks for the answer.

Mike Green
02-28-2007, 10:54 PM
An H-bridge just turns the motor on and off in either of the two directions. The PWM statement varies the average amount of time spent on and therefore the speed. You'll typically control the direction with a HIGH/LOW signal.

Phil Pilgrim (PhiPi)
02-28-2007, 11:26 PM
Yes, it's possible, if the H-bridge IC you're using has an enable input. ST Micro's L6203 is an example. It not only has an enable input for modulation by a PWM signal, but it has a sense pin for attaching a current sense resistor. With a low-value resistor attached between this pin and ground, the voltage on the pin can be used as feedback to the PWM controller.


Chris Savage
03-01-2007, 08:35 AM
As a note the PWM command on the BASIC Stamp isn’t really designed to drive an H-Bridge and will not continuously pulse the pin. The PWM command was designed to generate an analog voltage using a filter. The PWMPAL, linked below can drive the H-Bridge in the manner you need. Take care.


Chris Savage
Parallax Tech Support

Phil Pilgrim (PhiPi)
03-01-2007, 10:51 AM
You might also consider Parallax's MoBoStamp-pe (http://www.parallax.com/detail.asp?product_id=28300), which includes a BS2pe chip and two onboard coprocessors. With the pre-installed GPIO3 firmware, each coprocessor can sustain two PWM outputs at up to 37.5KHz, as well as perform A/D conversions to 10 bits of precision and event/frequency counting to 1MHz. The coprocessors respond to simple commands from the onboard BS2pe via its OWOUT statement.


03-01-2007, 04:18 PM
Hi everybody.

Thanks for the reply.

Phipi said :"Yes, it's possible, if the H-bridge IC you're using has an enable input. ST Micro's L6203 is an example."

How about if I use this(attached Photo) H Bridge. It use L298. can i send PWM to this H bridge to control the speed. I try to get the Hb25 but it seem too expensive here in my place.(USD 160 for 2).

I'm stuck here for my robotic project.·I·don't want to use servo cause it's too slow.

Thanks·in advance for your answer.

Phil Pilgrim (PhiPi)
03-01-2007, 04:46 PM
The L298 should work fine with a PWM speed control signal, since it has enable inputs. It also has sense pins, in case you need to monitor the motor current.


03-01-2007, 05:05 PM
Thanks Phil.

03-30-2007, 05:55 AM
I have built my own H-Bridge. If I just pulse one of the inputs to the H-Bridge, wouldn't that work just the same as pulsing an enable?

Like this:

Input 1-----Input 2

Post Edited (legiondttm) : 3/29/2007 10:59:58 PM GMT

T Chap
03-30-2007, 08:42 AM
If one input is for one direction, and the other is for the other direction, then yes you can pulse the pin and affect the speed. There are IC's you could use that would allow external PWM at whatever Frequency and Duty you wanted. A very easy solution would be to add an SX20/28 to your project, they are easy to program and are very cheap. You could let the SX be the PWM engine, just send it a serial input with the info, or use some parallel pins between the Stamp and SX that translate into duty. For low resolution, you could use 4 pins between the two, the SX uses those pins to scale 1 to 16 vaues for duty.

Post Edited (TChapman) : 3/30/2007 3:55:01 AM GMT

03-30-2007, 10:46 PM
I went to the lab today to test out the PWM. It works fine to pulse the inputs rather than a chip-enable. Though, I did make my H-Bridge using discrete darlington-pair transistors instead of using a chip, but I doubt that would make any difference.

Loopy Byteloose
03-30-2007, 11:23 PM
Generally, the PWM would be used to reduce the speed in an H-bridge. And it might even control the amount of acceleration or deceleration. But, the PWM requires that the BasicStamp be occupied with producing pulses. If you can use the H-bridge without the PWM, the BasicStamp will have more free time to manage sensors.

In sum, H-bridges [when properly designed and matched to the motor] will usually take full on; full off; or pulses.

IT depends on what you want.

"If you want more fiber, eat the package.· Not enough?· Eat the manual."········

···················· Tropical regards,····· G. Herzog [·黃鶴 ]·in Taiwan