SDG #016 Designing a Constant Current DC-DC LED Driver - Part 2
Part 2 of this LED driver series moves from hardware to firmware, and it is the stage at which most buck converter projects either come together or fail. The target chip is Microchip’s dsPIC33FJ16GS502, a device aimed squarely at digital power conversion thanks to its high speed PWM module and fast ADC, and the work here focuses on getting those two peripherals cooperating to hold a high power LED at a set current.
The practical value is in the configuration detail. Setting up the high speed PWM means understanding the auxiliary clock and PLL that feed it, choosing a switching frequency and duty resolution that suit the inductor and switch already chosen in Part 1, and ensuring that the ADC sample point is triggered at a sensible moment in the switching cycle rather than in the middle of switching noise. Sampling current at the wrong instant is one of the classic reasons a digitally controlled converter looks unstable on the bench when the power stage is actually sound.
The loop itself then receives attention: reading the current sense feedback, comparing it against a setpoint, and adjusting duty cycle in a way that settles quickly without oscillating or overshooting into the LED. Verification is done on real hardware with an MSO1074Z oscilloscope observing the switching node and current waveform, a bench supply feeding the converter, and a REAL ICE debugger attached so that the code can be stepped and tuned in place using MPLAB X and XC16.
Anyone considering a digital approach over an off the shelf analogue LED driver IC will get a realistic sense of the extra firmware effort involved, and of the payoff in programmable current, dimming and monitoring.


