VDC, depending on the load. Diode
D1 prevents the DC power source
from being connected backwards and
causing damage. The raw DC is sent to
the output section for powering the
LEDs in the display. Two voltage regulators provide 5 VDC for the analog and
TTL circuitry and 3. 3 VDC for powering the MSP430F2012 target board.
On the output side, the
74HCT139 demultiplexes the pulse
width modulation (PWM) signal from
the μC used to control LED brightness.
All four outputs are inverted in preparation for driving the output switching
transistors. NOTE: 74HCT technology
is required for reliably interfacing the
3. 3 volt logic outputs of the μC with
the five volt logic which follows.
Each color channel is driven by a
switching power transistor. Resistors in
each channel limit the current flow to
around 200 mA to equalize maximum
brilliance between channels. Resistor
values in the output channels differ as
a result of the differing forward
voltage drops across the different
colored LEDs. The output transistors
run only slightly warm to the touch so
heatsinks are not required.
There is hardware internal to the μC
used by the color organ. Specifically:
1) A 10 bit analog-to-digital converter
(ADC) is used to digitize the audio
with a sampling rate of 16,000
2) Timer A is used to generate
accurately timed PWM pulses to
control the brightness of each output
3) The watchdog timer functions as a
general-purpose timer to generate
periodic interrupts used to synchronize the display process.
thread, and the display thread. (Consult
the program listing for the details.)
The Main Thread
The main thread starts every time
the μC powers up and performs all
hardware and application initialization
1) Setting up the port bits needed to
drive the output demultiplexer.
2) Setting up the ADC for operation
and configuring a pin on the μC for
3) Setting up the watch dog timer for
generating periodic interrupts.
4) Setting up Timer A for PWM
5) Initializing application variables.
6) Enabling interrupts.
7) Putting the ADC into the automatic
single channel sample acquisition mode.
With initialization complete, the
main thread enters an infinite loop
doing nothing forever.
The Sample Acquisition
and Processing Thread
This is where time-critical activities occur. You can visualize this code
as having one input (the new sample)
and four outputs (the output of the
four color organ channels). This
code runs 16,000 times per second.
Each new sample is subjected to the
• Noise Gate — The noise gate
monitors each newly digitized sample
to make sure it is above a minimum
value before being allowed to pass.
Values smaller than the minimum are
replaced with a zero valued sample.
• Decay Processor — The decay
processor monitors the sample stream
for long runs of zero valued samples.
Two things happen when a lull in the
audio is detected. First, all of the filter
delay elements are reset to terminate
any ringing of the filters and second,
the AGC gain variable is set to unity
(Gain = 0) causing the AGC processor
to restart its gain control function. The
decay processor guarantees the
display goes dark between songs and
in low volume passages.
• The AGC Processor — The AGC
processor is made up of two parts: the
AGC gain control element and the AGC
state machine (SM). The SM can be considered the brains of the AGC processor;
the gain control element, the brawn.
A Gain value of zero indicates
unity gain and the samples flowing
through the gain element are
untouched. Each incremental value of
Gain causes a sample to be left shifted.
If Gain is 4, samples are left shifted four
times for a gain of 16. The AGC manipulates sample amplitude by applying
more or less gain to the samples as they
flow through the AGC Gain element.
There have been many AGC
designs over the years, but I may have
invented a new variety by using a state
machine to control gain. To understand
the operation of the SM in detail,
you should consult the code listing.
Basically, the SM runs every sample
period and has a total of four states. The
SM runs to completion every 1/16th of
a second or every 1,000 samples.
The result of the SM execution is
As you can see, the μC provides
a lot of useful hardware for this
The complexity of this color organ
is in the real-time nature of the software. There are three distinct threads of
execution at work: the main thread, the
sample acquisition and processing
2. 4 kHz
6. 2 kHz
All filters were designed using LWDFDesigner.java, discussed in a previous article.
January 2008 53