Electronic – arduino – How to interface with an H-bridge IC (L298N) using a single PWM pin

arduinodc motorh-bridgel298pwm

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?

Best Answer

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.