I'm working on a 2-wheeled robot and have connected up a raspberry pi to an L298N motor driver.

I'm sending the enable pin of a particular motor a software-generated PWM signal at 100Hz with a 50% duty cycle. I observe with an osciloscope:

  • a fairly clean square wave going into the enable pin as expected.
  • a fairly dirty square wave across the output motor terminals.

The motor turns at about 50% speed/torque as expected.

I find myself wondering if it would be better to control the speed of the motor by placing a flat lower constant voltage across its terminals, rather than oscillating a square wave. ie to do 50% speed/torque - instead of oscilating between 0V and 5V - just put a constant 2.5V across the motor terminals. I wonder if the oscillation is a waste of power/energy.

Is this true? Or doesn't it make any difference? Do high-end motor drivers use a variable flat analog voltage to control speed/torque, or do they use a PWM? If a PWM, does the frequency make any difference?


4 Answers 4


(I'd prefer this to be a commment but I don't have enough rep ;( )

Good question! Here are a few resources that might help:

Look at this for the PWM frequency question: https://electronics.stackexchange.com/questions/67663/criteria-behind-selecting-pwm-frequency-for-speed-control-of-a-dc-motor

-> Essentially the motor acts as a filter and can average out the pwm wave to create an analog voltage, so you want to look for a frequency that does this best. PWM can also effect the sound of your motors.

Look at this for PWM vs Analog: https://electronics.stackexchange.com/questions/87103/why-is-pwm-used-to-control-dc-motor-speed-instead-of-using-a-variable-resistance

-> It's more efficient to use PWM compared to, say, a resistor in series, as a lot power is dissipated through the resistor. It's also much easier to output a PWM pulse and is typically built into microcontroller's hardware nowadays.

  • $\begingroup$ Why not put your comments regarding your links in your answer, at the links? $\endgroup$
    – Chuck
    Commented Jul 31, 2015 at 14:21
  • $\begingroup$ Good idea. Edited above. $\endgroup$
    – JMarple
    Commented Jul 31, 2015 at 14:39

Essentially, PWM supplies full rated voltage to a component and effectively varies the current supplied by turning the component on and off very quickly.

For some things, like an LED, which has a bias voltage that must be surpassed for the LED to turn on, you must supply a voltage greater than the bias voltage. If you try to use an analog voltage supplied to the LED as a means of brightness control, you can only dim to a point, where you hit the bias voltage, at which point the LED turns off completely.

For other things, like your motor, there is great cost to generating an analog voltage. How are you intending to do it? A linear regulator uses essentially a voltage divider to create the analog voltage. This means if you want to supply 50% voltage to your motor, the other 50% of that voltage is being "burned off" by a large resistor in the form of heat.

The PWM output is supplying rated voltage to the motor, but the inductance (coil) in the motor creates a time constant in your circuit which is acting like (is, actually) a filter, which is why you are seeing a "dirty" square wave. There is very very little power loss in doing switching (PWM) power supply because the inductance and reactance in the load that causes the filtering effect are both imaginary loads; whatever power they "consume" while the capacitor/inductor is charging is paid back when they discharge; this is why you get the shark fin look on a square wave.

So, your options are to use PWM to provide a switching power supply directly to the motor, or send a PWM signal to 3rd party power supply to it can provide a switching power supply to the motor, or use a linear regulator and suffer the consequences


You are partly right, in thinking that high end Motor drives use a better method. But those methods may not be suitable in your small robot application, just because, to get that ease of control with power, you would need more power electronics(- because the circuit necessarily need to have fine control over current/voltage characteristics, plus feedback of output speed and torque).

With PWM, you always have this control, as you can employ duty cycles varying from 1 to 99 to output varying drive behavior. If for instance, you were using an analogue control, (12Volts) 1. the circuit needs to have fine control over voltage, which increases circuit complexity. 2. the feedback needs be there to ensure the voltage fed is at par with poer needed. ...and I always prefer PWM, because, it gives finer control without adding much complex electronics, and keeping the fed voltage constant. Hope this helps


Decades ago I saw some modified robots at a University laboratory - the motors used analogue control.

Computers used regular DAC chips to output analogue voltages, these were then amplified using some DIY kit audio amplifiers - effectively DC amplifiers as the input capacitors were removed, replaced by links. The output of the amplifiers fed the motors directly.

However I think this was done simply because the parts were readily available at the time. The amplifiers had failry small heatsinks but needed split/bipolar power supplies, and these days the common PWM method perhaps using microcontrollers would be easier and cheaper.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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