- Every tab is a live time simulation: ▶ Play, ❚❚ Pause, ↺ Reset.
- Speed 1× = real time. Slow down for electrical events, speed up for thermal ones.
- Dots follow the simulated current. Losses come from the datasheet values of the part you pick.
PWM keeps the LED’s peak current fixed and changes only its duration. The colour does not shift. The eye sees the average, but only if the frequency is high enough.
LED dimming: PWM with a low-side N-MOSFET
Why low-side?
The source is at ground, so VGS = the GPIO voltage. No level shifter needed. LED strips are common-anode anyway (+12 V common).
Gamma correction
The eye perceives brightness roughly as D1/2.2. 10 % duty looks 35 % bright. So use D = setting2.2 and at least 10-bit PWM.
Frequency
Below ~200 Hz the flicker is visible. IEEE 1789: at 100 % modulation ≥ 1.25 kHz is low-risk, ≥ 3 kHz no effect. Switching loss and EMI set the upper limit.
Worked: 3 LEDs at 12 V, 350 mA, series resistor
- String voltage3 · (2.8 + 0.8 · 0.35)9.24 V
- Series resistor(12 − 9.24) / 0.357.9 Ω → 8.2 Ω
- Actual current(12 − 8.4) / (8.2 + 2.4)340 mA
- Resistor loss0.34² · 8.20.95 Wuse a 2 W resistor
- MOSFET loss (D = 1)0.34² · 0.0252.9 mW
- 14.4 V with the engine running(14.4 − 8.4) / 10.6565 mA+66 % current
A one-direction motor needs one low-side N-MOSFET and one flyback diode. The average voltage D·V sets the speed. A PI loop holds the speed regardless of load.
DC motor speed control: PWM, flyback diode, PI
No braking
A single switch can only accelerate the motor. Friction and load do the slowing. That is why a downward step overshoots and recovers slowly.
PWM frequency
If the period is longer than τ = L/R, the current drops to zero each period. Torque ripples and the motor whines. 16–25 kHz avoids that and the audible tone.
Inrush at start
A stopped motor has zero back-EMF, so I = V/R. On a step the PI saturates at 100 % and draws that current. Size the switch and supply for this peak.
Worked: 12 V motor, inrush and PWM frequency
- Stall currentI = 12 / 26 Aseen at every start
- No-load speedω = 12 / 0.02600 rad/s ≈ 5700 rpm
- Electrical ττ = 1 mH / 2 Ω0.5 ms
- 20 kHz periodT = 1 / 20 kHz50 µsT ≪ τ → continuous current
- 200 Hz periodT = 1 / 200 Hz5 msT ≫ τ → discontinuous, pulsed torque
- Mechanical τJ·R / k² = 2·10⁻⁵ · 2 / 0.02²0.1 s
A heater is slow: even 1 Hz PWM is averaged perfectly. On/off is simple but oscillates because of the sensor lag. PI sets the power on average and shrinks the ripple.
Heater: on/off (hysteresis) vs PI (slow PWM)
Why slow PWM?
The thermal τ is seconds to minutes. Slow switching makes no EMI and almost no switching loss. AC heaters use an SSR that switches at zero crossing.
Relay or MOSFET?
A relay lasts ~100 000 cycles. At a 2 s period that is 2–3 days. For frequent switching use a MOSFET or an SSR.
Low-side or high-side?
Two-wire isolated heater: low-side N-MOSFET, the cheapest. One end on the chassis (seat heater, 24 V sourcing output): high-side P-MOSFET or a smart switch.
Worked: 12 V, 40 W heater, IRLZ44N
- Heater resistanceR = 12² / 403.6 Ω
- CurrentI = 12 / 3.63.33 A
- Conduction loss (100 %)3.33² · 0.0270.30 W
- Junction25 + 0.30 · 6244 °Cno heatsink needed
- Highest reachable T25 + 40 · 3145 °C
- Thermal time constantτ = 25 · 375 s1 Hz PWM is fully averaged
Holding a position needs both directions and braking: an H-bridge. The encoder measures the angle, the PID computes the duty. Duty saturates at ±100 %.
Position control: H-bridge, encoder, PID
Diagonal pair
Q1+Q4 drive one way, Q3+Q2 the other. The two switches of one leg are never on together. The driver inserts dead time.
Why four N-MOSFETs?
An N-MOSFET has 2–3× lower RDS(on) than a P-MOSFET. The high-side gate must rise above VS. Half-bridge drivers with a bootstrap capacitor do that.
P · I · D
P drives in proportion to the error. D brakes on approach and reduces overshoot. I removes the error left by load torque; anti-windup is mandatory.
Worked: resolution, speed and Kp
- Stall currentI = 12 / 34 A
- Output no-load speed(12 / 0.025) / 509.6 rad/s ≈ 550 °/s
- Counts per turn12 · 4 · 502400
- Resolution360° / 24000.15°
- Error for full duty1 / Kp = 1 / 0.0333°larger steps saturate
Hobby RC servo: the pulse width sets the position
- A servo packs motor, gearbox, sensor, H-bridge and controller into one box.
- Command: a 1–2 ms pulse every ~20 ms. Width = target angle.
- The signal line carries no power. The servo draws from its own 5–6 V supply, amps while moving.
Servo pulse → angle
Pulling in needs high current; holding needs far less. Peak-and-hold pulls in at full voltage, then lowers the current with PWM. Power falls with current squared, so the saving is large.
Solenoid valve: peak-and-hold vs plain DC drive
Diode only
At turn-off the current decays slowly with the coil’s τ = L/R. The valve releases late. The MOSFET sees only VS + 0.7 V.
Diode + zener
The zener applies VZ backwards and the current dies several times faster. The price: the MOSFET sees VS + VZ + VF. Check the VDS margin.
Best of both
During hold QZ shorts the zener: low ripple. At turn-off QZ opens: fast release. Injector drivers work this way.
Worked: 12 V valve, holding power and VDS
- DC power12² / 1212 W
- Holding power0.34² · 121.4 W
- Saving1 − 1.4 / 1288 %
- Energy at turn-off½ · 0.06 · 0.34²3.5 mJburned in the zener
- Peak VDS12 + 24 + 0.736.7 Va 30 V part avalanches
Single pulse: pulse width → energy
- Some loads get a single pulse: injectors, impact magnets, lock coils.
- Pulse energy: resistor heat + magnetic field + mechanical work.
- A pulse too short to pull in only makes heat.
Single-pulse simulation
The same MOSFET does three different jobs. Which one sets the frequency, the source of loss and the protection.
On/off 0 – ~1 Hz
Where: lamps, pumps, relay replacement, hysteresis heater.
Transistor: fully on or off for long times. Loss ≈ I²·RDS(on).
Risk: inrush, turn-off kick, short circuit.
Continuous: PWM 0.1 Hz – 100 kHz
Where: LEDs, motor speed/position, heaters, SMPS.
Transistor: two edges per period. Loss = conduction + V·I·tedge·f.
Risk: slow gate drive, missing freewheel path.
Continuous: linear DC
Where: CC LED sinks, linear regulators, electronic loads, soft start.
Transistor: half on, continuously VDS·ID.
Risk: DC SOA. Switching MOSFETs die easily in linear duty.
Pulse µs – ms
Where: peak-and-hold, servo command, stepper pulses, one-shots.
Transistor: short, high peak; small average. IDM and Zθ(t) matter.
Risk: where the ½·L·I² energy goes at the end.
| Application | Control | Frequency | Topology | Dominant loss / risk |
|---|---|---|---|---|
| LED strip | PWM | 0.2–20 kHz | Low-side N-MOS | Conduction; flicker at low f |
| Fan / pump | PWM | 16–25 kHz | Low-side + flyback | Inrush, switching |
| Position actuator | PWM + PID | 16–40 kHz | H-bridge | Shoot-through, dead time |
| Heater | On/off, slow PWM | 0.05–1 Hz | Low- / high-side | Conduction |
| Solenoid valve | Pulse + hold PWM | single + 20 kHz | Low-side + clamp | Turn-off kick |
| RC servo | Pulse width | 50–300 Hz | Signal only | Supply sag |
| Stepper motor | STEP/DIR | 0–50 kHz steps | 2× H-bridge, chopper | Resonance, missed steps |