In this article I’ll talk about one of the popular drive-modes of H-bridges, the Sign-magnitude drive in detail. If you’re not familiar with H-bridges in general, I suggest you read the previous part of the series first, where we’ve looked at the basic operating principles of an H-bridge and went through the various meaningful operating modes.
In sign-magnitude drive, we have four control modes to choose from:
These modes describe the way we map the states of the four switches to the ‘on-time’ and the ‘off-time’ of our PWM control signal. If you carefully investigate these tables, you’ll see that the four options describe the four possibilities for two binary choices: whether to keep the a-side or the b-side in a constant state, and whether to keep the low-side or the high-side switch closed continuously.
You will see pretty soon that one of these binary choices is usually made statically, while a control signal is used to decide between the remaining two choices.
However, for now, let’s just concentrate on mapping 1 and see, how the bridge operates! As the mapping tells us, during the on-time, Q1 and Q4 are closed. This means that the left-side of the motor is connected to Vbat, while the right-side is grounded. Current can flow from the supply through the motor:
When the off-time comes along, Q1 stays closed, but Q4 opens and Q3 closes instead. In this state, there’s no path from the supply to ground through the bridge. However, both of the motor terminals are connected to Vbat, basically short-circuiting the motor. If there was current flowing through the motor at the time the switch-over happened, that current can continue circulating around the in that loop:
The voltages and the current through the bridge will follow the following wave-forms:
The average voltage the motor sees can be calculated as the following:
Vmot_avg = Vbat * ton/tcycle, where tcycle is the cycle time, and ton + toff = tcycle
From this equation something should be immediately obvious: this mapping can’t move the motor backwards. For that we would need to be able to apply a negative (average) voltage to the motor terminals, but that’s not possible: the motor voltage can only be adjusted between 0 and Vbat. That would be a problem, but if we do the same math for mapping 5, we’ll see that in that mode, the opposite is true: that mode can only turn the motor in the reverse direction and the average motor voltage can only be between 0 and -Vbat.
In order to make a functional H-bridge, we need to employ both of these mappings and introduce a control signal that can choose between the two. This is the origin of the name of the drive mode: one control signal – the one that chooses between the two mappings – is used to determine the ‘sign’ of the voltage applied to the motor, while the other – the PWM signal – is used to determine the ‘magnitude’ of that (average) voltage.
The remaining two mappings are only slightly different from the previous two: the difference is that, during the off-time, instead of the two high-side switches, the two low-side ones are turned on. This means that the motor terminals are both connected to ground instead of the battery, but they are still shorted together and the motor current still circulates inside the bridge during the off-time:
Let’s take a closer look now at the way the current flows in the system! During the ‘on-time’ the motor inductors see a voltage difference of Vbat-Vg (provided the motor rotates in the same direction, the bridge tries to rotate it). If we disregard the internal resistance of the motor for a minute (or assume that the switching frequency is much higher than the electrical resonance frequency of the motor) this voltage will create a linear current ramp on the inductor (dI/dt = V/Lm). Since we assume Vbat is constant, the slope of the current increase will be determined by Vg, or in other words by the speed of the motor.
When the motor runs under no load Vg is very close to Vbat, so the current will change very slowly. If the motor is stalled, the current will rise much faster, as Vg is 0. The fastest current rise will happen if we abruptly change the drive direction from full-speed one way to full-speed the other way. In that case Vg will be close to Vbat in absolute value, but reversed in polarity.
During the off-time, the motor is short-circuited. If we disregard the internal resistance of the switches and the motor, the current can flow without interruption, and the inductors see Vg between their terminals. The current will start decreasing linearly, determined by the generator voltage and the motor inductor.
We say the bridge operates in a steady state if the cycle-to-cycle averages if the various parameters (voltages, currents) remain constant. The motor doesn’t accelerate nor decelerates and outputs a constant torque.
If things don’t change from cycle-to-cycle, it means that the motor current at the beginning of a cycle must be the same as at the end. Of course this doesn’t mean that the current stays constant during the cycle and this current-change is called ripple-current. Assuming linear current change during both the on- and the off time, the current deltas are the following:
Iripple = (Vbat-Vg)/Lm*ton = Vg/Lm*toff
If we express Vg from this, we get:
Vg = Vbat* ton/(ton+toff) = Vbat * ton/tcycle = Vmot_avg
What we get is this: in a steady-state, the generator voltage must be equal to the average voltage the motor sees. The average current will be whatever it needs to be to reach that condition. Now, if we put this Vg back to the current equation, we get this:
Iripple = Vbat / Lm / tcycle * ton*toff
and since toff = tcycle-ton:
Iripple = Vbat / Lm / tcycle * ton*(tcycle-ton)
This is a second-order function (a parabola) with its maximum at ton = tcycle/2. So the ripple current reaches its maximum at 50% duty cycle, and its value is:
Iripple_max = Vbat / Lm * tcycle/4
If you recall, the generator voltage is proportional to speed and current is proportional to torque. From the previous chapter it seems as though we have perfect speed control: the speed which is proportional to the generator voltage is equal to the average voltage seen by the motor, which in turn only depends on the duty cycle of the PWM input, our control signal. The torque (current) on the motor will be whatever it has to be to make that happen.
There’s something wrong with that picture isn’t here? After all we know that DC motors don’t keep a constant speed under load changes without any control circuit. True, and it’s easy to see what the problem is: we disregarded the internal resistance of the motor (and the switches).
Once you take those into account, you’ll see, that the motor current drops some voltage on those resistors, and the inductor sees only the remainder. (In the following equation I’ve made the simplification to assume that the motor current doesn’t change much, so the voltage drop on the resistor is relatively constant during the on- and off-times.)
VL_on = Vbat – Vg – Imot_avg*Rm during the on-time and
VL_off = -Vg – Imot_avg*Rm during the off-time.
If you put this into our previous ripple-current equation, you’ll see the result is a current- (or torque-) dependent difference between our intended speed and the actual speed of the motor:
Vg = Vbat * ton/tcycle – Imot_avg*Rm = Vmot_avg – Imot_avg*R
In the previous chapter we calculated the ripple current, but we kept saying that the average motor current (in the ideal case at least) will settle at whatever level it needs to to make Vg equal to Vmot_avg. This statement has an interesting consequence: we can’t predict the direction the current will flow during the on-time and the off-time. In fact, if Imot_avg is lower than half of Iripple, the motor current changes direction twice during the cycle:
Now, one of those direction changes happen during the off-time, when the motor is short-circuited, but the other happens when the motor is connected to the supply. What follows is that at the beginning of every on-time for a short while at least, the current flows out of the bridge. Most supplies can’t deal with this quick reversal of current flow 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 we need to put a capacitor 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 part of the cycle when the current flows to the ‘proper’ direction:
But just how big this capacitor needs to be? Well, that depends on a lot of things, so let’s list them:
- How much reverse-current can the power supply handle?
- How much voltage-hike can the circuit live with?
- What are the motor characteristics (mostly inductance)?
- What is the switching frequency and duty cycle of the bridge?
- How much torque the motor needs to output (the average current through the motor)?
Since some of these parameters are dependent on the operating conditions and the exact application, let’s first do some simplifications and assume worst-case conditions:
- Let’s assume the power supply can’t take any reverse current
- Let’s also assume that Imot_avg is 0, so the current changes direction exactly at half of the on-time. (The capacitor can’t be sized for the condition when even Imot_avg is reverse compared Vmot_avg, since in that case the capacitor can’t completely release its extra charge during the cycle. We will discuss that situation later).
- Finally let’s assume that the ripple current is at its maximum, so the duty cycle is at 50%
Under those conditions, the current will rise for 50% of the time, and cross 0 at 25% of the total cycle time:
The total charge released back to the system during the first-half of the on-time is:
Qrelease = 1/2*((Iripple_max/2)*ton/2)
We also know that
ton = tcycle/2
Finally we know our ripple current is at its maximum:
Iripple_max = Vbat / Lm * tcycle/4
Putting these together and do some simplifications, we get:
Qrelease = 1/64 * Vbat / Lm * tcycle2
If we assume that the power supply can’t take any of this charge as we’ve said before – in other words all of it needs to be stored in the capacitor – the capacitor voltage will rise:
Vbat_ripple = Qrelease/C
So if we know how much change in the supply voltage we can tolerate, we get a capacitor value:
C = Qrelease/Vmax_bat_ripple
Substituting Qrelease we get:
C = 1/64 * Vbat/Vmax_bat_ripple / Lm * tcycle2
Note that the term Vbat/Vmax_bat_ripple is the ratio between the supply voltage and the ripple voltage allowed on the it. If for example we allow for 5% ripple, this value is a constant 20 independent of the supply level. Also note that the capacitance value needed increases quadratically with the cycle time.
I’ve measured a few motors, and the lowest inductance value I’ve seen was in the order of 30µH, but of course this value varies a lot from motor to motor. So, to give you actual numbers, let’s take that 30µH inductance value, allow for a 5% ripple on the power supply and a 20kHz switching frequency. With that, we get a minimum ~26µF of capacitance needed on the power supply. If we only want to switch at – let’s say – 1kHz though, the capacitance needed is more than 10000µF!
Whenever Vg is not equal to Vmot_avg, the bridge is not in steady-state. When it is lower, the motor is accelerating, when it is higher, it is braking. We’ve seen above that the on-time current change is:
Idelta_on = (Vbat-Vg)/Lm*ton
while the off-time current change is:
Idelta_off = Vg/Lm*toff
Let’s express Vbat from Vmot_avg and put that into the first equation! We get:
Idelta_on = (Vmot_avg-Vg)/Lm*ton + Vmot_avg/Lm*toff
Next, let’s see what the difference between the current at the beginning of the on-time and the end of the off-time:
Idelta_cycle = Idelta_on – Idelta_off = (Vmot_avg-Vg)/Lm*ton + Vmot_avg/Lm*toff – Vg/Lm*toff
After some re-arranging:
Idelta_cycle = (Vmot_avg-Vg)/Lm*tcycle
In other words, the motor current changes from cycle to cycle proportionally to the difference between the intended generator voltage (Vmot_avg) and the actual generator voltage (Vg).
Since current is proportional to torque, this means that if there’s a difference between the two voltages, the torque will start changing linearly. In this simple model, the current would keep changing forever, but in reality that of course isn’t the case. For one, internal losses limit the maximum current as we’ll see in a minute, but eventually, the changed torque would hopefully change the motor speed as well, bringing it closer to Vmot_avg, slowing down the current change. Eventually a new steady-state is reached where Vg is equal to Vmot_avg and the torque changed to a new value that is needed in order to maintain that balance. (If you read the article on motor modeling, you’ll see that in many cases the motor and the attached mechanical system can be modeled as a large capacitor and some sort of loss. That capacitor, with the internal internal resistance of the motor determines the time-constant by which this new steady-state is reached, and the actual response will be closer to an exponential curve.)
Now, this is all fine for acceleration, but there’s something strange that happens during braking. When Vg is higher than Vmot_avg, the torque (current) will start decreasing. As the electrical time-constants are usually several orders of magnitude lower than the mechanical ones (again, see the article on motor modeling for the details), the current (and the torque) turns the opposite direction to the shaft rotation (generator voltage).
Let’s see how big this reverse current can be, but in order to do so, we’ll first have to re-introduce the motor resistance into our model. The reason is that without the resistor, the motor current will just keep decreasing (or increasing in the negative direction) until the generator voltage changes and becomes equal to Vmot_avg. In other words, without the resistor, the motor current can be an arbitrarily large negative number. With the resistor in place however, the bridge will quickly settle to a constant cycle-to-cycle current, as the voltage drop on the resistor will put an end to the current-increase over the inductor.
Once that happens, we can use our steady-state equations, to figure out the average current:
Vg = Vmot_avg – Imot_avg*Rm
and solving that to the current, we get:
Imot_avg = (Vmot_avg-Vg)/Rm
The reason the system can be in steady-state, while Vg is not equal to Vmot_avg is the internal motor resistance. What happens is that the internal resistance of the motor makes the cycle-to-cycle current change zero, which was the initial assumption in deriving the steady-state equations.
You can also see, that the average motor current is negative, as expected. It means that the torque is in opposite direction to the shaft rotation, so we are in fact braking the motor.
During the off-time this current is circulating through the motor and either the two low- or the two high-side FETs. However, during the on-time, the only way for the current to flow is through the supply. While the current through the motor is always in the ‘negative direction’ – more precisely opposing the generator voltage – the same current flows into the supply in the positive or negative direction, depending on which way the FETs are open during the on-time:
This current either charges the battery (first case), which is called regenerative braking or dis-charges it (second case), which is called dynamic braking.
While one would think that re-charging the battery is a good thing, there are two serious limitations to the effectiveness of regenerative braking:
- As we’ve seen, the average current during braking depends on the difference between Vmot_avg and Vg, and reaches its maximum when Vmot_avg = -Vbat. However, re-charging only happens if the current flow goes against the battery voltage, so we can’t operate the bridge in the reverse direction. This limits the amount of torque that’s available during regenerative braking. If more torque is needed, the bridge needs to operate in the non-regenerative (dynamic braking) domain. The regenerative braking torque will also decrease as the speed (Vg) decreases: it’s not possible to provide a constant deceleration down to 0 using regenerative braking alone.
- Even though the motor braking current gets greater, as Vmot_avg gets further away from Vg, that doesn’t mean that all that current will re-charge the battery: only during the on-time does the current flow through the battery. As you decrease Vmot_avg to increase the braking current, tonwill decrease as well and the re-charging effect will decrease with it. To be more precise, the amount of energy transferred in each cycle to the battery is the following:Ere-charge = Vbat * Imot_avg * tonwhich becomes this after doing the proper substitutions for Imot_avg and Vmot_avg:Ere-charge = Vbat/Rm*(Vbat*ton/tcycle-Vg)*tonAs you can see this is a quadratic function of ton, and it reaches its maximum whenton = 1/2 * Vg/Vbat * tcyclein other words when the Vmot_avg is half of Vg. This effect will further limit your ability to regenerate energy from the motor while braking, or your ability to quickly brake the motor while maintaining good re-generation efficiency, depending on which way you look at it.
Even if you’re fine with all the limitations above, the question still remains: what to do with the back-converted energy? If your system is battery operated, the battery may or may not absorb this energy, depending on its technology. Even more serious problem is that the amount of charge a battery can take depends on its charge level – a fully charged battery can’t take any more charge. This means that you either risk overcharging your battery or limit your braking capability at least under some circumstances. Neither options are too pleasing.
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 the 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 not very deterministic or reliable places to put energy to. 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 capacitor. Trouble is, actual capacitors of the sizes needed (easily several Farads) are not feasible. There is however 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.
As you can probably see from this much, the problem of safely and reliably putting the braking energy somewhere is a complex one. It requires full understanding of the complete electro-mechanical system, and there is no one-size fits all solution.
Let’s say you don’t want to use regenerative braking because of all the complexities involved. So you want to operate in the dynamic braking mode of the bridge, and avoid regenerative braking altogether. How do you do that? The first thing you need to do is to figure out if the system is in regenerative braking mode. You can go about it in two ways:
- We know the bridge is in regenerative mode if Vg is higher than Vmot_avg but the same polarity. To use this, we need to measure Vg or something related to it. That’s not necessarily a simple thing to do. I will come back to techniques for doing so in a future article about speed-control mechanisms, but usually you will need a method to measure the shaft speed using an encoder for example.
- Use the knowledge that the bridge is in regenerative mode if the bridge current flows in reverse direction compared to the battery voltage. This involves measuring the current through the bridge including it’s polarity.
After you have the right feedback in place, you can adjust your drive direction to make sure that Vmot_avg is always reverse in polarity than Vg any time you’re braking. But there’s another complication: how do you know you need to brake? You only know that if you know the intended and the actual speed of the motor, so you need to measure the shaft-speed (or Vg somehow) and you have to implement some sort of a control circuit.
If you did all that, you can successfully avoid regenerative braking. Then another problem arises: how much torque can you apply in braking mode to the shaft, provided you would only want to operate in the dynamic braking domain? We know that torque is related to the motor current and we’ve also seen that the average motor current during braking is the following:
Imot_avg = (Vmot_avg-Vg)/Rm
To make sure that the motor remains in the dynamic braking domain, you will have to make sure that Vmot_avg has the same polarity as the motor current, which is opposite to Vg. So if Vg is positive as in all of our examples so far, Vmot_avg will need to be negative. That has the unfortunate consequence that Imot_avg cannot be smaller (in absolute value) than a certain amount:
abs(Imot_avg) >= Vg/Rm
This is a problem because it tells us that we can’t brake the motor arbitrarily gently. The only way to achieve that is with regenerative braking. As a matter of fact, it also tells us that he minimum amount of braking torque we can apply to the motor depends on the speed and is proportional to it. So at high speeds we will have more abrupt braking than at low speeds.
By now you probably see that dealing with bridges in phase-magnitude drive is not simple. At first sight it seems you only need two control signals – a PWM input to set the average voltage on the motor and a digital signal to set the direction – and you’re ready to go.
Detailed analysis however shows that no matter how you operate your bridge, braking is a problem. You either use regenerative braking with all of its complications or try to avoid it which isn’t simple either. You probably need to monitor the bridge current and the supply voltage to make sure you you don’t over-charge your battery. If you want to avoid regenerative braking completely you’ll most likely have to somehow measure the motor speed as well.
The silver lining is that at least you have a fail-safe mode to go back to: you can always set the PWM to 0% duty-cycle, effectively short-circuiting the motor. That will safely brake it down to a halt (almost) without risking to over-charge your battery or causing any other harm to your system. When you do that however, you have no control over how long it will take for the motor to stop though, so while it sounds safe from an electrical perspective, it might not be from the mechanical side.
Also, if there’s an external torque applied to the motor, simply short-circuiting it will never completely stop it as the braking torque is proportional to the speed: your electrical car will never stop on a slope just by short-circuiting the motor. You’re battery won’t explode, so there’s some benefit, but you would still end up in the ditch.
Talking about safety, there’s another positive about sign-magnitude drive: you can set the input signals to a static state (0% PWM is basically a constant low- or high- voltage) at which point the motor won’t see any voltage from the battery. This is especially important in systems where some setup is needed on power-on before normal operation can start, like in the case of microcontrollers. You can configure the HW so that the default state of the control pins is such that the motor is safely stationary and only move out from that state only after the system initialization is complete.
All in all, sign-magnitude drive seems simple at first, but as with many things, the devil is in the details. For undemanding, simple applications it might be a good fit as it is, in most cases you’re probably going to need some sort of monitoring circuitry that can detect dangerous or unwanted situations and intervene to prevent them.
Where to go from there?
I will come back to the sign magnitude drive when we will talk about drive circuits and component selection. Before that however I will cover cover the other main drive mode, the lock anti-phase drive and compare the two to each other.