LED drivers: constant current with PWM and analog dimming
An LED wants a current, not a voltage, so an LED driver is a converter that holds a current and lets the string's voltage fall where it will. Here you open two drivers, size the first one with Design › Design Steps › LED Driver, see why 1 kHz PWM dimming is a flicker problem and 2 kHz is not, and then dim the second one two ways: the current itself (analog) and the share of time it flows (PWM). About 15 minutes.
File › Open Example is a menu path and F5 a key.
The numbers on this page are checked by the tests of crates/engine/tests/tutorial_led.rs, which run the same examples. All LED values in the examples are illustrative: each LED is a 3 V threshold and 1 Ω straight line, not a part.
1. Open the buck driver
Step 1 of 5 · about 1 minChoose File › Open Example › DC-DC › LED driver, buck with PWM dimming.
48 V feeds a buck whose comparator Hys holds the LED current iled inside a band of ±50 mA around 0.7 A; no oscillator and no compensator are needed, the band sets the switching frequency. The string LED1 is eight LEDs, so it sits near 29.6 V. A 1 kHz PWM Dim at half duty switches the reference to zero for half of each period, so the current flows in pulses.
2. Size it
Step 2 of 5 · about 1 minChoose Design › Design Steps › LED Driver and press ▶ Run with every field empty: each input is read from the circuit (the list says which ones came from the circuit and which are defaults). The command is design.ledDriver {"verify": true}.
- The switching frequency in regulation is 243 kHz: the inductor's volt-second balance over the band (Erickson and Maksimović, Fundamentals of Power Electronics, 3rd ed., §2.2).
- The mean LED current with half-duty dimming is 0.349 A, and the verify run simulates the circuit and finds 0.349 A, with a peak of 0.75 A, the top of the band.
- A pulse needs time to rise from zero, so a very short pulse never reaches regulation: the shortest dimming duty that does at 1 kHz is 1.7 %.
3. Flicker
Step 3 of 5 · about 1 minThe same reply shows the flicker: 100 %, because the light goes fully off between pulses. IEEE Std 1789-2015 (Recommended Practices 1 and 2) allows a low-risk flicker of 0.08 times the frequency in percent, which at 1 kHz is 80 %, so the verify check flicker fails and the notes say so. Set dimFreq to 2k and the reply reads low risk: above 1250 Hz the standard sets no limit, so the same pulses now pass. Dimming above 1250 Hz is the rule; the other way out is analog dimming, below.
apply writes the design into the circuit in one history step, which Edit › Undo takes back.
4. Open the boost driver
Step 4 of 5 · about 1 minChoose File › Open Example › DC-DC › LED driver, boost with analog and PWM dimming.
12 V feeds a boost onto a string of ten LEDs near 33 V, so this one has to step up. A PI loop sets the switch's duty so iled follows the reference Ifull·Adim (Ifull 0.5 A, Adim 0.6). A series switch Sdim cuts the string off between dimming pulses; while it is open the loop's integrator is held and the output capacitor keeps the string's voltage, so each pulse starts at the regulated current. Press F5: the run is 20 ms, four periods of the 200 Hz dimming.
5. Two ways to dim
Step 5 of 5 · about 1 minRead iled in the middle of the last pulse, and its mean over the whole last period (scope.measure).
Adim |
Held current in a pulse | Mean over a period (PWM at 0.5) |
|---|---|---|
| 0.6 | 0.307 A | 0.150 A |
| 0.3 | 0.152 A | 0.075 A |
Change Adim under Circuit › Variables and the current inside each pulse follows it: that is analog dimming, with no flicker added. Change Ddim and the share of time the current flows follows it instead: that is PWM dimming, and the mean is the duty times the held current. Both work together, as the table shows (half the duty on half the current is a quarter of the full current).
The flicker of the PWM part is again 100 %, and at 200 Hz the low-risk limit is 16 %, so for a 200 Hz dimming the current should be dimmed with Adim and PWM kept above 1250 Hz. design.ledDriver {"topology": "boost"} reads this circuit, sizes L1, Cout and the loop gains (with the loop's phase margin against the right-half-plane zero) and, with apply, writes them and checks the mean current by simulation.
Next: the manual lists every field of design.ledDriver.