10 years, 8 months ago.

PWM Motor won't run at high frequencies, why?

So I'm using the following command trying to control a DC motor through PWMing on L298N H-bridge on the enable line

en_a.period_us(200);

What I notice is if I start to decrease the period beyond this point, the motor gets to a point where it doesn't move. Why is that?

2 Answers

10 years, 8 months ago.

Do you also update the duty cycle? The mbed lib is supposed to default to 50% dutycycle and maintain this automatically when you change the period. However, a recent comment indicated that this code may be broken at the moment. Best answer is to either measure and confirm it it OK now or set duty at 50% whenever you change the period. Note that min period for standard PWM is 1us (1 MHz).

2us actually, since the pulsewidth is also 1us accuracy. So 50% duty cycle at 2us is the fastest standard PWM can go. http://mbed.org/users/Sissors/code/FastPWM/ can go up to full clock period for the pulsewidth.

posted by Erik - 11 Mar 2014
10 years, 8 months ago.

There are two things which restrict the pwm speed. The switching speed of the L298N ~ 2us and the inductance of the motor winding. The speed is controlled with the duty-cycle not the period. If you lower the period , you also lower the switching losses, but you can get a acoustical problem. The motor can buzz. If you want to control a motor with high speed signals, you have to use high voltages and a current regulation.

Yes, speed is controlled with duty-cycle. By "lowering" the period I am interpreting your response as meaning that I need to increase the period duration (that is from 10us to 50us for example). So increasing the period will effectively decrease the frequency of the PWM signal which directly contributes to audible frequency if I fall below 20kHz.

Onto your last sentence regarding high speed signals, can you describe this circuit or include a schematic sketch? I'm not familiar with this implementation. And thanks so much for responding! This was a really helpful response as I did NOT remember to consider inductance of the motor.

posted by Joshua Liu 11 Mar 2014

The L298N's switching speed means that to go both up and down will take approximately 4us, assuming you want a triangle and not a square. Thus, your absolute max switching frequency is going to be 250KHz, if you've got a purely resistive load. I'd recommend staying even lower than that - say, 30KHz (33 microsecond period), just so you have some room to make a square, rather than a triangle.

Beyond that, because you're switching an inductive load, the current through the motor won't change instantly. Instead, the motor will take some time to respond as well. Since V = L * di/dt, you can speed this process up by reducing inductance (different motor) or increasing the voltage you're putting across the motor. Thing is, if you put a 'lot' of voltage across the motor, once you get through the transient region (and you've actually gotten the current to where you want it) you're just dumping current through the resistance of the windings, and bad things will happen (melting). Thus, the 'best' case is to use a current-regulated driver, such that you get short spikes of high voltage, allowing current to change rapidly, and then as the inductance relaxes, the voltage the driver is applying reduces back to more nominal levels. You'll see this behaviour a lot in stepper motor drivers, which need to pulse rapidly to turn quickly.

posted by Greg Link 12 Mar 2014