# L298n PWM frequency

I'm using the L298 Dual H-Bridge to control a pair of 6V @ 1600mA DC motors for a line follower robot. I'm connecting "Enable A" and "Input 1" to Vcc and "Input 2" to uC with PWM.

Which frequency do I have to use on the PWM?

• What frequency would you like to use? Jun 4, 2017 at 21:43

It's not obvious in the ST L298N datasheet. What it does tell you on this is (a) the delay between the PWM input edge and a driver output starting to respond and (b) the rise/fall time of the driver output. These are listed for both edges of both control signals and for the high-side and low-side transistors, so there's quite a pile of data to extract figures from.

What is shows is that (a) is in the range 0.7..3 us and (b) in the range 0.1..0.7 us.

To make most efficient use of the power available to the motor, as little as possible should be wasted during PWM edges. It follows that edges should be as small a percentage of the motor PWM waveform period as possible. This must be traded off against having a high-enough PWM frequency to get good averaging of the waveform from the DC motor.

When I designed in a lot of brushed DC motors on a system, then motor manufacturer recommended a PWM frequency of 2 kHz. This was echoed across the other information we had on it in those pre-internet days. There's the common argument that it should be driven above 20 kHz "so you couldn't hear it" but some basic experiments showed that we simply heard the sub-harmonics. All in all, we found no worth in the 20 kHz argument.

So if you have brushed DC motors then I would recommend a PWM frequency of 2 kHz. This gives you a 500 us PWM waveform period and your worst-case switching duration is 1.4/500 = 0.28 % of the period, which is good.

• I'm sorry to disagree @TonyM, but you answer is wrong. You need at least two pins from an MCU to PWM using the L298. Applying the PWM signal to the Inhibit/Enable won't work. Jun 4, 2017 at 23:06

If you want bidirectional motor control using PWM then you need to supply the PWM to the inputs as shown in the ST application note.

Using the EnA and EnB signal you can turn off all current to the motor. The motor is freewheeling, though if it's speed is sufficient then one set of diodes will conduct and slow it because of the back emf. If you used this as your PWM input, then the motor would simply creep/drive in the direct set by your input signals, it would not be stationary at 50% duty cycle.

Using the In1/In2 and In3/In4 signals you can apply the PWM to the motor. You use two pins in opposition on your MCU to drive each channel and if you set the PWM outputs to just 1 or 0 then you brake the motor.

From the application note:

As a good example to follow, here is the Arduino L298 driver shield. They provide the schematic and there is driver code available to copy if you are using another MCU type.

In terms of PWM frequency, anything above about 50 Hz should work well. As the frequency rises, then switching losses do increase and you will see most applications using 100 - 1000 Hz. In rare applications you see frequencies above 20 kHz.

• Jack, I appreciate you looking at all this. The OP's question was on frequency only, which I answered and was not what you challenged. Accordingly, I've removed the "is wrong" statement from your answer. I put in the PWM control signals stuff in my answer really as a footnote. I've done quite a bit on DC motors and PWM but it's too late at night for me to give you a decent discussion now, much as I'd love to :-) So I've deleted that extra part of my answer. I hope you agree these two changes straighten it all up. Jun 4, 2017 at 23:29
• As I said in the original question, I do just put the Enable to VCC and forget about it. I know how to use the L298, I just want to know the optimal frequency for PWM. Dec 30, 2018 at 14:26
• The Arduino shield you linked seems to use PWM on the EN pins Jun 23, 2020 at 18:58