In the previous post of the series, I’ve talked about sign-magnitude drive. This article will put the other main drive-mode, the lock anti-phase drive under the microscope. Just as before, if you’re not familiar with H-bridges in general, please read the introductory part of series first.
If you came here from the discussion of the sign-magnitude drive, you’ll see that the structure of the discussion will be the same as in that article. As a matter of fact, even the chapter names line up. While that might look lazy on my part (well, it is lazy), it also serves a purpose: it makes it easy to compare the various aspects of the two main drive-modes side-by-side and clearly see the similarities and the differences.
Before we continue with the discussion, let’s quickly establish the basics. Our motor control circuit is an H-bridge, with the following configuration:
We will use a very simple motor model in most of the reasoning below. A lossy inductor in series with a voltage source:
As a matter of fact, for the most part, we will even ignore the resistance and just deal with the inductor and the voltage source.
When the bridge is driven in lock anti-phase mode, the state of the four switches (Q1…Q4) is mapped the following two possible ways to the PWM control signal:
If you look at the two alternatives, it’s easy to see that the two modes are identical when we reverse the PWM duty-cycle between the two as well. Because of that, I’ll only use mapping 3 in the following discussion.
This popular drive mode turns all four FETs of the bridge on and off in every cycle. The diagonal pairs are driven in pairs. So for example, for the first part of the cycle Q2 and Q3 are on, and for the second half, Q1 and Q4 conduct. The two sides (side-A and side-B) are always driven in opposite ways, they’re in ‘anti-phase’ from one another. That’s where the name of the operating mode comes from.
In this configuration, if the two diagonal pairs are on for the same amount of time – in other words the bridge is driven at 50% duty-cycle – the average voltage on both terminals is Vbat/2, and the average voltage across the motor is 0:
This is the idle condition, since the motor doesn’t see an (average) voltage difference across it’s terminals. If the duty cycle is increased, Q1 and Q4 will be on longer than Q2 and Q3 are. The average voltage on the ‘B’-side of the motor will be higher than on the ‘A’ side, so it will start spinning in the forward direction:
Conversely, if the duty cycle is decreased below 50%, the ‘A-side’ sill see a higher average voltage than ‘B’, so the motor will turn in the reverse direction.
The average voltage on the motor terminals is:
Vmot_avg = Vbat*(ton-toff)/(tcycle)
Now let’s examine the current flow in the bridge. The image below assumes the motor is turning in the forward direction, in other words Vg is positive. For now, let’s also ignore the voltage drop on the internal resistance of the motor.
During the ‘on-time’ the motor sees a voltage difference of Vbat-Vg in its inductor (remember, the motor acts as a inductor in series with a voltage source). This voltage will induce a linearly increasing current on the inductors (dI/dt = V/Lm). The current flows in the circuit following the red arrow above. The rate of increase will be proportional to the voltage, and inversely proportional to the inductance of the motor windings. If the motor runs fast, the voltage difference between Vbat and Vg is small, so the current increases slowly. If the motor is stalled, or rotates slowly, Vg is close to 0, so the current rises rapidly. If the motor is turning in the other direction in which the drive would like to turn it, the current increase is even faster. The fastest current increase is expected when the motor is turning full-speed in one direction and the driver is abruptly switched to full-speed in the other direction.
During the off-time the voltage on the motor windings is -Vbat-Vg, usually a higher absolute value than for the on-time, and in the reverse direction. This voltage starts collapsing the inductive field in the inductors in the same linear fashion as it was built up during the on-time. The current flows along the blue arrow on the diagram above. You can see that while the motor-current flows through the bridge in the opposite direction as in the on-time, it’s direction through the motor remained the same. (It’s also possible that both during the on- or the off-time the current crosses 0 and actually changes direction. When I’ve drawn the arrows above, I just assumed that was not the case.)
When the whole system is in a steady state – the motor doesn’t accelerates nor decelerates – the average current through it should be constant as there’s no change in torque. So the current change during the on-time (the peak-to-peak or ripple-current) should be equal to the change in the off-time. In other words:
Iripple = (Vbat-Vg)/Lm*ton = (Vbat+Vg)/Lm*toff
Solving it for Vg we get:
Vg = Vbat * (ton-toff)/(ton+toff) = Vmot_avg
Now, if we take this expression of Vg back to the previous equation, we get:
Iripple = 2*Vbat/Lm/tcycle*(tcycle-ton)*ton
This is a parabola over ton, and it reaches it’s maximum when ton is tcycle/2, in other words, when the duty cycle is at 50%. The maximum ripple-current over the motor is:
Iripple_max = 1/2*Vbat/L*tcycle
The fact the Vg is equal to Vmot_avg says that – in a steady state – the generator voltage is equal to the average voltage on the motor terminals. The average current will be whatever it needs to be to make this happen. Now, remember that the generator voltage is proportional to the rotational speed of the motor, and the current is proportional to the torque. So the above statement means that the motor will rotate at a constant speed, proportional to the average voltage on the motor terminals and it will exert as much torque as it needs to to make it happen. We have also seen that the average voltage is set by the duty-cycle of the drive (it’s deviation from the mid-point). So it seems as if we implemented perfect speed-control: the speed of the motor only depends on the PWM input signal.
This is of course not true in real life, and you only have to go back to the initial assumptions to see why: we assumed that the motor has no internal resistance. Once you take the internal resistance into account, this nice relationship breaks, as the current will create a voltage drop across that resistance. This voltage drop will reduce the voltage that the inductors see and introduces a torque-dependent difference between intended and actual motor speed. The inductor voltage will be:
VL_on = Vbat – Vg – Imot_avg*Rm during the on-time
VL_off = -Vbat – Vg – Imot_avg*Rm during the off-time.
These voltages will induce a linear current-change on the inductor (here I’ll assume that the current doesn’t change too much so the voltage drop on the internal resistor can be assumed to be constant), but – being in a steady-state – the current changes still chancel each other out:
VL_on/Lm * ton – VL_off/Lm * toff = 0
If you substitute the two voltages from above and express Vg, you get:
Vg = Vbat * (ton-toff)/(ton+toff) – Imot_avg*Rm
and after some simplification:
Vg = Vmot_avg – Imot_avg*Rm
Remember that in our discussion about the current flow, during the ‘on-time’ the current flows into the bridge, while during the ‘off-time’ if flows out of the it. (The current flow doesn’t abruptly change direction on the motor, being an inductive load, but the bridge configuration changes, directing the load in the reverse direction.)
Most supplies can’t deal with this quick reversal of current, and if the reverse-current can’t find its way back to the power supply, the supply voltage will start rising potentially to dangerous levels. To handle this reverse current properly a capacitor needs to be put on the input terminals of the bridge to temporarily soak up the current coming from the bridge. The capacitor will release it’s extra charge back into the motor in the next on-cycle:
To calculate the size of this capacitor, you’ll have to take a few things into consideration:
- How much reverse-current can the supply handle?
- How much voltage-hike can the circuit tolerate?
- What is the switching frequency of the bridge?
Some of these parameters depend on the operating conditions of the bridge, so let’s make the worst-case assumption that the supply can’t tolerate any reverse-current.
Next, let’s have a look at what the current looks like from the supplies perspective. Even though the motor current has a nice triangle-wave shape, the supply current ‘jumps’ around because of the way the switches conduct in the bridge:
Some if this current flows though the supply, but some flows through the capacitor (they’re in parallel, so they divide the current amongst themselves):
We also know that the capacitor should end up with the same amount of charge at the end of the cycle as what it started with, otherwise it’s cycle-to-cycle voltage would not stay constant. (Remember, we’re still discussing steady-state conditions where nothing changes from cycle to cycle). This means that the average part of this supply current must flow through the supply and only the rest, the ripple current part would go though the capacitor. So, let’s calculate this average current first!
The average current during the on-time is:
Ibat_avg_on = (Imax+Imin)/2
while the off-time average current is:
Ibat_avg_off = (-Imax-Imin)/2
The on-time current flows for ton/tcycle fraction of the time, while the off-time current flows for toff/tcycle. The total average current through the supply is then:
Ibat_avg = Ibat_avg_on*ton/tcycle + Ibat_avg_off*toff/tcycle
Doing the substitutions and after some re-arranging we get:
Ibat_avg = 1/2 * (Imax+Imin) * (ton-toff) / tcycle
You can also realize that 1/2 * (Imax + Imin) is nothing but the average current through the motor, Imot_avg. Doing this final substitution, gets us the following:
Ibat_avg = Imot_avg * (ton-toff) / tcycle
This is a nice equation, that’s easy to understand: because of the switching of the bridge, the average motor current flows in to it for the duration of the on-time (ton) and out of it during the off-time (toff). The average supply current thus must be the weighted average by ton and -toff.
Now that we know the average current that must flow through the battery, we know the rest – the ripple current – that must be going in- and out-of the capacitor as well. This current charges up or down the capacitor depending on it’s polarity. The capacitor takes charge in during the off-time, and off-loads it during the on-time. The total charge going in to the capacitor is the following:
Qoff = (Ibat_avg + Imax + Ibat_avg + Imin)/2*toff
The total amount of charge released during the on-time is:
Qon = (Ibat_avg – Imax + Ibat_avg – Imin)/2*ton
Substituting the above formula for Ibat_avg we get the following equations after some simplifications:
Qoff = (Imax + Imin) * (ton*toff/tcycle)
Qon = – (Imax + Imin) * (ton*toff/tcycle)
As you can see, the two in fact are the same absolute value, but opposite polarity, which means that the capacitor in deed ends the cycle with the same charge it started it with. We also know that Imax+Imin is twice the average motor current (Imot_avg), and toff = tcycle-ton. Putting these into the first equation we get:
Qoff = 2*Imot_avg * (ton*(tcycle-ton)/tcycle)
The voltage change on the capacitor due to the charge-up during the off-time is the ripple voltage, and we can calculate it like this:
Vripple = Qoff/C = 2*Imot_avg * (ton*(tcycle-ton)/tcycle) / C
So, what is the worst-case ripple voltage? The above equation is a parabola over ton and reaches its maximum when ton = tcycle/2, in other words at 50% duty-cycle. The ripple voltage in that case is:
Vripple_max = 1/2 * Imot_avg * tcycle / C
And from this, the required capacitor value:
C = 1/2 * Imot_avg / Vbat_ripple * tcycle
Just how large this value can be? To figure that out, we need to know the maximum average motor current. There are two ways about that.
- We can be extra conservative, and take the stall-current from the motor data-sheet. That however is not realistic: the motor usually can’t sustain that current and would overheat. And remember, we are still talking about steady-state conditions, ones that the system can continuously operate in.
- A better – and still quite conservative – approach is to take the maximum rated current of the bridge.
We also have to come up with a reasonable ripple-voltage value. 5% of the supply voltage would not be too esoteric to assume, but of course it depends on the demands of the supply and the system in general.
So, to put numbers in the equations, let’s assume, we’re designing a 20A max. current bridge, that can operate up to 24V. We allow for 5% ripple voltage (Vbat_rippple = 1.2V). If we operate the bridge at a 20kHz switching frequency, we get a capacitor value of 208µF. That’s not too bad, however if we design a much higher current bridge, operating at a much lower frequency for example, numbers get out hand quickly: a 100A bridge operating at 1kHz would need a bigger than 20000µF capacitor.
Whenever Vg is not equal to Vmot_avg, that is when the motor is turning faster or slower than we intend it to do, the bridge is not in a steady-state, it effectively is accelerating or braking.
The energy pumped into the motor inductors during the on-time is not the same as what is removed during the off-time. The changes of the current during the on-time and the off-time don’t cancel each other out, and the average current is changing from cycle-to-cycle:
Let’s express the various quantities on this drawing! The current change during the on- and off-time is the same as for the steady-state, the only difference is that they don’t cancel each other out:
Idelta_on = (Vbat-Vg)/Lm*ton
Idelta_off = (Vbat+Vg)/Lm*toff
And from that:
Idelta_cycle = Idelta_on – Idelta_off = (Vbat-Vg)/Lm*ton – (Vbat+Vg)/Lm*toff
After some re-arranging and expressing Vbat from Vmot_avg, we get:
Idelta_cycle = (Vmot_avg-Vg)/Lm*tcycle
What it means is that the current changes linearly from cycle-to-cycle proportional to the difference between the intended and the actual speed of the motor.
In this simple model, where we disregard the motor resistance, it seems that the motor current would change forever, unless Vg becomes eventually equal to Vmot_avg. And that is in deed what happens: if you think about what the mechanical equivalents are, you’ll see that as the current changes, so does the motor torque. That change in torque would eventually in fact have an effect on the rotational speed, which in turn is related to Vg. The change will be in the way to make Vg closed to Vmot_avg. Once that happens, the current change would slow down. The process finishes when Vg becomes equal to Vmot_avg, and the average motor current (and torque) settles to the new value needed to keep the balance between the generator voltage and the average motor voltage.
For acceleration this is more or less the end of the story, but for braking we have more to discuss.
When Vg is higher than Vmot_avg, that is, the intended motor speed is lower than the actual, the motor would have to slow down to get back into a balanced steady-state condition. In other words, the motor is braking at that point.
As we’ve seen above, during braking the motor current keeps getting lower from cycle to cycle, and since the mechanical time-constants are usually several order of magnitude lower than the electrical ones, the current pretty soon turns negative (more precisely opposite to Vg):
As that happens, the motor is operated in its generator mode and is essentially converting mechanical energy to electrical. Let’s figure out how big this braking current could be, but for that we’ll have to re-introduce the motor resistance into our model – we’ve seen before that without that the motor current would change indefinitely. With the resistor in place however, the motor current will drop some voltage on this resistance, pretty soon balancing out the difference between Vmot_avg and Vg, so the current-change stops. Once that happens, we can again use our steady-state equations to figure out the current:
Vg = Vmot_avg – Imot_avg*Rm
And from this:
Imot_avg = (Vmot_avg-Vg)/Rm
When we’re braking, Vg is higher than Vmot_avg, so the current is in deed negative (opposing Vg). This also means that the torque applied by the motor is opposing the motion of its shaft, so we’re in fact braking.
We also know form the previous chapter on the input capacitor that the average supply current flows through the battery (or power supply). Depending on whether this current opposes the supply voltage or not, we either charge or discharge our battery. From that chapter we even know the equation for that current:
Ibat_avg = Imot_avg * (ton-toff) / tcycle
Doing the proper substitution for Imot_avg, we get:
Ibat_avg = (Vmot_avg-Vg) * (ton-toff)/tcycle * 1/Rm
What’s interesting about this equation is that while Vmot_avg-Vg is always negative, since we’re braking, the current isn’t necessarily. If ton is greater than toff, in other words the bridge is operated in the forward direction, the current flows back into the battery. This condition is called regenerative braking. However, if ton is less than toff – the bridge is operated in the reverse direction – the battery current becomes positive and flows out of the battery, into the bridge. This situation is called dynamic braking.
To understand this equation a little better, let’s express Vmot_avg from Vbat and put it in the average current equation. We get:
Ibat_avg = (Vbat*(ton-toff)/tcycle -Vg) * (ton-toff)/tcycle * 1/Rm
Now, we know that toff = tcycle-ton, so using that, and rearranging the result a little bit, we get:
Ibat_avg = 1/Rm * [ (ton/tcycle)2 * (4*Vbat) - (ton/tcycle) * (4*Vbat + 2*Vg) + Vbat + Vg ]
It might be a little hard to see first, but it’s essentially a parabola over the duty cycle (ton/tcycle). It has two zero-s. One at 50% duty cycle, and one where Vmot_avg is equal to Vg. In other words, where:
ton/tcycle = 1/2
ton/tcycle = 1/2 * (Vg/Vbat + 1)
Let’s graph this battery current! In the following graph I’ve used 1V battery voltage, 0.8V Vg, and 1Ω for Rm to normalize the picture somewhat. I’ve plotted the average battery current (blue) and the average motor current (brown) over 0-100% duty cycle:
You can play around with the curve yourselves as well.
You can see that the motor current and the battery current are in opposite direction throughout the first part of the diagram, until you hit the first zero, the 50% mark. This is the area of dynamic braking: the motor current is negative (we’re braking) but the battery current is positive, so we’re discharging the battery.
Between the two zeros, both the motor and the battery current is negative, so while you’re braking the motor, you’re also charging the battery. This is the land of regenerative braking.
Once you pass the second zero, both the motor current and the battery current turns positive. Now, you’re accelerating, since Vbat_avg is higher than Vg. The positive motor current also means we’re accelerating the shaft, while obviously we’re discharging the battery as the positive battery current shows.
Regenerative braking can be good or bad depending on whether you can take advantage of it. The problem is, just as with the off-time current, that you have to put the converted energy somewhere. This energy however can be much larger (more or less un-bound) than the one that is coming from the inductive field in every cycle.
There’s no capacitor big enough to handle that much of energy so another repository needs to be found.
If your system is battery operated, the battery may or may not absorb this energy, depending on battery technology, and more importantly its charge level. A fully charged battery can’t take any more charge. To avoid overcharging (and potentially exploding) your battery, you’ll have to monitor the charge-rate of your battery and control your braking capability. You might be limited in how much brake power you can apply by the state of your battery, which is not a pleasant thought.
If you run your system from mains (and necessarily through a power supply, since mains is AC and we’re driving a DC motor here), you’re even more limited: unless you specially design your power supply, it simply can’t pump energy back into the power outlet.
In both cases it seems that your safest bet is to consume or store the regenerated energy locally. If you have other loads consuming power, of course you can power those loads up to their current requirements. You might have lights, computers, other motors, heaters, sensors what not running at the same time, that need energy. All that is great, but you don’t want your brake distance depend on how much the seat-wormer is on in your car, do you? In other words, all these options provide some, but very deterministic and unreliable place to put energy.
What you would really need is some sort of reliable energy storage device that is not as sensitive as a battery and can store a lot of energy. Effectively a large capacitor. While actual capacitors of these sizes (easily several Farads) are not feasible, there is another way (you would have to read more on mechanical modeling to understand why): stick another motor with a big wheel attached to it into your system. When you have more energy then what you know what to do with, simply spin-up the wheel to store the energy. When you are in need of energy, use (again) regenerative braking on that wheel to regain the energy and supply your needs. This is called a flywheel, and is in fact used in certain systems.
Trains, subways and other large, but well controlled systems usually benefit from regenerative braking as well as they quite often have another consumer (another, accelerating train) that can use the regenerated energy.
All these problems aside, let’s say you can in fact store or in some other way use the energy coming back from the motor.
Are we golden?
Unfortunately far from it. First, as you can see in the curves above, regeneration only happens when Vbat_avg is the same polarity (but lower than) Vg. As soon as Vbat_avg reverses polarity, we enter the dynamic braking domain. If you look at the motor current, you’ll see that this region corresponds to a relatively small (absolute) current value, consequently a relatively low braking torque. What is even more troubling though is that as braking becomes effective and Vg start decreasing, at constant Vbat_avg, so does the braking torque. This means that you can’t apply a constant braking torque down to 0 without entering the dynamic braking domain.For constant braking torque, you have to maintain a constant difference between Vbat_avg and Vg.
The other problem is this: as we’ve seen above the domain of regenerative braking is between 50% duty cycle and the point where Vbat_avg reaches Vg. Since we’re talking about a parabola, the current minimum (maximum absolute value) happens in the middle point between these two extremes, in other words, when Vbat_avg = Vg/2. At that point the average motor current is
Imot_avg = (Vg/2-Vg)/Rm = 1/2 * Vg * 1//Rm
while the average battery current is:
Ibat_avg = 1/4 * Vg2/Vbat * 1/Rm
So if you want to maintain good regeneration efficiency, you’ll have to further limit your braking torque to half of what it could be (still using regeneration).
In summary, you can only use regeneration for relatively light braking and even than you’ll have to choose between high braking torque and high recharging current.
Dynamic braking isn’t much easier to do either. In order to be in the dynamic braking domain, you’ll first have to ensure that you’re Vbat_avg is opposing Vg. For that, you’ll have to somehow measure the generator voltage, or something related to it, like the shaft speed. Neither of them are necessarily simple to do, but I’ll come back to techniques when we’ll discuss closed-loop control of a DC motor. You could opt for measuring the (average) battery current and make sure it never turns negative as well.
However, even if you did do all that, in order to be able brake in the dynamic braking domain effectively, you’ll first have to figure you that you in fact need to brake! That again involves measuring Vg and comparing it to the intended speed. Essentially implementing a closed-loop speed-control system.
If you do these things, you’ll risk reversing the motor rotation and instead of braking, start accelerating in the reverse direction.
The other problem is in some way the opposite of regenerative braking. There the problem was that you can’t brake too abruptly. Here, you can’t apply a gentle enough braking torque. If you look at the chart again, you’ll see that by the time you reversed Vbat_avg, the average motor current is pretty large. You can’t make it any smaller because that would require you to cross over to the regenerative domain. Your braking torque is also a function of the generator voltage (speed). The lower the speed, the lower this minimum torque is: at high speed you will only be able to apply abrupt braking – at least with dynamic braking.
Lock anti-phase drive seems simple at first: a single PWM signal drives all four switches, and provides full control over the bridge. As we’ve seen however the simple PWM control signal is almost never enough, as some means of releasing the regenerated energy needs to be provided. This includes some monitoring circuit that identifies the cases when that’s needed and some ways for that monitor to carry out actions.
The good news is that you can always set the PWM cycle to 50%, at which point the motor will safely brake to (almost) a halt without a risk of over-charging your battery or raising the supply voltage to dangerous levels. The bad news is that In that mode you have no control over how long it will take the motor to stop, so while electrically this might sound a safe choice, the mechanical side might tell a different story. On top of that, if there’s external torque applied to the motor, simply centering the PWM drive will not stop it. (You will not be able to stop a car down-hill like that.)
And now, that we’re on the topic of safety, there’s another problem with this mode: the idle state is not static. In other words, if something goes wrong (or more likely, during startup) and the control signal stops switching, the motor will start accelerating very fast in one direction or another. This is a serious problem for example for systems where the PWM signal is generated by a micro-controller, as it has to make sure that during power-up the PWM signal is available and valid almost immediately. If that’s not possible, another ‘enable’ control signals needs to be provided that disables the bridge until the control signal is running.
Lock anti-phase drive seems simple at first site, but if you look into it in more detail, it quickly turns out to be a complex beast with many nasty problems. It can be effective, but you’ll have to understand its limitations.
Where to go from here?
It might seem that we’ve exhausted the drive modes available to us. However, there’s a problem: both the sign-magnitude drive and the lock anti-phase drive suffers from regenerative braking that is at least a serious design complication.
In the next chapter we will discuss if there’s anything we can do about it: is there a way to drive an H-Bridge in a way that doesn’t ever experience regenerative braking?