1
\$\begingroup\$

I would like to know if it's advisable to control an H-bridge IC (L298N) using a single PWM pin?

Let me explain: By driving ENB pin High and by feeding complementary PWM (achieved by using a simple NPN transistor inverter circuit to invert PWM signal from Arduino) to IN1 and IN2, the dc motor connected to OUT1 and OUT2 is working (circuit schematic shown below).

Circuit Schematic for Interfacing with a L298N using a single PWM pin

In this setup, I am only using a single PWM: a duty cycle of 0% is maximum speed in one direction, a duty cycle of 100% is maximum speed in the other direction and a duty cycle of 50% stops the motor.

Apart from having a reduced resolution, everything seems to work. However all the tutorials online advise to use 3 pins to control L298N, with the PWM pin connected to ENB (for example this Tutorial). Why is this so? Is it not advisable to do what I did, using a single PWM pin?

\$\endgroup\$
  • 1
    \$\begingroup\$ adding a circuit schematic could help \$\endgroup\$ – muyustan Jun 1 '20 at 9:44
  • \$\begingroup\$ you can totally do that single-PWM control with an H-Bridge that is designed for that. Generally, the L298N is a terrible IC by modern standards, and so many better alternatives exist that it makes little sense trying to make this work with an antique IC like the L298N. Simply don't use a L298N but something that does what you need, done. \$\endgroup\$ – Marcus Müller Jun 1 '20 at 11:09
  • \$\begingroup\$ Can you suggest some modern ICs ? I chose L298N because it was relatively cheap. \$\endgroup\$ – glamis Jun 1 '20 at 11:15
1
\$\begingroup\$

In this setup, I am only using a single PWM: a duty cycle of 0% is maximum speed in one direction, a duty cycle of 100% is maximum speed in the other direction and a duty cycle of 50% stops the motor.

That is not really what this is doing, no.

Is it advisable to control an H-bridge IC (L298N) using a single PWM pin? By driving ENB pin High and by feeding complementary PWM

Generally, yes, if your H-Bridge has built in circuitry that eliminates the time during which both transistors of one side of the H-Bridge are on, then you can do that.

The L298N doesn't, so there's a short amount of time where the inverter hasn't inverted yet, but the uninverted path has already been toggled, where that happens. And that shoot-through can damage you H-Bridge, lead to catastrophic flyback spikes on the power supply line etc.

So, you need a better H-Bridge controller.

Getting an H-Bridge controller that isn't the L298N (and thus, from the 1970s) also allows you to omit the inverter, and go fully digital.

So, good approach, bad component. For example, TI has a pretty large portfolio of motor drivers. Some you can just instruct to do what you want, and don't have to do any PWM yourself.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your advice. I chose L298N because it was cheap and readily available for hobbyist \$\endgroup\$ – glamis Jun 1 '20 at 11:31
  • \$\begingroup\$ all these ICs are available, and I don't know how cheap your L298N was, but a device that doesn't do what you want (and your PWM forward/backward thing clearly won't work as intended) is always too expensive, no matter how cheap it is. \$\endgroup\$ – Marcus Müller Jun 1 '20 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.