Building an H-Bridge from a salvaged Uninterruptible Power Supply

R. X. Seger
14 min readSep 6, 2016

--

“An H bridge is an electronic circuit that enables a voltage to be applied in either direction” — Wikipedia. In this article, we’ll build an H-bridge along with control logic entirely from parts salvaged from an UPS. After testing to confirm it is able to function in isolation, applying voltage in forward or reverse direction, etc., we will see how the bridge can be driven with NPN transistors controlled by Raspberry Pi’s 3.3V GPIO ports, and then build a NOR gate using N-channel MOSFETs to simplify the 4-bit control signal down to 2-bits, slightly reducing functionality but protecting against short-circuits. Finally, the H-bridge will be used in a practical (?) application, opening and closing a CD/DVD tray you may recognize from Salvaging a Samsung DVD-M101 Player.

Disassembling the UPS

Tripp Lite BC350 Uninterruptable Power Supply:

Labels on the reverse side:

BC350
Series AGBC5049
Input 120V ~ 60Hz 12A
UPS output: 115V ~ 60 Hz, 350VA, 180W
Total output not to exceed 1440W

References:

This unit has a dead battery, replaced several times, low output power, not worth or interested in replacing it again. Let’s take a look inside:

The dead 12V battery reads <0.5V. The transformer from Winsson Enterprises Co, Zhongding, is labeled Part No 62–1225. Update: more about this transformer, see Opening a Winsson 62–1225 Power Transformer.

Circuit Components

This UPS has a circuit board with primarily through-hole components (very few surface-mount, unlike what we saw when salvaging the DVD player). There are 3 regulated outlets, 3 non-regulated:

A closer look at the circuit board:

and the solder side:

Selected components of interest, these might come in handy later:

  • LS1: WT-1201 P transducer, datasheet: 1.5V(1–2V), 16±4.5 Ω, 2.4± 0.2kHz
  • Q1: X0402mF VU PHL thyrister/SCR datasheet: 4 A, 600 V, 200 µA sense
  • Q2, Q3, Q4, Q6, Q15, Q16,Q17,Q18: D1786R 3B NPN Darlington transistors
  • U5: UTC TL431K WJ9: adjustable voltage regulator, datasheet: 2.5V-36V (what is this chip? see Ken Shirriff’s blog: Reverse-engineering the TL431: the most common chip you’ve never heard of)
  • Q12, Q13, Q14: MPSA56 945: PNP general amplifier, datasheet: process 73
  • U3: LM324N: low-power quad-operational amplifiers datasheet
  • U2: 947Y f 817C: 4-pin DIP phototransistor optocoupler, datasheet
  • C19: 1000 µF 25 V electrolytic capacitor
  • C7: 1K275V-X2 Carli MPX40/100/21: X capacitor, 0.1 µF (0.01–10 µF)
  • Q7: P60NF06 7SAGU V6: N-channel STripFET power MOSFET datasheet
  • Q8+HS2, Q11+HS1: P60NF0 7SA GZ V6: N-ch power MOSFET datasheet
  • V1, V2, V3: MDC Z151 20UL: metal oxide surge varistor, datasheet
  • F1: 30 A cartridge fuse
  • TF6: X2X UMI 133ºC PT 3A 250V~ 5A 125V~ (PS)E JET thermal fuse radial lead, datasheet
  • R44: 47 Ω resistor, high wattage
  • R4, R12, R17: 1 kΩ resistor
  • R56: 2 kΩ resistor
  • R87: 3.3 kΩ resistor
  • R84: 4.7 kΩ resistor
  • R5, R10, R11, R51 (blue), R60: 10 kΩ resistor
  • R85: 47 kΩ resistor
  • D19: green LED for “on/off”
  • D18: red LED for “overload/check battery”
  • D1, D2, D3, D4, D5: 1N4007 diodes, 1A, datasheet: 1A, 1000V peak
  • D10, D11: 1N5404 diodes, datasheet: 3A, 400V peak, recovery rectifier
  • K1, K2: Song Chuan 812H-1A-C miniature PCB power relays, datasheet: single pole normally open (single throw), coil voltage 6V DC, flux tight

On the reverse side, surface-mount components:

  • U6: 95010WP K938Q 1K serial SPI EEPROM with datasheet: 2.5–5.5V
  • U4: ST (e4) Z 692217 99279 VP MYS 99 701, in a 34-pin SOIC package: unknown ST device, maybe an ST7 series microcontroller?

Update: here’s the board almost completely salvaged (not 100%, as I stopped desoldering resistors off this board once I bought a new pack of assorted resistors, see Organizing electronic components):

H-Bridge Design

Talking electronics : The H-Bridge describes many possible designs. A few:

Double-throw relays

First idea: an H-bridge can be built with one relay (DPDT) or two (2xSPDT), but the two relays included in the UPS are SPST, so four relays would be needed; there is a SPDT variant (1C) but the 1A relays are missing the normally-closed contact, only have normally-open. Next:

NPN transistors

Second plan: use NPN transistors, either this design (design #23):

or simplified, from letsmakerobots (NPN-only design on left):

wired this up on a breadboard:

using 1N4007 diodes, D1786R NPN transistors, but there’s a problem: the D1786R appears to be a Darlington Transistor (note: maybe not, the pinout is the garden-variety E/B/C, not B/C/E as on that page):

the voltage drops were too much, from the +5V power supply, insufficient to power the 5V motor.

Higher voltage?

Barrel connector on an old JTAG board (not related to the UPS, but wanted to try this anyway), required +5V center positive, but didn’t have a 5V wall wart handy, so unsoldered it and hooked up to RPi GPIO 5V:

Removed the connector, it can be repurposed for other uses:

like this 12.0 VDC 750 mA power supply with a compatible center positive barrel connector:

Even with this power supply, couldn’t get this H-bridge design to supply enough voltage to turn the motors; may be a faulty wall wart, erroneous design, or other issues, but did not investigate further. A new approach:

Single-throw relays

Third take: fortunately I happened to have another identical UPS, took it apart for two additional SPST relays. Wire it up as H-Bridge with switches:

except using four relays to replace the pushbutton switches.

Since the relay coil is an inductive load, and these are rated for 6V (works with 5V), control from 3.3V through an NPN transistor, for each relay.

Note you could simply build an H-bridge with transistors, cheap and efficient (other possibilities: use the power MOSFETs — but there are only three per UPS need for, or: use 2 x PNP and 2 x NPN, this could work, there are PNP’s on this UPS I haven’t used), but had these relays on hand, and they happen to be rated for 230V, could drive large loads, bigger motors. Overkill for these tiny 6VDC motors, but allows for further expansion, and I wanted an excuse to use these relays anyway:

Here they are laid out to resemble the H-bridge schematic. On the left you can see my failed attempt to scratch underneath the case to reveal the normally-closed contact, but it is not present in these single-throw relays. The two pins in the corners control the coil, the middle pin is common, and the lone pin in the corner is the normally-open contact. The four relays are arranged symmetrically, matching the diagram on Wikipedia: H bridge:

TODO: relay schematic

Solder the relays, using the mains wire from the UPS for good measure:

  • white: +5V (motor)
  • green: +5V (relay coil)
  • blue: motor+
  • brown: motor-
  • black: ground

The unsoldered corner pins are the control inputs, to the other side of the relay coils. Solder these on, along with 1N4001 diodes across the coils for flyback protection:

24 AWG wires:

  • white: +5V (motor)
  • red: +5 V (coil)
  • green: relay 1
  • purple: relay 2
  • blue: relay 3
  • yellow: relay 4

At this point, the H-Bridge is functional — you can wire up +5V power and ground, drive the four control inputs and the motor+/motor- outputs will swing to +5V or -5V or floating appropriately, but there are some problems.

H-Bridge Problems & Solutions

Transistor Driver

This relay-based H-Bridge can successfully drive a motor, or other high-current/voltage device, but it can’t itself be safely driven by a Raspberry Pi’s GPIO port. The Pi’s GPIO is 3.3V (~6V required for the relay coils) and is not intended to supply moderate amount of current required of inductive loads.

Solution: transistors. Use a circuit similar to this motor driver circuit. Fortunately, the UPS contains at least 4 NPN transistors (D1786R) and resistors (10 kΩ). Wire up as follows on a breadboard (ignoring the right-hand side of the breadboard, still has the old motor driver):

The base of each transistor (middle pin) through the resistor is then connected to the Pi’s GPIO inputs. I used the following pins I had available:

  • K1: pin #38 (G20), green wire
  • K2: pin #7 (G4), purple wire
  • K3: pin #36 (16), blue wire
  • K4: pin #40 (G21), yellow wire

A Python script can be easily written to control the bridge, hbridge1.py:

Current limiting

There’s a fundamental problem with this H-Bridge design. If two relays on top of each other are turned on, then +5V will be shorted to ground! It won’t go through the motor at all, and possibly damage the power supply.

The power supply in my case is a 5V DC 2A wall wart with USB micro-B connector, purchased from Sparkfun for powering the Raspberry Pi 3:

On the Pi’s GPIO port, +5V directly from this power supply is available, plus +3.3V and output pins. Maximum current ~50 mA for all GPIO pins, and 16 mA for each, according to the forums. But I’m not powering the relays using GPIO, rather, from +5V directly from the power supply.

How can the damage be limited should the H-Bridge inadvertently short?

5V through a 50 Ω resistor, limit current to I = V / R = (5 V) / (50 Ω) = 100 mA. Power of P = IV = (100 mA)(5 V) = 0.5 watts. Common small resistor wattages are 1/4 and 1/8 W. Used a 47 Ω high-wattage resistor from the UPS.

With this current-limiting resistor through the “+5V (motor)” connection, an H-bridge short will draw slightly more than 100 mA at most — this is enough to interfere with the Raspberry Pi operation, but not enough to reboot; recovers if restored quickly enough. And there is no discernable impact on the DC motor’s performance.

Control inputs review

Now it is time to review the control inputs to the H-Bridge, and the four unique operations. Wikipedia: H bridge: Operation documents this well, but to be comprehensive, it is helpful to list all 16 possible control inputs:

K1 K2 K3 K4

  • 0000: coast
  • 0001: coast
  • 0010: coast
  • 0011: short
  • 0100: coast
  • 0101: brake
  • 0110: forward
  • 0111: short
  • 1000: coast
  • 1001: reverse
  • 1010: brake
  • 1011: short
  • 1100: short
  • 1101: short
  • 1110: short
  • 1111: short

The most useful inputs are 0110 and 1001, turning the motor “forward” and “reverse” (positive and negative current), respectively. There is only one possible input to drive each of these operations.

Another useful operation is “coast”, leaving the motor’s inputs floating, disconnected, letting the motor spin freely until it stops. Four possible inputs combinations will give coast, but 0000 is the most logical canonical input.

Braking connects both of the motor’s lines to ground (0101) or the supply voltage (1010). This resists the motor’s momentum. Somewhat useful, depending on what you’re using it for, but I could do without.

Finally, there are 7 possible inputs causing short-circuits. Useless!

To sum it up, we have 4 control lines, occupying 4 GPIO outputs, yet nearly half of the possible values are damaging, and 69% are redundant or useless.

Inverter?

If we only care about the fwd/rev operations, then only 1 bit is needed:

K1 = C
K2 = not C
K3 = not C
K4 = C

where C is now the sole GPIO input, 0 gives 0110 (forward) and 1 gives 1001 (reverse). We’ll only need one new gate, an inverter, to implement this. However, this design forgoes the “coast” and “brake” operations.

No, NOR

Braking I could do without, but coasting, aka turning off the motor but not working against it, is kind of important. Otherwise the motor would run forever which is not desirable at least for my purposes, YMMV.

Here’s another design, using only a single NOR gate, and two input bits:

K1 = C
K2 = not (C or D)
K3 = not (C or D)
K4 = C

and the truth table, with corresponding operations:

D C → K1 K2 K3 K4

  • 00 → 0110 = forward
  • 01 → 1001 = reverse
  • 10 → 0000 = coast
  • 11 → 1001 = reverse

Reversing is overrepresented, but at least it is now possible to go both forward, reverse, and additionally coast. Using C for control plus D for disable, D = 0 given C = 0. With some additional logic, adding braking as the fourth state would be possible, but I’m ok with only coasting for now.

Building the NOR Gate

NOR gates are readily available in off-the-shelf ICs, such as the 7400 series 7402/74G102 or 4000 series 4000/4001/4002. NOR, or NAND, is the basic building block of modern computers. A commodity readily available.

But I didn’t have any jellybean NOR gates on hand, or much of anything else really, and I can only use salvaged parts from this UPS. Enter NMOS logic:

The UPS has three STP60NF06 N-channel STripFET II Power MOSFETs, at Q7, Q8, Q11. Two have hefty aluminum heatsinks, carefully unsolder each:

Pinout from datasheet:

Solder drains (pin #2) together, then to a 47 kΩ resistor pull-up resistor (couldn’t find a 100 kΩ in this UPS), in parallel with a 1 kΩ resistor (once I found out 47 kΩ was too limiting to drive the motors) to +5V, and sources (#3) together and then to ground. First take:

but then I realized on these MOSFETs, drain is wired to body. Screw tightly into the heatsinks, then solder onto the heatsink posts directly. This is a slightly more difficult solder job, since the heatsinks sink heat, but it can be done and I find it to be cleaner:

Wire up the NOR gate to power:

World’s biggest NOR gate
  • Input A: yellow
  • Input B: blue
  • Output Q: green
  • +5V power: black
  • Ground: white

and test each of its inputs versus the NOR truth table. It works! We now have a working NOR gate from salvaged power MOSFETs, albeit overkill for low-power logic, it is functional.

Hooking it up to the rest of the system. New GPIO pin assignments:

  • C, control input: pin #38 (G20)
  • D, disable input: pin #40 (G21)

C to K1 and K4, and then (D nor C) to K2 and K3. Tested the logic levels, but with the relays attached the voltage drop was too great, so I decreased the resistance of the pull-up resistor by adding 1 kΩ in parallel. A quick and dirty hack, would’ve been better to design for the current draw and voltage drop properly with specifications. Anyways here is the new Python script to control the 2-bit GPIO output, hbridge2.py:

TODO: could the propagation delay of NOR gate allow for short circuit?, if transitioning from C=1 (therefore K1=K4=1, reverse) to D nor C = 1 (K2=K3=1, forward, only case is C=0 and D=0), guard against in software?

Testing with this script, the motor correctly runs forward and reverse, or coasts, as per the command-line arguments. It works, sweet. But what now?

Application: CD/DVD Tray Control

You may recall I salvaged a CD/DVD tray in Salvaging a Samsung DVD-M101 Player, and was able to control it via GPIO but only in one direction. We now have the missing piece (an overcomplicated H-bridge circuit) to run the motor in both directions!

First some tests, to partially eject or inject the tray:

pi@raspberrypi:~/gpio $ python hbridge2.py reverse ; sleep 0.1 ; python hbridge2.py coast
pi@raspberrypi:~/gpio $ python hbridge2.py forward ; sleep 0.1 ; python hbridge2.py coast

Note the “coast” at the end to turn off the motor, otherwise it’ll continue running even with the tray is fully open/closed — this could burn out the motor, or worse.

Here is the pinout copied from Salvaging a Samsung DVD-M101 Player:

  • 1: GND
  • 2: OPSW
  • 3: CLSW
  • 4: TM+
  • 5: TM-

connecting the open/close switches to GPIO inputs, the motor can be turned off (set to coast, since I did not implement braking) when the tray is fully opened or closed. A simple script can be written in Python to open or close the tray, running the motor in the correct direction until it done, netbus.py:

running the script in a loop:

Notice you can hear the relays clicking as they switch off or on, and the blue/yellow LEDs in the upper-left hand corner toggle as the tray close and open state is detected.

And there we have it, a fully-functional H-bridge circuit including NPN transistor drivers and a MOSFET NOR gate for control logic, built entirely using parts salvaged from a broken UPS (or two).

Conclusions

It may have been much simpler to use an off-the-shelf H-bridge IC, such as the L298 in a multi-leaded power package (photo):

Summary of the parts used instead, salvaged from the Tripp Lite BC350 UPS:

  • 2× K1, K2: Song Chuan 812H-1A-C miniature PCB power relays, datasheet
  • Q8+HS2, Q11+HS1: P60NF0 7SA GZ: N-ch power MOSFETs with heatsinks, datasheet
  • Q2, Q3, Q4, Q6: D1786R 3B NPN Darlington transistors
  • D1, D2, D3, D4: 1N4007 diodes
  • R44: 47 Ω resistor, high wattage
  • R5, R10, R11, R51, R60: 10 kΩ resistors
  • R85: 47 kΩ resistor
  • stranded mains wire, ~12 AWG

The design could definitely be optimized further, especially if component selection is not limited to salvaged electronics.

I wouldn’t necessarily go out of my way to buy an UPS to use for parts, but if you have one lying around unused or half-used, you might crack it open, solder up the extra outlets to use as a power strip, and repurpose the relays, MOSFETs, BJTs, diodes, resistors, and wires into an H-bridge or something else useful.

Update 2016/09/09: schematic of the H-bridge, including control logic:

KiCad schematic now available at: https://github.com/rxseger/rp-hbridge

--

--