Loading [MathJax]/jax/output/HTML-CSS/jax.js

H-Bridge Current Sensing

I intend to do some experiments with motor control and switching converters. Some of these experiments require to control currents in power electronic circuits, in particular the currents through inductive loads in H-bridge circuits. For that purpose, currents in H-bridges first have to be measured.

Consider a H-bridge as in Figure 1 below. Via PWM, an arbitrary voltage in the range VB,,VB can be applied to the load. To apply a positive voltage to the load, M4 is permanently on and complementary PWM signals are applied to M1 and M2. In one PWM period of duration T, M1 is on for a certain time t1, then M1 is turned off and M2 is turned on for the remaining time t2=Tt1, resulting in an average voltage of VL=VBt1/T at the load. To apply a negative voltage to the load, M2 is permanently on and the PWM signals are applied to M3 and M4. (There are also other modulation schemes for controlling H-bridges, see e.g. this application report from TI, in which the design of output filters for Class-D audio amplifiers for different modulation schemes is discussed.) In motor control applications, the load presents some inductance. Depending on the PWM frequency and the inductance, the current through the load has some ripple. By choosing an appropriately high PWM frequency, this ripple can be reduced to a level which is acceptable for the application.

MISSING IMAGE
Figure 1: H-bridge.

Current Sensing via Shunt Resistor

One way to measure a current is to measure the voltage drop over a shunt resistor caused by it, i.e. we simply have to connect a shunt resistor (typically several mΩ to several tens or a few hundred mΩ) in series with the load and measure the voltage drop over Rshunt.

MISSING IMAGE
Figure 2: H-bridge with shunt resistor.

However, conditioning this voltage signal such that it can be measured with the AD-converter of a microcontroller is not a straight forward task. We are interested in the voltage drop Vdiff across the shunt resistor. Therefore, a differential amplifier is needed. However, the differential amplifier must be able to handle a large common mode voltage. Due to the inductive nature of the load, the voltage at node A can even drop below the ground potential (by the voltage drop of the body diode of the MOSFET M2) and exceed the bus voltage VB (by the forward voltage drop of the body diode of the MOSFET M1). (If we are dealing with a H-bridge or three half bridges as in three phase applications or some other configuration does not matter. In any case, measuring the current involves the conditioning of a small differential voltage under the presence of a large common mode voltage.) There exist highly specialized differential amplifiers designed specifically for current sensing applications in PWM controlled power electronic circuits which can handle this, e.g. the INA240, which can handle common mode voltages from 4V to 80V while only supplied by 5V and which recovers from common mode transients within several hundred nanoseconds. However, this and comparable chips do not seem to be very common among hobbyists. I am not aware of commonly available breakout boards for this chip. The same applies to comparable current sense amplifiers like e.g. the MAX40056F

Other differential amplifiers which can handle very large common mode voltages are e.g. the INA149 or the AD628. Also these amplifiers seem to be well suited for current sensing applications, though their data sheets do not say a lot about their behavior under fast common mode transients as they occur in PWM controlled H-bridges. The INA149 has unity differential gain. In principle, the circuit used in this chip could be built with an operational amplifier and some precisely selected resistors. The principle circuit in the AD628 is not complicated either. It consists essentially of two basic operational amplifier circuits, namely an operational amplifier configured as differential amplifier (with differential gain less than one to allow for large common mode signals, we analyze that in detail below) and an operational amplifier configured as non-inverting amplifier (the gain of this stage can be set by two external resistors). The simplicity of the principle circuits of these amplifiers made me wonder whether I can build such amplifiers myself, using only some commonly available operational amplifiers and metal film resistors. Let us first consider the following circuit (inspired by the schematic given in the data sheet of the AD628).

MISSING IMAGE
Figure 3: Differential amplifier Version 1.

Let us analyze this circuit in regard to differential gain and the maximal admissible common mode voltage. The voltage at the inputs of OP1 must not exceed its supply voltage Vs and must not drop below the ground potential 0V. Opamps which can handle that are called rail-to-rail input amplifiers (similar to rail-to-rail output amplifiers, whose output voltage swing (almost) includes the supply rails). However, not all opamps are rail-to-rail input amplifiers, in which case an extra margin of typically several hundred mV up to a few V to the supply rails has to be taken into account. In the following, this margin is denoted Vm.

Let Vin1=Vcm+1/2Vdiff and Vin2=Vcm1/2Vdiff, i.e. the voltage at the inputs of the circuit consists of a common mode component Vcm and a differential mode component Vdiff. Applying some basic network analysis methods, we find that the output voltage Vout2 of this circuit is given by

Vout2=Vref+R2R1(1+R4R3)Vdiff

The common mode voltage Vcm has (ideally) no effect on the output voltage. The gain of the first stage, i.e. the ratio of R2 and R1 is limited by the admissible common mode voltage at the inputs of OP1. The voltage at the inputs of OP1 follows as

(Vcm+12Vdiff)R2R1+R2+VrefR1R1+R2

and as discussed above, this voltage must not exceed VSVM and must not drop below VM, i.e.

Vm(Vcm+12Vdiff)R2R1+R2+VrefR1R1+R2VsVm

In our application, the common mode voltage swings approximately between 0V and the bus voltage VB, whereas the differential mode voltage is only the voltage drop across the shunt resistor, i.e. we may neglect Vdiff compared to Vcm for determining bounds on the ratio of R2 and R1. Furthermore, it is obviously reasonable to assume Vm<Vref<VsVm. The first part of the inequality is relevant for negative Vcm=Vcm,min with Vcm,min<0V (which can occur with inductive loads), and yields

R2/R1VrefVmVmVcm,min(with Vcm,min<0V)

The other part of the inequality is relevant for Vcm=Vcm,max and yields the restriction

R2/R1VsVmVrefVcm,maxVs+Vm(with Vcm,max>VsVm)

Example 1:

For Vs=5V, Vref=2.5V, Vm=0V (rail-to-rail input amplifier) and Vcm,min=1V as well as Vcm,max=25V (corresponding to a bus voltage of the H-bridge of VB=24V), an upper bound on the ratio of R1 and R2, and thus the gain of the first amplifier stage, is given by R2/R12.5 due to the first inequality and R2/R10.125 due to the second inequality. So in this example, the first stage actually dampens the signal by a factor of 8. Damping the signal in the first stage and amplifying it in the second stage makes the circuit susceptible for offset voltages of the opamps and noise.

Another problem of this circuit is its common mode gain. Ideally, i.e. with perfectly matched resistors, the common mode gain of the circuit is zero. However, in practice the resistors R1 and R2 connected to the inverting input of OP1 will slightly differ from R1 and R2 connected to the non-inverting input of OP1, see the figure below.

MISSING IMAGE
Figure 4: Differential amplifier Version 1 - with resistor mismatch.

A mismatch of the ratios R2/R1 and R2/R1 causes a common mod gain. Let R2/R1=(1+ϵ)R2/R1, i.e. for ϵ=0 the resistor ratios are perfectly matched, the larger ϵ the worse is the match. For the above circuit one derives

Vout2=Vref+[ϵ1+R2R1(1+ϵ)Vcm+(1+ϵ2(1+R2R1(1+ϵ)))Vdiff]R2R1(1+R4R3)Vref+(ϵ1+R2R1Vcm+Vdiff)R2R1(1+R4R3)

The common mode rejection ratio, which is the ratio of the differential mode gain and the common mode gain (and is usually given in dB) of this circuit is thus approximately

CMMR1+R2R1ϵ

A high CMMR is crucial in our application since the common mode voltage Vcm is in the range of the bus voltage VB, whereas the differential mode voltage Vdiff, i.e. the voltage drop across the shunt resistor, is only in the range of at most a few hundred mV.

Example 2:

With R2/R1=0.125 (see Example 1) and 0.1% resistors, the worst-case mismatch of the resistor ratios is ϵ=1.0012/0.999210.004, we achieve CMMR281. A swing of the common mode voltage between 0V and 24V causes the same swing of the output voltage Vout1 of the differential amplifier as a differential mode voltage swing of approximately 0.085V. In conjunction with a shunt resistor of e.g. 200mΩ, this corresponds to an error in the measured current of 425mA.

According to the above formula, a high CMMR is achieved by a good match of the resistors (i.e. a small ϵ) and a large ratio R2/R1. Above we have seen that R2/R1 is limited by the admissible common mode voltage at the inputs of OP1.

Improving the CMMR

Above, we have derived that CMMR(1+R2/R1)/ϵ, i.e. the CMMR improves with a larger resistor ratio R2/R1. This resistor ratio is also the differential gain of the circuit, so a larger ratio is indeed desireable. However, as we have also seen above, the ratio R2/R1 is limited by the common mode signal which the circuit has to be able to handle (see Example 1 above). Raising the supply voltage Vs of OP1 to the bus voltage VB of the H-bridge (for low voltage applications, i.e. VB=24V, this can easily be done with standard opamps) and choosing Vref=Vs/2 allows for the largest resistor ratio R2/R1 (a 78xx fixed voltage regulator may be used for generating Vref from (filtered) VB). Recall that with an inductive load in the H-bridge, the common mode voltage can exceed VB and drop below 0V by the voltage drop of the body diode of the corresponding MOSFET, i.e. about 1V (though this only occurs during the short period of dead-time in which none of the MOSFETs is turned on). Taking this transient into account, i.e. requiring that the circuit can handle a common mode voltage of VDiode to VB+VDiode, and choosing Vs=VB as well as Vref=Vs/2 yields (for a rail-to-rail input amplifier)

R2/R1VB2VDiode.

Consequently, the ratio R2/R1 and thus the CMMR can be improved significantly. The output of OP1 is now of course centered at Vref=Vs/2 and may swing between approximately 0V and Vs. Therefore, in the circuit below, the voltage divider formed by R3 and R4 is used for conditioning the signal for ADC inputs. The overall differential gain is thus ADiff=R2R1R4R3+R4. A drawback of the proposed circuit is that Vref cannot be used directly in a differential input ADC, it also needs to be divided down by a voltage divider with resistor values R3 and R4. (When only using a single ended ADC, this additional voltage divider is of course not needed. However, then inaccuracies of Vref directly influence the current reading.)

MISSING IMAGE
Figure 5: Differential amplifier Version 2.

For the above circuit, one derives the following formula for the output voltage

Vout=R4R3+R4VrefVref+R2R1R4R3+R4AdiffVdiff

Taking into account a mismatch of the resistors, where R2/R1=(1+ϵ1)R2/R1 and R4/R3=(1+ϵ2)R4/R3 and an offset voltage Vos of the opamp, as illustrated in Figure 6 below

MISSING IMAGE
Figure 6: Differential amplifier Version 2 - with resistor mismatch and offset voltage.

one derives

Vout=R4R3+R4Vref[ϵ11+R2R1(1+ϵ1)Vcm+(1+ϵ12(1+R2R1(1+ϵ1)))Vdiff]R2R1R4R3+R4+(1+R2R1)R4R3+R4VosR4R3+R4Vref+[(ϵ11+R2R1Vcm+Vdiff)R2R1+(1+R2R1)Vos]R4R3+R4

and for the difference VoutVref, which is relevant when an ADC with differential inputs is used, we obtain

VoutVref[ϵ2R3R3+R4Vref+(ϵ11+R2R1Vcm+Vdiff)R2R1+(1+R2R1)Vos]R4R3+R4.

Example 3:

Assume that we have Vs=VB=24V (the opamp may be supplied by a filtered version of the bus voltage, a varying bus voltage is not really a problem because the power supply rejection ratio of usual opamps is usually in the range of 100dB), a shunt resistor of e.g. 200mΩ and a desired measuring range of ±2A, which should produce an output voltage Vout between 1V and 4V (i.e. centered at 2.5V). The required differential gain of the circuit is thus ADiff=3.75. The differential gain of the circuit is given by ADiff=R2R1R4R3+R4. Since Vout1 should be centered at 2.5V and Vref=Vs/2=12V, it follows that R4/(R3+R4)=5/24 and consequently R2/R1=18. Again with 0.1% resistors and the worst-case mismatch of the resistor ratios of ϵ0.004, we achieve CMMR4750. A swing of the common mode voltage between 0V and 24V causes the same swing of the output voltage Vout1 as a differential mode voltage swing of approximately 0.005V. With the 200mΩ shunt resistor, this corresponds to an error in the measured current of 25mA, which is a significant improvement over the 425mA of the previous circuit. The larger the gain of the circuit, i.e. the larger the ratio R2/R1, the larger is the effect of the offset voltage. In this example, a usual input offset voltage of OP1 of 2mV corresponds to an error of the measured current of approximately 12.6mA.

Depending on the PWM frequency, the load inductance and its resistance, the current through the load has some ripple. To filter out this ripple, i.e. to sense the average current through the load, Vout has to be low pass filtered. Adding a capacitor with capacitance C in parallel to R4 results in low pass filtering with a cutoff frequency of fc=R3+R42πR3R4C.

Experimental Results

For testing the current sensing amplifier in practice, I have set up a test circuit on a breadboard. On the left, you can see a L6205 dual full bridge ic. It is wired up according to the typical application circuit provided in its data sheet (only one of the two full bridges is actually used). The shunt resistor is formed by two large 1Ω resistors in parallel (thus Rshunt=0.5Ω), which you can see in the middle. (Such a setup is of course far from a proper Kelvin connection of the shunt resistor. The contact resistance of the breadboard, which depends on many factors and is thus not very well reproducible, adds to the shunt resistance. In my setup, with a brand-new breadboard, I measured a contact resistance below 4mΩ, which is negligible compared to the shunt resistance. However, for a lower value shunt resistor, I would solder sensing wires directly to its leads.) To the right, you can see a dual opamp, namely the very common LM358. One opamp in this package is the actual current sensing amplifier, set up according to Figure 4, the other one is used for providing the reference voltage of about half the supply voltage for the current sensing amplifier. The load is one winding of a stepper motor (approximately 1Ω and 0.8mH). The whole setup is supplied by roughly 18V from batteries (which drops to about 15V under load due to their internal resistance and the way to thin wire used for connecting them to the breadboard).

MISSING IMAGE
Figure 7: Experimental setup.

The actual current sensing amplifier is set up according to the circuit in Figure 5 using 0.1% resistors with nominal values R1=10kΩ, R2=30kΩ, R3=30kΩ, R4=10kΩ. Together with Rshunt=0.5Ω, this results in a sensitivity of 0.375V/A. The PWM signal comes from a function generator. In one of the two half bridges, which together form the H-bridge, the low-side MOSFET is all the time on and the high-side MOSFET all the time off. The other half bridge is feed by the PWM signal. I tested 10kHz and 50kHz with 20% duty cycle in each case. The measurement results are presented below.

In Figure 8 below, you can see the measurement results for a PWM frequency of 10kHz with no load connected and no filtering (i.e. no capacitor in parallel to R4). The top trace is VoutVref (which here should ideally be zero throughout) and the bottom trace is Vin1 (i.e. the common mode input voltage of the current sense amplifier). Note that the vertical setting for both channels is different. The common mode gain of the amplifier is too low to be visible with the used vertical setting, however, the switching transients of the PWM are visible in the output signal.

MISSING IMAGE
Figure 8: CH1: Vout-Vref' | CH2: Vin1 | 10 kHz PWM | no load | no filter.

Figure 9 below shows the measurement results with the load connected. One can clearly see that the current through the load is rising during the on-time of the PWM and falling during the rest of the PWM period (during this time, the load is shorted via the two low-side MOSFETS of the H-bridge).

MISSING IMAGE
Figure 9: CH1: Vout-Vref' | CH2: Vin1 | 10 kHz PWM | with load | no filter.

Figure 10 below shows the measurement results with the load connected and 5nF capacitance connected in parallel to R4. This results in a first order low pass filtering of the output signal with a cutoff frequency of approximately 4.2kHz. The this way averaged output signal VoutVref is approximately 0.55V, corresponding to an average load current of 0.55V/(0.375V/A)=1.47A. Measuring the voltage drop across the shunt resistor with a multimeter gave me a reading of 0.720V, corresponding to an average current of 0.72V/Rshunt=1.44A. The relative error between these two measurements is thus only approximately 2%.

In Figure 11 below, the setup is exactly the same, except that the PWM frequency is 50kHz. The averaged output signal VoutVref is approximately 0.45V, corresponding to an average load current of 0.45V/(0.375V/A)=1.20A. Measuring the voltage drop across the shunt resistor with a multimeter gave me a reading of 0.590V, corresponding to an average current of 0.59V/Rshunt=1.18A. (Although the duty cycle of the PWM signal generated by the function generator is in both cases 20%, the actual duty cycle seen by the load is smaller when the frequency is higher due to the dead-time of the H-bridge, which is necessary to prevent cross conduction.)

MISSING IMAGE
Figure 10: CH1: Vout-Vref' | CH2: Vin1 | 10 kHz PWM | with load | with filter.
MISSING IMAGE
Figure 11: CH1: Vout-Vref' | CH2: Vin1 | 50 kHz PWM | with load | with filter.

Conclusion

Using a standard differential amplifier circuit based on an opamp seems to be feasible for current sensing in low voltage H-bridges with bus voltages of up to maybe 30V. The accuracy depends on how well the used resistors are matched and the value of the shunt resistor. If a shunt resistor in the range of a few hundred mΩ is acceptable, reasonable accuracy can easily be achieved. However, such a self built current sensing amplifier may not be well suited for shunt resistances of only a few mΩ. In general, I do not think that it is worth taking the hassle to build current sensing amplifiers yourself. In future projects, I will rather use current sensing amplifiers like the INA240, or use Hall effect (or flux gate) based current sensors like the LTS x-NP, CASR x-NP or T60404.

Hall Effect Current Sensing

Besides measuring currents via the voltage drop over a shunt resistor, currents can also be measured via the magnetic fields caused by them. Magnetic fields can in turn be measured via the Hall effect. There are many current sensors available which rely on the Hall effect, for example the ACS712. This and similar current sensors provide a galvanic isolation between the current sensing path and the actual sensing circuit, which makes them perfectly suited for current sensing in H-bridges and other power electronic circuits. The ACS712 comes in an 8-Lead SOIC package, i.e. the same SMD package used e.g. for opamps. The current to be measured flows via a low resistance trace through the ic. In close proximity to this trace, a Hall sensor is placed. The amplified and conditioned output voltage of the Hall sensor is then proportional to the current flowing through the ic. The ACS712 is quite popular in the hobby electronics community, ready to use breakout boards for this chip are widely available. A drawback of this an similar current sensors is however that they are susceptible to external magnetic fields and the output signal is quite noisy (see data sheet for noise specifications). Other Hall effect based current sensors use a ferrite or iron powder core. The current to be measured flows through a loop of wire around the core and a Hall sensor is placed in an air gap of the core. Instead of these open loop sensors, which output the amplified voltage from the Hall sensor, there are also closed loop current sensors available. As with the open loop sensors, the current to be measured flows through a loop of wire around the core and a Hall sensor is placed in an air gap of the core, but an additional winding around the core is used for compensating the magnetic flux caused by the current to be measured. This is achieved by a feedback control loop, which controls the current through this compensation winding. The current needed for compensating the flux is related to the current in the primary winding via the turns ratio of the primary winding and the compensation winding. A current sensor based on this principle is e.g. the LTS 6-NP.

MISSING IMAGE
Figure 12: Open loop and closed loop Hall effect based current sensor principle.