LED dimming using Binary Code Modulation

Summary:

This article has given a brief overview of just a couple of methods of dimming LEDs using microcontrollers. In the lists below, I have summarised points about each method, not to find a 'winner', but to help guide you to which method might be suitable for your application. If you're just dimming a single LED then hardware PWM is probably your best bet. If you want to control five or six RGB LEDs from a single AVR, then I'd suggest Binary Code Modulation as a solution (each colour is a separate channel of output). If you're playing with several hobby servo motors, then Software PWM is probably for you.

Hardware PWM

Software PWM

Binary Code Modulation

It's always difficult/dangerous to simplify and generalise decisions. The correct choice for a given situation will inevitably involve many more factors than I could possibly cover here, but in order to offer some guidance (however mistakenly), here is what I'd choose for controlling LEDs with 8-bit resolution;

Note: Changes:
8th January 2009 -
Modified some details about Software PWM as I think I'd been slightly mislead into believing that S/W PWM is more processor intensive than it is.

Thank you for reading this article. We hope it was useful.

We appreciate any feedback - you can email us here at batsocks.co.uk using our "feedback" email account.

You can find more stuff that we've written in the Read Me section.

The following files are available for download:

Version Date File Size
"LED dimming using Binary Code Modulation" article 2.0 2009-01-08 (PDF file) art_bcm_02.pdf 174.3 kB
1.0 2008-10-25 (PDF file) art_bcm_01.pdf 146.5 kB
example code 1.0 2008-10-25 (.c file) code_art_bcm_10.c 4.2 kB