Projects — UDP PWM RGB LED Deck Lights — 2009 06 18

I've always been fascinated with LEDs ever since I was a little kid. Finally, I was able to purchase an affordable set of RGB LEDs off eBay. These are basically LEDs mounted on an adhesive strip of plastic that you can attach to whereever you want, and then feed them with 12VDC to light them up. Of course, being RGB LEDs, you can set whatever colour you want!

LED string with full green
LED string with full green

This is a picture of the LEDs on the adhesive strip lying on the floor with full green.

This image is not Photoshopped in any way! The LEDs are so bright that even with the camera's flash the green is still very much visible!

The trick with LEDs in general is that you need to drive them with a variable power source. You could try varying the voltage, but that doesn't work as nicely as using pulse width modulation (PWM). Basically, in PWM, you select a period (let's say 1 millisecond), and during that period you decide what percentage of time the power is on, and therefore what percentage of time the power is off. If you select 50% on and off "duty cycle", then this means that for 500 μs the power is on, and then for 500 μs the power is off. The cycle then repeats, over and over. To get a "dimmer" intensity, simply change the duty cycle so that the on time is shorter; conversly to get a brighter intensity, change the duty cycle so that the on time is longer.

The Hardware

Having purchased the LEDs on eBay, I knew that I'd need:

The power supply was readily available — for $50 or so I obtained a brand new 12V 12.5A (150W) switching power supply.

The main focus of this article is going to be the PWM generator and the computer interface.

PWM is relatively easy to generate (in fact, you can now get microcontrollers that have several PWM ports, but that's not nearly as much fun as building it yourself out of 74LS TTL components). The basic idea is you need an oscillator, a counter, and a magnitude comparator. I decided to use 8 bits. So, the 8 bit counter counts forever, 0..255 and then back to 0 and so on. The job of the magnitude comparator is to see if we're in the "on" part or the "off" part of the duty cycle. The comparator compares two 8-bit numbers, and delivers a "<", "=", or ">" signal as output. We use the "<" output of the comparator to indicate "on" ("off" is implied). If I want a 50/50 duty cycle, then I'd set one set of inputs of the comparator to 128 — this means that all the counts from the counter that are < 128 are "on", and all counts that are >= 128 are "off".

Parts layout for PWM driver for high current LEDs
Parts layout for PWM driver for high current LEDs

Here's the layout for the chips used on the PWM circuit. The module on the left is a really sweet product. It's from Elexol, and it's an Ethernet controllable 24-bit digital I/O port! I use it to supply the three sets of 8-bit values to the comparators (one set for each colour). You simply send it a UDP packet with two bytes — the first byte is the ASCII 'A', 'B' or 'C' character (indicating the I/O port number) and the second byte is the port value. It's that simple.

The chips are, in column order:

3 x 74LS374 Used to capture the 8 bit R, G, and B data
3 x 74LS85 The 4 high-order bits of the three sets of comparators
3 x 74LS85 The 4 low-order bits of the comparators
1 x 74LS04
1 x 74LS393
1 x 74LS175
The LS04 used for clock generation, the LS393 used for the counter, and an LS175 (I replaced the 2 LS74s after this photo was taken with the one LS175 shown in the photo below) used for de-glitching the comparator output
3 x MCP1407 MOSFET drivers
3 x RFP50N06 N-Channel MOSFETs, one for each colour chain.

Compare this picture to the constructed one below to see the power rigging.

Completed layout for PWM driver for high current LEDs
Completed layout for PWM driver for high current LEDs

And this is what it looks like after a few evenings of soldering.

Completed Total Effect
Completed Total Effect

And this is what you can look forward to after all your hard work! Shown here is the chain set to purple. The LED chain runs all along the inside railings of the top deck, and along the bannisters of the stairs, and also in the corner of the stairwell. This picture was snapped with a 4 second exposure (if I recall correctly) and of course a tripod.

Artistic Shot of Total Effect
Artistic Shot of Total Effect

And this is a much more artistic shot showing the lights under the railings. This picture was taken June 21st, hence the 21:40 timestamp on the clock in order to wait for sufficient darkness.

Updates — 2009 06 25

A few days ago, the green MCP1407 driver blew out. Not spectacularly, but it just got quite warm to the touch and stayed "on" regardless of input signal. I replaced it with a socketed one, and added decoupling caps (100 nF and 1 μF) like the app note says to.

I also updated the controller software because I don't like the "linearity" of the intensities. What I mean by that is that if you give the PWM controller the values 1 and 2, well, 2 is obviously twice as bright as 1. But if you give it 255 and 254, 255 is not twice as bright as 254. This means that a lot of the effects that my software generates (like a randomized sine wave through the R, G, B colours) end up being full of white and off-white colours. So, what I did was I added a table of 17 colours:

static int colour17 [17] = { 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 255 };

This was done in order to keep the relative intensity ratios the same between successive steps. (Yes, this limits the number of colours to 173 (4913) but that's fine).

Colour Organ — 2009 07 08

My next project for the lights is to synchronize them to music coming from an MP3 decoder. Initially, I thought I could just run the audio output stream through an FFT, sum up the amplitudes in three bins (red, green, and blue) and display that on the LEDs. Bzzzt, wrong. This turns out to consume tons of CPU and, for the most part, the LEDs are pretty much full on, or very nearly so. The next approach will be to run the audio stream through three band-pass filters (which will consume much less CPU!) and use that as the output to drive the red, green, and blue LEDs. I might need to low-pass filter the outputs of the band-pass filters just to give a smoother output. This is most likely this weekend's research project :-)

Colour Organ — 2015 08 31

Nailed it! See my article, Real Time FFT.