This is only a preview of the October 2012 issue of Silicon Chip. You can view 21 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "LED Musicolour: Light Up Your Music, Pt.1":
Items relevant to "Reverse Loop Controller For DCC Model Railways":
Items relevant to "The Nick-Off Bad Cat Deterrent":
Items relevant to "Colour MaxiMite Microcomputer, Pt.2":
Items relevant to "Wireless Remote Control For The Barking Dog Blaster":
Purchase a printed copy of this issue for $10.00. |
L i ght up your music with the . . .
LE D
MUSICOL OUR
C
HRISTMAS IS NOT far off so if
you don’t have a light show up
and running already you’d better get
started! Our new LED Musicolour
makes it easier than ever. It drives
up to 16 sets of LEDs directly. These
can be strips, strings, single LEDs or
a set – whatever, as long as they run
off 12-24V DC.
You can even build multiple LED
Musicolours and run them in parallel,
to control 32 or even 64 sets of LEDs.
You can drive the LED Musicolour
30 Silicon Chip
using any line source such as CD or
MP3 player, or you plug in an SD card
which has been loaded with WAV
files. In the latter case, it can be a selfcontained sound and light controller
with no need for any extra hardware
apart from a power supply.
The unit supports high-capacity
SDHC cards so you can load it up with
lots of music (organised in folders) and
use a universal infrared remote control
to skip through them. If you build
more than one, you can use one as the
“master” to play the audio and feed it
to the others for a synchronised light
show, as well as to an amplifier so you
can hear the music at the same time.
The LED Musicolour uses a 40MHz,
16-bit digital signal controller which
is actually a specialised DSP (digital
signal processor) microcontroller. It
is powerful enough to do real-time
frequency analysis using a Discrete
Fourier Transform. The unit also incorporates a Wolfson WM8759 audio
DAC for good-quality line level sound
siliconchip.com.au
Pt.1: By NICHOLAS VINEN
Now you can have a kaleidoscope of colour which continually
changes in time to music. This consists of 16 strings of LEDs which
are individually controlled by 16 frequency bands. Louder signals
in each of those bands means that the respective LED string will be
brighter. Use it for a Christmas light show, a disco or just for fun
when playing music.
output. It all fits into a tiny plastic
case which seems quite innocuous
considering all the fancy processing
it is performing.
Echoes of the past
This unit is intended as an easierto-use version of the DSP Musicolour
which was published in SILICON CHIP
from June-August 2008. It was also
somewhat inspired by the Digital
Lighting Controller featured in the
October-December 2010 issues.
siliconchip.com.au
The Digital Lighting Controller
controls the brightness of up to 32
mains-powered lights or LED strips, in
time to music. But its light sequences
are pre-arranged, ie, you program a
specific sequence to go along with
each sound file. That is a somewhat
laborious process but it gives you full
control over the light show. It has no
option to feed in external audio and
its output sound quality is a bit so-so.
Also, the Digital Lighting Controller
required you to build a master unit
and between one and four slave units,
with one slave controlling eight lights.
The new LED Musicolour, on the other
hand, is fully self-contained and can
control 16 LED strips per unit. And as
explained earlier, you can chain multiple LED Musicolour units together
if you need to control more LEDs.
So to sum up, the LED Musicolour is
more flexible (having an audio input)
and is easier to build and set up but
doesn’t give you quite as much control
as the Digital Lighting Controller from
October 2012 31
8x DUAL N-ch
MOSFETs
–
12/24V LED STRIP
+
+12/24V
Q1a
16-BIT
SERIAL PORT
EXPANDER
(IC5, IC6)
–
12/24V LED STRIP
+
Q1b
(UP TO 16 LED STRIPS)
–
ADC
INPUTS
SPI1
12/24V LED STRIP
+
Q8b
LINE OUTPUT
LINE INPUT
BUFFER
(IC4)
LPF
34kHz
CON11
INFRARED
RECEIVER
(IRD1)
DIGITAL SIGNAL
CONTROLLER
(MICRO + DSP)
(IC1)
24-bit 192kHz
STEREO DAC
(IC2)
2
DCI (I S)
PWM (MCLK)
CON12
SPI2
POWER/ACK
LED (LED1)
SD CARD
(CON13)
CLOCK 4
(IC3)
BCLK
Fig.1: block diagram for the LED Musicolour. At its heart is IC1, a dsPIC33 Digital Signal Controller/Microcontroller.
IC5 and IC6 are used to drive the Mosfets which control the brightness of up to 16 LED strips. Audio can either be fed
in to CON11 or played back from an SD card in CON13, via stereo DAC IC2, to CON12.
2010. Having said that, the LED Musicolour’s light shows are quite impressive and it is much simpler to build.
How it works
Take a look now at the block diagram
of Fig.1. At its heart is IC1, a dsPIC33
digital signal controller (DSC). As
stated above, this is a 40MHz 16-bit
microcontroller and it features a fixedpoint digital signal processing (DSP)
unit and extra features to enhance its
performance, such as multi-ported
random access memory (RAM).
The brightness of the 16 strips of
LEDs is controlled by switching 16
Mosfets at 200Hz, using pulse width
modulation (PWM). IC1 only has 28
pins and that isn’t enough to drive the
Mosfets directly and leave some over
for other purposes. So the Mosfet gates
are driven from the outputs of two
8-bit serial-to-parallel latch ICs (IC5 &
IC6) which act as a port expander. IC1
updates their output state using one of
its internal Serial Peripheral Interface
units, SPI1.
When a given output from IC5 or
IC6 is high, this turns on the corresponding Mosfet, which sinks current
from the negative supply line of the
corresponding LED strip. The positive
supply lines are permanently tied to
the 12-24V supply. By controlling the
proportion of the time that the Mosfet
32 Silicon Chip
is on, we control the average current
through the LED strip and therefore
its brightness.
Audio can be fed into the unit via
3.5mm phono socket CON11. The
audio signals (left & right) are then
AC-coupled to IC4 which buffers them
and applies a DC offset (~1.65V). This
offset is necessary since the circuitry
runs off a single DC supply rail.
Before being fed to IC1, the signals
go through a low-pass filter with a corner frequency of 34kHz. This removes
high-frequency signals which could
cause aliasing when IC1 digitises the
audio at a sampling rate of 48kHz, using its internal 12-bit analog-to-digital
converter.
Alternatively, the unit can play back
the audio from an SD card at CON13.
IC1 reads WAV audio data off the card
using its other SPI peripheral, SPI2. It
then simultaneously analyses the data
to determine the brightness of the LED
strips and sends it to IC2, a stereo digital-to-analog converter (DAC), using
its data converter interface (DCI) unit.
Audio data is transmitted from IC1
to IC2 in I2S format. The DAC also
requires a “master clock” which is a
multiple of the sample clock – in this
case, 192 times. For example, when
playing 48kHz audio, the master clock
is 9.216MHz. This is generated by IC1
using a PWM output, which outputs
a rate proportional to its instruction
clock.
The ratio we are using is 4:1,
which gives an instruction clock of
34-37MHz, depending on the audio
sampling rate. This is derived from an
8MHz crystal by changing the multiplication and division factors of IC1’s
internal phase-locked loop (PLL).
IC3 acts as a clock divider to convert
the master clock (192 times sample
rate) to the appropriate bit clock rate
for the I2S stream. This has a fixed
ratio; we are transmitting 48 bits for
each sample (24 per channel) which
means we need a division ratio of
192 ÷ 48 = 4. This bit clock is fed to
both IC1 and IC2. The audio from IC2
is AC-coupled to CON12, a 3.5mm
phono socket.
If you want to control the LED Musicolour with an infrared remote control,
which is handy when playing back
WAV files (but not strictly necessary),
the commands are received by IRD1
and sent to IC1 which decodes them.
The Power/Ack LED (LED1) flashes in
response; it is normally lit while the
unit is powered, to indicate that it is
operating.
Circuit description
Refer now to Fig.2 for the full circuit
details. As shown, IC1 sends serial
data to and controls shift registers IC5
siliconchip.com.au
LED Musicolour Parts List
1 PCB, code 16110121, 103 x
118mm
1 front panel, code 16110122,
134.5 x 30mm
1 rear panel, code 16110123,
134.5 x 30mm
1 instrument case, 140 x 110
x 35mm (Jaycar HB5970,
Altronics H0472)
1-16 12V or 24V LED strips with
2-pin or 4-pin sockets
1 12V or 24V DC power supply
sufficient for LED strips
1 SD or SDHC card (optional)
1 universal infrared remote control
(optional) (eg, Jaycar AR1726,
Altronics A1012)
2 PCB-mount M205 fuse clips
(F1)
1 10A M205 fuse (F1)
8 8-pin dual row right-angle pin
headers, 2.54mm pitch (may be
snapped from larger headers)
(CON1-CON8)
1 PCB-mount DC socket (CON9)
1 2-way right-angle pluggable
terminal block (CON10)
2 PCB-mount switched 3.5mm
phono sockets (CON11,
CON12)
1 Oupin SMD SD card socket (or
equivalent) (CON13) (Altronics
P5720)
& IC6 using four data lines: DS (serial
data), SRCK (serial clock), LCK (latch
control) and MR (master reset). While
microcontroller IC1 runs off 3.3V, IC5
and IC6 run off 5V, to drive Mosfets
Q1a-Q8b with sufficient voltage to
switch them on.
Unfortunately, a 74HC595 with a
5V supply will not work reliably with
3.3V input signals (according to the
data sheet), so these signals need to
be level shifted to 5V. For SRCK, DS
and LCK, the corresponding IC1 pins
(RB8, RB6 & RB5) are set as open drain
outputs. These pins are 5V tolerant and
with 1kΩ pull-up resistor to +5V, they
can operate to at least 1MHz.
For MR, we have used a different
arrangement as we want this line to be
low by default, keeping the outputs of
shift registers IC5 and IC6 off until IC1
brings it high. NPN transistor Q9 acts
as an inverter/level shifter; the 100kΩ
pull-up resistor between its base and
siliconchip.com.au
1 8MHz HC-49 crystal (X1)
1 6073B type TO-220 heatsink
(Jaycar HH8502, Altronics
H0630)
1 M3 x 6mm machine screw
1 M3 x 10mm machine screw
2 M3 shakeproof washers
2 M3 hex nuts
4 No.4 x 9mm self-tapping
screws
1 28-pin narrow IC socket
1 8-pin IC socket (optional)
1 14-pin IC socket (optional)
2 16-pin IC sockets (optional)
Semiconductors
1 dsPIC33FJ128GP802-I/SP
microcontroller programmed
with 1611012A.hex (IC1)
1 WM8759 24-bit 192kHz
stereo DAC (IC2) (Element14
1776274)
1 74HC393 dual binary counter
(IC3)
1 LM358 dual op amp (IC4)
2 74HC595 serial-to-parallel shift
registers (IC5, IC6)
8 Si4944DY dual SMD Mosfets
(or equivalent) (Q1-Q8) (Jaycar
ZK8821)
1 BC547 NPN transistor (Q9)
1 BC327 PNP transistor (Q10)
1 7805T 5V 1A regulator (REG1)
collector holds it on when IC1 is not
driving it.
IC5 and IC6 drive the Mosfet gates
via 100Ω series resistors which form
low-pass RC filters in conjunction with
the Mosfet gate capacitances (about
1nF each). This prevents oscillation
and overshoot when switching on or
off, due to copper track inductance.
We are using eight dual-Mosfets to
keep the cost and size down. Each can
switch up to 9.4A at 30V.
The LED strings are connected to a
series of 4-pin headers. Their outer two
pins are connected to the high side of
the supply (12-24V) and the inner two
to the Mosfet drain. That way, you can
plug the LED strip connector in either
way around and it will still work. It
also gives more contact area to safely
allow up to 2A per LED string.
Audio inputs
Turning now to the audio inputs,
1 LM3940IT-3.3 3.3V LDO
regulator (REG2)
1 1N4004 1A diode (D1)
4 BAT85 small signal Schottky
diodes (D2-D5)
1 green 3mm LED (LED1)
1 3-pin infrared receiver (IRD1)
(Jaycar ZD1952, Altronics
Z1611A)
Capacitors
1 220µF 25V low-ESR
electrolytic
2 220µF 16V electrolytic
5 100µF 25V electrolytic
4 10µF 16V electrolytic
1 10µF 6V SMD ceramic (3216)
13 100nF MKT or MMC
2 10nF MKT or MMC
2 100pF ceramic
2 33pF ceramic
Resistors (0.25W, 1%)
2 1MΩ
6 1kΩ
2 120kΩ
2 470Ω
3 100kΩ
1 220Ω
3 47kΩ
19 100Ω
5 10kΩ
1 10Ω
1 4.7kΩ
Note: the PCB and front & rear
panels are available from the
SILICON CHIP PartShop.
the left & right channel signals from
CON11 first pass through low-pass
RC filters consisting of 100Ω resistors
and 100pF capacitors. These filters
prevent RF (radio frequency) signals
from entering the device. There are
also 1MΩ bias resistors in case the
source’s output is AC-coupled. The
value of these resistors can be lowered
if you want to feed in the output of an
iPod, eg, to 1kΩ each.
The signals are then AC-coupled by
100nF capacitors to a resistive divider/
DC bias network. This forms a highpass filter with a -3dB point at 7Hz. It
also sets the input impedance of the
device to 1MΩ || 220kΩ = 180kΩ.
The 100kΩ/120kΩ dividers allow
an input signal of up to 2.2V RMS before clipping. The signal fed into IC1
is limited by its supply rails to 3.3V
peak-to-peak. This translates to 3.3V
÷ (2√2) = 1.17V RMS. However, many
CD/DVD/Blu-ray players, computers
October 2012 33
F1 10A
12/24V DC (3A MAX)
D1 1N4004
A
CON9
K
12/24V DC
10A MAX
2
+12/24VF
REG1 7805
+5V
OUT
IN
REG2 LM3940IT-3.3
GND
100F
IN
GND
100F
1
+3.3V
OUT
100F
220
CON10
100nF
+5V
2
K
D2
100nF 100k
1M
100pF
100nF
RB6
2
8
2
470
1
IC4a
RchIn
RA4
LINE
INPUT
6
RB7
1.65V
100F
CON11
1M
100pF
6
K
D5
D3
A
24
25
5
K
23
IC4: LM358
100nF 100k
7
22
10k
120k
100
+3.3V
LchIn
IC4b
4
7
470
LCK
12
MR
1k
AN4/RB2
RB9
10k
14
IC1
dsPIC33FJ128GP802
10nF
120k
SRCK
DS
RA1
Vcore/Vcap
A
3
17
15
RA0
10F
D4
A
RB8
RB5
20
K
Vdd
LED1
K
1k
100nF
13
MCLR
ON/ACK
3
D2–D5:
BAT85
28
AVdd
1
1
100
100F
3
10k
A
100
IR
RECEIVER
IRD1
1k
100nF
26
RB4
AN5/RB3
MCLK
18
LRC
11
SD
21
BCK
RB10
RB11
RB1
RB12
RB0
RB13
RA3/OSC2
RB14
RB15
RA2/OSC1
AVss Vss
8
27
10nF
16
5
DACEN
4
SDpwrCon
10
X1
8.0MHz
9
Vss
19
33pF
33pF
A
GND ANALOG
GND
+3.3V
SD CARD SOCKET
WP
8
7
6
5
4
3
2
1
9
47k
DATA OUT (from card)
CLK
Q10
BC327
10
DATA IN (to card)
E
B
4.7k
C
10k
CS
10F
CD
47k
100nF
CON13
SC
2012
LED MUSICOLOUR
Fig.2: the LED Musicolour circuit diagram. Audio fed into CON11 is filtered, AC-coupled, attenuated, buffered and
filtered again before passing to IC1’s internal ADC. IC1 communicates with IC5 & IC6 via a serial (SPI) bus and these
ICs drives Mosfets Q1a-Q8b. Another SPI bus is used to read/write the SD card in CON13 while a similar I2S serial bus
is used to send audio data to stereo DAC IC2. IC3 ensures that the DAC’s master clock (MCLK) and serial data bit clock
(BCK) are synchronised.
and so on will put out 2V RMS or more.
So we attenuate the signal by a factor
of 120kΩ ÷ (100kΩ + 120kΩ) = 0.55 to
allow for this.
The bottom end of these resistive
dividers is connected to a half-supply
point of about 1.65V, derived using two
34 Silicon Chip
10kΩ resistors and filtered by a 100µF
capacitor. The signals fed to analog
input pins AN4 and AN5 of IC1 thus
swing symmetrically around its halfsupply point. Op amps IC4a & IC4b
buffer the input signal so that the following RC low-pass filter (470Ω/10nF)
does not load up the signal source or
previous stages.
Schottky diodes D2-D5 protect the
inputs of IC4 from going outside its
supply rails when the unit is not powered. While not strictly necessary, this
makes the circuit more “bulletproof”.
siliconchip.com.au
+12/24VF
+5V
CON1a
4
3
1k
12
11
14
13
16
Vdd
LCK
Q1
SRCK
Q2
Q3
DS
Q5
OE
Q6
MR
Q7'
Q7
10
Vss
C
E
15
Q9
BC547
1
G
3
11
14
13
10
LCK
G
D
Q2a
+5V
S
CON7b
CON7a
CON8b
CON8a
4
3
+12/24VF
1
2
LEDs14
Q0
15
TO
Q5a,
Q5b,
Q6a,
Q6b
1
2
3
IC6 Q4 4
74HC595
5
Q6
Q7
Q7'
S
S
S
S
6
1
7
O3
CP
O2
IC3a
8x100
2
O1
MR
O0
6
13
5
4
12
3
14
1
2
3
4
O1
O0
8
9
10
100nF
11
1N4004
IRD1
LRCIN
DIN
1
2
K
3
A
IC2
WM8759
EN
CAP
HPOUTL
DEEMPH DGND AGND
12
10
7
Audio outputs
As explained earlier, the master
clock for DAC IC2 (ie, from output RB7
5
220F
10F
100nF
BC327, BC547
D2 D2
D1
D1
ous sub-harmonics being detected.
The filters (mostly) prevent that from
happening.
LINE
OUTPUT
9
Si4944DY
G2
G1S2
S1
220F
6
HPOUTR
BKIN
LED1
K
8
AVdd
11
DVdd
FMT
10F
100nF
100nF
MCLK
47k
siliconchip.com.au
IC3b
MR
O2
+5V
13
The low-pass RC filters following
IC4a & IC4b both have a -3dB point of
34kHz and are tuned to the sampling
rate of IC1’s ADC (48kHz). If there is
much signal above the Nyquist frequency (48kHz / 2 = 24kHz), this can
cause aliasing which results in spuri-
O3
CP
7
10F
K
+5V
IC3: 74HC393
+3.3V
A
LOW ESR
Q8b
G
Q1-Q8: Si4944DY
DUAL MOSFET
Vss
8
BAT85
220F
25V
D
Q8a
14
9
7
D
Q7b G
G
LEDs15
5
8
D
Q7a
G
3
LEDs16
6
7
8
1
2
4
LEDs13
5
D
Q5
A
Q2b
G
S
TO Q3a, Q3b,
Q4a & Q4b
9
Q3
MR
Q1b G
6
Q2
OE
7
D
D
LEDs3
5
8
7
Q1
DS
3
LEDs4
6
S
6
SRCK
1
S
100nF
12
4
7
Q1a
CON2a
2
LEDs1
5
D
2
8
16
Vdd
LEDs2
8
IC5 Q4 4
74HC595
5
10k
100k
Q0
6
8x100
CON2b
1
2
+5V
100nF
B
CON1b
1k
1k
7805, LM3940IT-3.3
B
E
C
CON12
GND
IN
GND
OUT
of IC1) is generated by a PWM peripheral which divides IC1’s instruction
clock by four. This is fed to IC2 and
also to IC3a’s CP-bar clock input (pin
1). Its O1 output is one-quarter of the
input frequency and this is the audio
data bit clock, BCK. BCK is fed to both
October 2012 35
Specifications
•
•
LED voltage: 12-24V DC
LED current: up to 10A total (ie,
120-240W maximum)
•
Number of LED strings: up to 16
per unit
•
LED control method: PWM,
200Hz, 255 brightness steps
•
LED connectors: 2-pin or 4-pin
male headers, 2.54mm pitch
•
Audio input: 0.5-2.2V RMS nominal, 180kΩ || 100pF input impedance
•
Audio output: 1.1V RMS, THD+N
0.004%, signal-to-noise ratio 100dB
•
Audio file support: 8-48kHz 16-bit
mono or stereo WAV files
•
Maximum directory depth: eight
levels
•
•
Maximum files per directory: 100
•
•
•
Dimensions: 140 x 110 x 35mm
Control method: universal infrared
remote (optional)
Supply voltage: 12-24V DC
Current drain: ~110mA at 12V
IC1 & IC2, which use it to send and
receive the audio data respectively.
IC3a’s O3 output (1/16th MCLK) is
connected to input CP-bar of IC3b, the
other half of the dual binary counter.
This is for testing purposes; the IC3b
outputs give various frequencies related to the sampling rate being used.
For example, with a 48kHz sampling
rate, pin 9 of IC3 (O2) will measure
72kHz (48kHz x 1.5) and pin 8 (O3)
will measure 36kHz (48kHz x 0.75).
The I2S data stream from IC1’s DCI
peripheral comes from pins RB9 (LRC)
and RB4 (SD). LRC is the left/right
clock and represents the sampling
rate (eg, 48kHz). It is produced by the
data framing output of the DCI module. SD is the serial audio data and
this is clocked according to the signal
received at its RB10 input (pin 21).
By default, IC2 is in standby mode
as its enable pin (pin 4) is pulled to
ground by a 47kΩ resistor. When IC1
is transmitting audio, it brings output
RB1 (pin 5) high, pulling IC2’s enable
pin high and thus turning on the DAC.
IC2 has a pair of bypass capacitors
(MKT and electrolytic) between each
pair of supply pins, digital (DVDD/
GND) and analog (AVDD/AGND).
36 Silicon Chip
Its format input (pin 13) is tied high
to 3.3V, setting it to I2S mode. Its
DEEMPH input (pin 12) is low since
we don’t need digital de-emphasis. A
pair of capacitors between its CAP pin
(pin 5) and AGND filter its internal
half-supply rail.
Audio is available at HPOUTL (pin
9) and HPOUTR (pin 6). These signals
are AC-coupled using 220µF electrolytic capacitors, as IC2 can drive loads
down to 16Ω. The 1kΩ DC bias resistors set the average output level to 0V.
SD card interface
The SD card interface is quite simple
and is a tweaked version of the same
interface we have used in the past.
Microcontroller input RB11 (pin 22) is
connected to the socket’s Card Detect
line which is pulled to ground when
a card is inserted. IC1’s weak internal
pull-up is enabled for RB11, allowing
it to sense when this occurs.
The SD card is operated in 1-wire
mode and IC1’s SPI2 unit is used to
send and receive data. This is mapped
to pins RB15 (pin 26, card select), RB14
(pin 25, data to card), RB13 (pin 24,
serial clock) and RB12 (pin 23, data
from card). The card select (CS) and
data from card (DATA OUT) lines are
pulled up to VDD to prevent any card
operations from occurring when IC1
is reset or being programmed.
The SD card’s VDD line is not connected directly to 3.3V but rather
switched by PNP transistor Q10,
which is controlled by output RB0
(pin 4) of the micro. This allows it to
turn power on for the card only after
it has been inserted.
The associated 100nF and 10µF capacitors bypass the SD card’s supply,
while a 10Ω series resistor prevents
excessive current from being pulled
from the 3.3V rail when the SD card
is first powered up. A 47kΩ bleeder
resistor shunts any leakage from Q10
so that the supply bypass capacitors
don’t charge up when it is off.
Remaining parts
Infrared receiver IRD1 detects IR
pulses from the remote and converts
them into digital signals which it sends
to input RA1 (pin 3) of IC1. IC1 then
uses a pin-change interrupt handler
routine to decode the Philips RC5coded transmissions. IRD1 is powered
from a 5V supply which is filtered using a 100Ω series resistor and 100µF
and 100nF capacitors.
IC1 has two 100nF supply bypass
capacitors, for its 3.3V VDD and AVDD
lines, plus a 10µF capacitor on the
output of its internal 2.5V regulator at
pin 20 (VCAP). A 10µF SMD monolithic
ceramic capacitor is the preferred type
here, as it has good performance and a
long life. A 10µF through-hole tantalum capacitor could also be used and
this is catered for in the PCB design.
Power indicator/acknowledge LED1
is switched from output RA0 (pin 2) of
IC1. It’s fed via a 220Ω series currentlimiting resistor, giving a LED current
of around 5mA when it is on, ie, when
RA0 is driven low.
Power supply
The incoming 12-24V DC supply is
applied to either DC socket CON9 (up
to 3A) or to pluggable terminal block
CON10 (up to 10A). The positive line is
fed to the 16 LED strips via a 10A fuse,
while a 220µF low-ESR electrolytic
capacitor prevents the supply voltage
from drooping too much when the
LED strips are switched on in unison.
Current also flows from CON9/
CON10 to 5V regulator REG1 via reverse polarity protection diode D1.
The 5V output from REG1 powers
infrared receiver IRD1, buffer op amp
IC4, serial latches IC5 & IC6 and the
analog section of DAC IC2.
REG2, 3.3V low-dropout regulator,
is also fed from 5V and supplies power
to the remaining components: microcontroller IC1, clock divider IC3, the
SD card (via transistor Q10), LED1 and
the digital section of DAC IC2.
It also acts as the half-supply bias
generator for the analog inputs (IC4a
& IC4b).
Software
For those interested, the source code
will be available for download from
the SILICON CHIP website. We won’t go
into detail here but will just give some
basic information on its operation.
IC1 only needs to shift one word of
data (ie, 16 bits) to IC5/IC6 in order to
update the state of all LED outputs. IC5
and IC6 are cascaded, with IC5’s Q’H
output going to IC6’s serial input. This
is triggered off one of IC1’s internal
timers that is set to a rate of 200Hz.
When the timer interrupt occurs,
the SPI1 peripheral is used to shift a
new word to IC5 & IC6, turning on any
LEDs that have a brightness above zero.
A second timer is then set to generate
an interrupt at the time when the dimsiliconchip.com.au
The 16-channel outputs from the unit are connected
to the coloured LED strings via 4-way pin headers
(two pins for the positive rail and two for the switched
negative rail). All parts are on a single PCB, with no
external wiring (apart from the LED strings).
mest LED strip needs to be turned off
for the correct duty cycle; this delay is
calculated as 5ms x (duty cycle) ÷ 100.
When this second interrupt is triggered, the handler routine turns off
that LED strip and any others with an
identical brightness, then re-schedules
the timer for the next dimmest LED
strip and so on. As a result, depending
on the exact brightness value for each
LED output, up to 200 x 16 = 3200
interrupts per second are needed to
control the LEDs. Thus the overhead
is relatively low, given that IC1 runs
at around 35MHz.
The LED brightness is updated
for every 1024 audio samples. A 1k
Fast Fourier Transform (FFT) is then
applied, with a Blackman-Harris
window, to convert the time domain
data to the frequency domain. The
magnitudes of the resulting vectors
are calculated, giving the frequency
content for each bins and the bins are
siliconchip.com.au
averaged in bands to give the brightness values for the LED outputs.
Audio playback
Since IC2 (the stereo DAC) has no
volume control, we need the ability to
digitally attenuate the audio data sent
to it. Thus, we send 24-bit audio data,
even though the WAV files only store
16-bit samples. They are converted
to 24 bits by multiplying them by the
8-bit volume level.
For 48kHz audio, IC1’s internal
clock is set to 36.857MHz using its
PLL (8MHz x 129 ÷ 28). MCLK is set
to this frequency divided by four, ie,
9.214MHz and BCLK = 9.214MHz ÷ 4
= 2.304MHz. This is the rate at which
audio data is serially transmitted to
DAC IC2.
The DCI (data converter interface) is
set to I2S mode with 24 bits per sample,
giving us a sample clock (LRCK) of
2.304MHz ÷ 24 ÷ 2 = 47.991kHz, which
is very close to the target of 48kHz.
Getting the DCI to transmit 24-bit
data is a little tricky since it works with
16-bit words. We set it to transmit two
12-bit words per sample and the audio
data is stored in memory in 32-bit
chunks, with eight bits of each unused.
The rest of the software is fairly
straightforward and involves the reuse of much of our existing dsPIC33
codebase, including the SD card interface, FAT16/32 file system layer,
interrupt-based infrared protocol decoding and so on. Besides the LED strip
control, the main area of new code for
this project is the audio playback layer
which has been enhanced to support
WAV files residing in multiple folder.
It also supports folder hierarchies
several levels deep.
That’s all we have space for this
month. Next month, we will describe
the assembly and show you how to
SC
drive it.
October 2012 37
|