Jump to content

How Does PWM Work?

Judd

I have been interested in PWM for a while now, and I know how it works, but I want to know something. Let's say I have an Arduino with a PWM chip connected to the base of a transistor, and I have a 12v DC battery (2amps) and a motor connected to the collector and transmitter.  The motor pulls a maximum of 2amps, so the max the battery can supply. Let's say I put the PWM chip at half cycle, so only on 50% of the time.  First, can the transistor start and stop this quickly? If so, would the motor effectively run at half speed? And finally, does it run at half speed because the voltage was halved or the current? Because the minimum voltage of the motor to run is 3v, so if I did 20% cycle it would not spin up, only if the voltage is split. But if the current was split it would be fine. If this doesn't make sense I can draw a quick diagram of it and rephrase the question. Thanks for helping. 

Link to comment
Share on other sites

Link to post
Share on other sites

As a side note, I may end up connecting the transistor to a relay switch because that may work best for the motor setup. The motor, in turn, would then be connected to the relay.

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, Judd said:

Let's say I put the PWM chip at half cycle, so only on 50% of the time.  First, can the transistor start and stop this quickly?

That depends on your chosen PWM frequency. It should be fairly obvious that if you have a PWM signal with 50% duty cycle at 1Mhz your transistor is going to have to be a lot faster then if you had a PWM signal with 50% duty cycle at 1Khz.

 

Your switch (transistor) is only efficient when it is either fully off (nearly no current flowing trough it) or fully on (nearly no voltage dropping across it). During the transitions from on to off (falling edge) or off to on (rising edge) there is both a voltage drop and current flowing, thus power dissipation. For this reason one wants the rise and fall times to be limited to only a few percent of the period time. The higher the PWM frequency, the shorter each period, the lower the desired rise and fall times, the faster the transistor needs to be.

RiseFallTimes1.jpg

 

Large power transistors are typically slower then smaller lower power transistors (Typically, more power means physically larger which means more parasitics such as capacitance which means slower). That said, power BJT's can be made to switch within   microseconds and MOSFETS can be made to switch very large currents within a few tens of nanoseconds. Allowing PWM frequencies from a few Khz into the Megahertz range, respectively. 

 

The frequency to choose depends on the motor. It's inductance is employed to act as a low pass filter to smooth out the current. One typically chooses a frequency that minimizes current ripple while still being workable. As switching large currents with very short rise and fall times - high di/dt - opens up a whole new can of worms (Ringing, inductive spikes, EMI, freewheel diode recovery times, etc).

 

7 hours ago, Judd said:

If so, would the motor effectively run at half speed?

Hard to say, it depends on your motor/setup. The relationship dutycycle - motor speed need not be linear.

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

13 hours ago, Judd said:

As a side note, I may end up connecting the transistor to a relay switch because that may work best for the motor setup. The motor, in turn, would then be connected to the relay.

You may find your relay and motor burning out rather quickly this way due to the constant surges in current. 

@Unimportant gives a great explanation of pwm. 

Link to comment
Share on other sites

Link to post
Share on other sites

The average voltage being applied to the motor is what changes with duty cycle. So at 50% duty you're applying 0V half the time, and 'some volts' on the other half. The whole thing with PWM is that if you switch fast enough the fluctuations in voltage don't matter.

 

PWM is so great because of its efficiency (transistors draw very little current when fully on or fully off, but draw more when they're 'sort-of' on. PWM only operates in the former two states (except for a tiny period during the transition from 0-Vcc)), and ease of implementation without  DACs (you save on hardware and I/O!). You can also start the motor more smoothly because (janky explanation incoming) the pulses overcome the motor inertia better than a DC signal of the same average voltage would. Drawbacks include 'pitting' of the motor core over time if the motor wasn't designed for use with PWM (don't worry about that though, it was just FYI).

 

At the speeds a motor PWM signal would run at you don't need to worry about rise/fall times of the transistor. What you do need to worry about is back EMF and noise from the motor damaging the power transistor and the output of the microcontroller. So wire a reverse biased shottkey diode between collector and emmiter, another between the output of the microcontroller and ground, and some capacitors around the motor terminals. Stick a current limiting resistor in series with the microcontroller output and transistor base too.

 

You also need to wire the motor in between the collector and power rail (instead of the emitter and ground) if you want to apply the power rail voltage to the motor (less the ~0.6V drop across the transistor). If you connect to the motor between ground and emitter, you'll only be applying the 3.3V coming out of the microcontroller.

 

If you're using N-channel MOSFETS instead of NPN bipolars, the replace the following words in the above:

* Collector --> Drain

* Emitter --> Source

* Base --> Gate

 

Hope some of that was helpful.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Robi_g said:

So wire a reverse biased shottkey diode between collector and emmiter

The diode needs to be placed in parallel with the motor itself so that the inductor current can freewheel.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Unimportant said:

The diode needs to be placed in parallel with the motor itself so that the inductor current can freewheel.

You can do either, I've seen circuits with both. Across the transistor allows you to run the motor either direction (with some extra transistors etc...) if you just stuck it across the motor you could only go in one direction. In the end, all you're looking to do is protect the rest of the circuit from the motor.

Link to comment
Share on other sites

Link to post
Share on other sites

15 hours ago, Robi_g said:

You can do either,

No, you can't. Placing the diode over the transistor does not do anything at all, the diode is always reverse biased.

 

When the transistor is turned on, current flows from the power supply "+V" trough the motor, trough the transistor to ground. The diode is reverse biased as per the following image. The motor's inductance is storing energy in it's magnetic field.

Freewheel_diode_wrong.png.8cf749a1d2c5d93c068402e5ed86d687.png

 

When the transistor is turned off, the motor's inductance wants current to continue flowing in the same direction. It wants to resist changes in the amount of current flow like any other inductor. To do this it uses the energy it had stored in it's magnetic field and becomes a current source itself, theoretically generating whatever voltage required to overcome any resistance in it's path. But the current does not change direction, so the diode is still reverse biased and does nothing!

Freewheel_diode_wrong2.png.3f049370860612c445755f6ded2ca3ff.png

 

The diode needs to be placed reversed biased parallel to the motor, then when the transistor is turned off and the inductor becomes a current source the current can recirculate or freewheel trough the diode:

Freewheel_diode_right.png.e33f8f94ae166eb72018eb938338a093.png

 

15 hours ago, Robi_g said:

I've seen circuits with both. Across the transistor allows you to run the motor either direction (with some extra transistors etc...) if you just stuck it across the motor you could only go in one direction.

You're talking about a H-bridge for bi-directional motor control. There the diodes are indeed across the transistors, but that is because the diodes across the opposite transistor pair are used as freewheel path when a transistor pair is turned off.

 

15 hours ago, Robi_g said:

In the end, all you're looking to do is protect the rest of the circuit from the motor.

There's more to it then that. Freewheeling is part of the low pass filter action of the inductor. Done right, you can obtain a relatively smooth (triangle) current waveform.

 

Compare it to the diode in a asynchronous buck regulator. The diode is not just there to protect the circuit from the inductive kick. It's an integral part of the circuit and allows the inductor itself to power the load during the rectification phase of the cycle.

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, Unimportant said:

No, you can't. Placing the diode over the transistor does not do anything at all, the diode is always reverse biased.

 

There's more to it then that. Freewheeling is part of the low pass filter action of the inductor. Done right, you can obtain a relatively smooth (triangle) current waveform.

That's why I said shottkey diode across the transistor, where its lower breakdown voltage would allow current through it when reversed biased hard enough.

 

I'm aware that It's called an h-bridge, and I also know that there's 'more to it than that' (I have a Masters in Electronic Engineering and work as an electronic engineer). I was trying to reduce the amount of fluff around my answers for the OP, to save them going down the rabbit hole of learning everything about everything. It would be a bit of a baptism of fire to ask how PWM works and end up with some huge glut of jargon.

 

I'm not saying you can't do things your way, quite the opposite, I completely agree with you on that. But I'm also saying that you can stick a diode with low breakdown voltage across the transistor to protect it. The method you're pushing is probably better, as you're not injecting a load of current into the ground plane (although that's what capacitors across the supply are for I guess), but it's wrong to say that the other method just flat out won't work (unless you use a regular diode, then it won't work for the reason you stated).

Again, I have seen working circuits that use either method.

 

Also, diodes in regulators is a different use case. You can use diodes to create voltage references too, but that's got nothing to do with motors.

Link to comment
Share on other sites

Link to post
Share on other sites

22 minutes ago, Robi_g said:

That's why I said shottkey diode across the transistor, where its lower breakdown voltage would allow current through it when reversed biased hard enough.

 

I'm aware that It's called an h-bridge, and I also know that there's 'more to it than that' (I have a Masters in Electronic Engineering and work as an electronic engineer). I was trying to reduce the amount of fluff around my answers for the OP, to save them going down the rabbit hole of learning everything about everything. It would be a bit of a baptism of fire to ask how PWM works and end up with some huge glut of jargon.

 

I'm not saying you can't do things your way, quite the opposite, I completely agree with you on that. But I'm also saying that you can stick a diode with low breakdown voltage across the transistor to protect it.

Fair enough, but I'm sure you realize exploiting the diode's avalanche breakdown requires careful engineering to make sure the diode can handle the avalanche energy, etc... That's possibly an ever trickier rabbit hole :)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×