H-Bridge and Motor Control
Try it in Lab 02
Discover motor dead zones, calibration, and differential drive for precise movement patterns. → Motor Control tutorial | → Hardware Abstraction tutorial
How to Control a DC Motor
An H-bridge is a clever solution to a fundamental problem in motor control—how to reverse the current flow efficiently. Imagine you have a DC motor. When you connect a DC voltage to its two terminals, it starts rotating in one direction. But what if you need it to spin the other way? Simply swapping the connections would work, but doing this manually isn’t practical in automated systems.
This is where the H-bridge comes into play. By using a combination of electronic switches, it allows the motor’s connections to be dynamically reversed, enabling smooth and controlled bidirectional motion. This makes the H-bridge an essential component in robotics, electric vehicles, and various motor-driven applications.
How does a DC motor work?
If you connect a DC voltage to a motor's two terminals, it will rotate in one direction. To make it rotate in the opposite direction, simply swap the polarity of the voltage applied to the motor terminals. But why does this work?
Basic theory of DC motor operation
A DC motor works on the principle of electromagnetism. When a current passes through a coil within a magnetic field, a force is exerted on the coil, causing rotation. The direction of this rotation depends on the polarity of the applied voltage. Swapping the voltage reverses the direction of the current through the motor windings, thereby reversing the rotation.
Comparison to BLDC motors
While a brushed DC motor requires physical commutators and brushes to switch the current direction, a Brushless DC (BLDC) motor uses an electronic controller to achieve the same effect. BLDC motors tend to be more efficient and durable since they lack brushes, which wear out over time.
How an H-Bridge works
An H-bridge circuit connects the motor terminals to both the positive and negative sides of a DC power supply. By switching the connections electronically, the motor's direction can be changed without manually altering the wiring. This switching can be achieved using either relays or transistors.
Theoretical H-Bridge circuit
An H-bridge consists of four switches (transistors) arranged in an "H" configuration. The motor sits at the center of the "H."

By closing two opposite switches at a time, current flows in one direction through the motor.

Reversing which switches are closed changes the motor direction.

Controlling motor speed and torque
If the motor is directly connected to the DC supply, it will run at full speed. However, the actual speed depends on the load. What we can control directly is the torque, as it is related to the fundamental principles of electromechanical systems.
Basics of Induction in Electric Machines
-
Voltage and Current Relationship: Applying voltage across the motor terminals causes current to flow through its windings, generating a magnetic field.
-
Torque and Speed Relationship: The torque is proportional to the current, while speed is influenced by both the voltage and the motor load.
Using PWM for speed and torque control
To control the motor's speed and torque, we regulate its voltage and current using Pulse Width Modulation (PWM). Adjusting the duty cycle of the PWM signal allows us to modify the torque by controlling the average power delivered to the motor. The most efficient way to implement this control is by using MOSFETs in switching mode.
Why MOSFETs are Preferred for Switching?
MOSFETs are ideal for high-speed switching applications because they have:
- Low ON state resistance (reducing power loss)
- Fast switching speeds in range 25–500kHz (allowing efficient PWM control)
- High energy efficiency compared to mechanical relays high power dissipation
Preventing short circuits
With four MOSFETs in the H-bridge, it is crucial to control their switching sequence correctly. If both MOSFETs on the same side of the bridge turn on simultaneously, a short circuit (known as shoot-through) will occur, potentially damaging the circuit.

This can be ensured with a dead time.

Preventing shoot-through with dead time
To prevent shoot-through, we introduce a "dead time" between switching events. This ensures that both MOSFETs on one side are never conducting simultaneously. The required dead time depends on the switching characteristics of the MOSFETs and must be determined from datasheets and real-world measurements.
Back-EMF in Motors
Electric motors don’t just consume power—they can also generate it. When a motor is spinning, especially when it's slowing down or suddenly turned off, it can behave like a generator. This is due to its inductive nature and leads to the generation of back electromotive force (back-EMF)—a voltage that opposes the original supply.
Back-EMF is a normal phenomenon, but it becomes a problem when it creates high-voltage spikes that can damage transistors, controllers, or other sensitive components in the circuit. This is especially critical in DC motor control applications using switching devices like MOSFETs or BJTs. Proper handling of back-EMF is essential for safe and reliable motor operation.
How Back-EMF Is Managed in Circuits
Several techniques are commonly used to safely handle back-EMF and protect the surrounding electronics:
-
Flyback Diodes (Freewheeling Diodes):
These are the most common protection method for DC motors. A diode is placed across the motor terminals (or across the switching device, depending on the configuration) in reverse bias relative to the supply voltage. When the motor is switched off, the back-EMF causes current to flow through the diode instead of building up a high voltage across the switch. This provides a safe path for the current and prevents voltage spikes. -
Snubber Circuits:
Snubbers are combinations of resistors and capacitors (sometimes including diodes) placed across switching elements. They absorb the sudden change in voltage or current caused by back-EMF and smooth out transients. Snubbers are especially useful in high-speed switching circuits and for AC motors or inductive relays. -
Regenerative Braking:
In more advanced systems, the energy from back-EMF isn’t wasted—it’s recovered. Regenerative braking feeds the generated power back into the power supply or battery, improving overall efficiency. This method is commonly used in electric vehicles and robotics.
Regenerative Braking and Energy Recovery
When braking or slowing down a motor, the kinetic energy stored in the rotating parts doesn't just disappear—it must go somewhere. There are two main approaches to handle this energy:
-
Dissipating Energy as Heat:
One common method is to redirect the back-EMF through a braking resistor. This resistor converts the excess electrical energy into heat. While simple and reliable, this method wastes energy and is less efficient. -
Recovering Energy (Regenerative Braking):
A more efficient approach is to capture and reuse the energy. Regenerative braking feeds the energy generated by back-EMF back into the power supply system, typically by charging a battery or capacitor bank. This not only conserves energy but also extends battery life in systems like electric vehicles and robotic platforms.
Regenerative systems require more complex circuitry, including bidirectional power converters and control logic, but the energy savings can be significant.
Summary
- An H-bridge allows bidirectional motor control by electronically swapping motor connections.
- PWM is used to regulate torque and speed.
- Proper control of MOSFET switching prevents shoot-through.
- Dead time is necessary to avoid short circuits.
- Back-EMF must be managed to protect the circuit.
- Regenerative braking can be used to recover energy.
This forms the foundation of motor control using an H-bridge, and further refinements can enhance efficiency and functionality.
Professional Context: Automotive & Industrial Motors
Your robot uses simple brushed DC motors with a basic H-bridge. Professional systems use significantly more sophisticated motor control. Here's how they compare:
Motor Comparison
| Feature | Robot DC Motor | Automotive (EPS/EV) | Industrial Servo |
|---|---|---|---|
| Type | Brushed DC | BLDC / PMSM | BLDC / Stepper |
| Power | 1-5W | 500W - 150kW | 50W - 50kW |
| Efficiency | ~60-70% | ~90-95% | ~85-95% |
| Position feedback | None | Resolver / Encoder | Absolute encoder |
| Speed feedback | None | Hall sensors + estimation | High-res encoder |
| Current sensing | None | Per-phase shunt resistors | Integrated |
| Control loop | Open loop / basic PWM | Field-Oriented Control (FOC) | Cascaded PID + feedforward |
| Update rate | 50-100 Hz | 10-20 kHz | 1-10 kHz |
| Safety | None | ISO 26262 ASIL-D | SIL 2/3 |
Why Professional Systems Are Different
1. Feedback is Everything
Your robot: set_speed(100) → hope motor goes that fast
Automotive EPS:
Torque command → Current controller (20kHz) →
→ Measure actual current →
→ Adjust PWM in real-time →
→ Verify position with resolver
2. Field-Oriented Control (FOC)
BLDC/PMSM motors need sophisticated control: - Measure 3-phase currents - Transform to rotating reference frame (Clarke-Park) - Control torque and flux independently - Transform back to phase voltages - All at 10-20 kHz
This is why EVs and power steering feel so smooth.
3. Functional Safety
| Our Robot | Automotive Motor Control |
|---|---|
| Motor fails → robot stops | Motor fails → car crashes |
| No redundancy | Dual processors, watchdogs |
| No diagnostics | Continuous self-test |
| "It works" | Mathematically proven safe |
What You're Learning
Even with simple motors, the concepts transfer:
| Robot Concept | Professional Equivalent |
|---|---|
| PWM duty cycle | Switching frequency, dead-time optimization |
| H-bridge direction | 3-phase inverter commutation |
| Open-loop speed | Closed-loop torque/speed/position control |
| Bang-bang control | Cascaded PID with anti-windup |
| Motor characterization | System identification, parameter estimation |
Industry Examples
| Application | Motor Type | Key Challenge |
|---|---|---|
| Tesla Model 3 | PMSM 200kW | Efficiency, range optimization |
| Bosch EPS | BLDC 1kW | Torque ripple, steering feel |
| FANUC Robot | AC Servo | Position accuracy ±0.01mm |
| Dyson V15 | 125k RPM BLDC | Vibration, bearing life |
Hardware Limits Principle
What Software Can and Cannot Fix
Software CAN improve: - Response time → better control loop tuning - Smoothness → higher PWM frequency, filtering - Efficiency → optimized switching patterns - Accuracy → closed-loop feedback (if you have sensors!)
Software CANNOT fix: - No position feedback → need encoder/resolver hardware - Motor cogging torque → need different motor design - Thermal limits → need better cooling or bigger motor - Brush wear → need brushless motor - Gear backlash → need better gearbox or direct drive
The Pattern: Your robot has no motor feedback sensors. You can estimate speed from IMU vibration (Lab 7), but for true precision, you need encoder hardware.
➡ Next Steps
- Line Following - Controlling robot movements