Key Engineering Takeaways
- •An H-Bridge uses 4 switches to allow bidirectional current flow through inductive motor coils.
- •Legacy BJT drivers like the L298N drop 2V+ as heat; modern MOSFET drivers (DRV8833, TB6612FNG) have milliohm RDS(on) resistance.
- •Silent TMC2209 stepper drivers use StealthChop2 and spreadCycle for resonance-free precision motion.
- •BLDC Field-Oriented Control (FOC) achieves maximum torque efficiency and silky smooth low-speed positioning.
Prerequisites
- • Ohm’s law
- • PWM signals basics
Required Hardware / Tools
- • TB6612FNG or DRV8833 Driver
- • TMC2209 Stepper Driver
- • 12V DC Gearmotor
- • NEMA 17 Stepper
H-Bridge Topology & Shoot-Through Protection
An H-Bridge consists of four transistor switches arranged in an "H" configuration with the motor armature in the center. By activating diagonal pairs ($Q_1$ and $Q_4$ vs $Q_2$ and $Q_3$), current flows forward or reverse.
### The Dead-Time (Shoot-Through) Danger
If high-side switch $Q_1$ and low-side switch $Q_2$ are accidentally enabled at the exact same instant, a direct dead short occurs from $V_{\text{motor}}$ to Ground. This **shoot-through condition** vaporizes silicon in microseconds. Modern driver ICs incorporate automatic hardware **dead-time insertion** (typically 200ns-1µs) to ensure one switch fully opens before its counterpart closes.
Why L298N is Obsolete: Modern MOSFET Drivers
The vintage L298N is built on outdated bipolar junction transistors (BJT). A typical L298N has an internal collector-emitter saturation voltage drop of $1.8\,\text{V} - 3.2\,\text{V}$. If drawing $2\,\text{A}$:
$$P_{\text{lost as heat}} = V_{\text{drop}} \times I = 2.5\,\text{V} \times 2.0\,\text{A} = 5.0\,\text{Watts}$$
In contrast, a modern MOSFET driver like the **TB6612FNG** or **DRV8871** has an on-resistance $R_{\text{DS(on)}} \approx 0.08\,\Omega$:
$$P_{\text{lost}} = I^2 \times R_{\text{DS(on)}} = (2.0\,\text{A})^2 \times 0.08\,\Omega = 0.32\,\text{Watts}$$
You gain over 93% reduction in wasted thermal energy, preserving battery life and eliminating heavy heatsinks.
tb6612_driver_control.cpp
cpp
#include <Arduino.h>
// TB6612FNG Hardware Pins
const int PIN_PWMA = 25; // ESP32 PWM pin
const int PIN_AIN1 = 26;
const int PIN_AIN2 = 27;
const int PIN_STBY = 14;
// PWM Configuration for ESP32
const int PWM_FREQ = 20000; // 20kHz ultrasonic frequency (no audible whine)
const int PWM_CHAN = 0;
const int PWM_RES = 8; // 8-bit resolution (0-255)
void setupMotor() {
pinMode(PIN_AIN1, OUTPUT);
pinMode(PIN_AIN2, OUTPUT);
pinMode(PIN_STBY, OUTPUT);
ledcSetup(PWM_CHAN, PWM_FREQ, PWM_RES);
ledcAttachPin(PIN_PWMA, PWM_CHAN);
digitalWrite(PIN_STBY, HIGH); // Enable driver out of standby
}
void setMotorSpeed(int speed) { // speed from -255 to +255
if (speed > 0) {
digitalWrite(PIN_AIN1, HIGH);
digitalWrite(PIN_AIN2, LOW);
ledcWrite(PWM_CHAN, constrain(speed, 0, 255));
} else if (speed < 0) {
digitalWrite(PIN_AIN1, LOW);
digitalWrite(PIN_AIN2, HIGH);
ledcWrite(PWM_CHAN, constrain(-speed, 0, 255));
} else {
// Active electronic braking
digitalWrite(PIN_AIN1, HIGH);
digitalWrite(PIN_AIN2, HIGH);
ledcWrite(PWM_CHAN, 0);
}
}Tags:#Motors#H-Bridge#MOSFET#BLDC#ESC#Stepper#FOC