The LED Driver implementation is fully firmware-based and uses various peripherals of the SAM R21 MCU to drive the LEDs.
Figure 1 shows the block diagram of the scheme used in the implementation of buck LED driver.
The SAMR21 controls the LED peak current using boundary-conduction-mode. The peripherals used for the implementation are:
The event system connects the output of the analog comparator and external interrupt (ZCD). It sends a signal to the timer TCC0 to start or stop the PWM signal for the buck MOSFET depending on the mode-of-transition (high-to-low or low-to-high) of analog comparator output and ZCD signals.
The reference for the peak current is generated using timer TC3. Timer TC3 generates a PWM signal at 10kHz with a desired duty-cycle and the PWM signal is passsed through a low-pass filter to give a DC reference for the analog comparator. The duty-cycle of TC3 is varied to adjust the reference voltage to achieve amplitude dimming.
The LED Driver implementation is available in
\Light\src\LightPwm.c
and corresponding header file.