This is only a preview of the October 2010 issue of Silicon Chip. You can view 27 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. Items relevant to "A High-Quality DAB+/FM Tuner, Pt.1":
Items relevant to "Digital Controller For Christmas Light Shows":
Items relevant to "Two Toslink-S/PDIF Audio Converters To Build":
Articles in this series:
Items relevant to "Build A GPS Boat Computer":
Purchase a printed copy of this issue for $10.00. |
BUILD IT NOW IN TIME FOR
YOUR CHRISTMAS EXTRAVAGANZA!
DIGITAL
LIGHTING
CONTROLLER
Part 1 – by
Nicholas Vinen
and Jim Rowe
Want one up on your neighbours? Instead of a static Christmas
Lights display (so passé!) now you can have the ultimate in
Christmas extravaganzas. This amazing controller will bring your
Christmas lights to life, making them flash, dim up and down, you
name it, all in time with your favourite Christmas music. It’s easy to
build, easy to connect and, best of all, easy to program!
O
K, we have to admit it. We
first had this idea after watching Chevy Chase’s “Christmas
Vacation”. Then it was given further
impetus by a YouTube clip we saw a
couple of years ago. It’s taken a while
to put the idea into practice!
You’ve probably seen the clip we’re
talking about. Just one version of it
has had nearly seven million hits!
But if you haven’t and/or if you’d
like to see the inspiration – and get
some idea of what this will do for
you, check out www.youtube.com/
watch?v=rmgf60CI_ks (or simply en36 Silicon Chip
ter “Christmas Lights” on YouTube).
Actually, we lie: we’re pretty sure
that controller only had about 12-16
channels. Ours has up to 32, so you’ll
be able to put that to shame.
Just imagine the neighbours – they’ll
be as amazed as everyone else who
stops to admire your handywork this
festive season.
There are certainly some amazing
displays this time of year. But for the
most part, they’re static. Most don’t
DO anything except look pretty. With
this controller, yours can look pretty
AND look spectacular at the same time.
We know that quite a number of
readers have used SILICON CHIP’s DSP
Musicolour Lightshow (June-September 2008) to control their Christmas
Lights, flashing them in time with
music. That’s fine, of course, if all you
want is flashing lights.
Like the Musicolour, this unit has
multiple high-current Triac outputs
capable of phase-based brightness
control. But that’s where the similarities end. With this new controller (or
more properly called a sequencer) you
can program in specific lighting patterns and movements, similar to the
siliconchip.com.au
MAINS IN
CAT5
CABLE
INFRARED
RECEIVER
MAINS IN
(OPTIONAL)
1-3 SLAVE
UNITS
SLAVE UNIT
(8 TRIAC OUTPUTS)
dsPIC33FJ64
GP802
MICROCONTROLLER
(IC1)
SD/MMC
CARD
RJ-45
JACK
RJ-45
JACK
MAINS-POWERED
LIGHTS
AUDIO FILTER
(IC2)
ZERO-CROSSING
DETECTOR
RJ-45
JACK
MAINS-POWERED
LIGHTS
Fig.1: the block diagram showing
how both master and slave units
operate. The master unit plays the
music and sends commands to the
slaves which in turn control the
lights. An infrared remote can be
used to control the whole lot.
LINE LEVEL
STEREO AUDIO
OUTPUT
AC-TO-DC
REGULATED
POWER SUPPLY
9V AC
PLUG PACK
YouTube clip above.
We decided that for this application,
rather than attempt to synchronise the
light show with music being played
from another source, it would be best
to have the Controller itself play the
music AND sequence the lights. This
makes for a self-contained project
which will always keep the light sequence strictly in time with the music.
The hardware
The hardware is split into two sections. One is a small plastic box containing the master unit while a larger
instrument case houses the slave unit.
Between one and four slave units, each
of which controls up to eight channels,
can be connected to the master.
The master unit, which is controlled
via a hand-held remote, plays the music and a sequencer file (which you set
up) from an MMC (MultiMedia Card),
SD (Secure Digital) card or SDHC (high
capacity) card. It sends serial commands to the slaves via a Cat5/6 cable
with up to 30m between the units.
Splitting the project into two parts
has two advantages. Firstly, only the
slave units contain mains wiring,
making it easier to build them safely.
Secondly, you can build the number of
outputs you need. One slave with eight
channels will drive a small light show
while four slaves, totalling a whopping
32 channels, will create a lighting
RJ-45
JACK
spectacular worthy of a Broadway hit!
Each slave has eight mains output
sockets but you can use as many or as
few of these as required.
While each of the eight slave channels can drive lights up to 1200W at
230V AC (5A), the total amount of
power allowed per slave unit is 2300W,
limited by the 10A input socket and
fuse. The power figures are halved for
115V AC mains.
Since we have designed this project for use anywhere in the known
universe, mains supply frequencies of
50Hz and 60Hz are supported.
Because the slave power limit is
2300W, if you are using all eight
channels with identical lights, the
The master controller fits into the
smaller box on top, while each 8-channel slave unit
requires the larger case below. Up to four slaves can be connected.
siliconchip.com.au
October 2010 37
Features
Audio THD+N..............................0.06%
Audio Signal-to-Noise Ratio.......65dB
Audio sample rates (kHz)...........11.025, 12.0, 22.05, 24.0, 32.0, 44.1, 48.0
Audio file formats.......................WAV format, 16 bit PCM, mono or stereo
Music capacity............................At least 4GB (ie, more than six hours at CD quality)
Playback order............................By directory order, alphabetically or random (shuffle)
Number of light “channels”.......32 (max. 4 slaves = 32 channels)
Light power per channel.............25-1200W (230V AC) or 12-600W (115V AC)
Total light power (four slaves)...9200W (230V AC) or 4600W (115V AC)
Extra features..............................Remote control, Filament preheat, Volume control
Infrared formats supported.........Philips RC5 12-bit, NEC 16-bit
maximum power per channel would
be 287W (1.25A).
We don’t believe that will normally
be a problem because (a) most Christmas Tree “bud” light strings are only 1050W or so and (b) even PAR38 coloured
floodlights are usually only 100W.
The 1200W per channel figure is
only possible if some channels are left
unused or have lighter loads.
If you wanted to run four slave units
giving up to 32 channels, you could
do so by spreading them over separate
same-phase mains circuits, each of
which is normally limited to 15A.
That does NOT mean running four
slaves from the one powerboard or
double adaptors! (Don’t laugh – we’ve
seen much worse . . .)
While a personal computer is used
to initially set up the music files and
sequences, no PC is required for playing the music or controlling the light
sequence. This results in a simplified
set-up with increased safety and less
power consumption.
The music output
Finally, the master unit also has a
line-level audio output to drive virtually any amplifier, perhaps with outdoor speakers so everyone can enjoy
the music and lightshow.
Perhaps your neighbours may not be
too happy for you to set up loudspeakers playing Christmas music continuously along with your light show (bah,
humbug!).
As suggested by a reader last month,
one clever solution is to wire up a
small FM transmitter (build from a kit
or purchased as a retail device) so that
people can tune in and listen in their
cars or even their mobile phones while
watching the show.
A sign out the front could say “to listen in, tune your car radio to 88.X MHz”
(or something similar). Just make sure
you don’t pick a frequency occupied
by an FM radio station in your area!
Apart from Christmas Lights?
This project isn’t just limited to a
Christmas Light application.
It can be used any time that you want
lights to be controlled synchronously
with audio. For example it could be
used in a museum exhibit, where pressing a button activates narration explaining the exhibit while the appropriate
sections are lit up in turn.
Or it could be used as part of an art
project, where music and/or narration/
music/sound effects are accompanied
by different sections being illuminated
Here’s the main sequencer unit with
DC power input, infrared receiver, data output socket,
SD/SDHC/MMC card reader (under PC board) and at right, the
3.5mm audio output socket. Full construction details will appear next month.
38 Silicon Chip
siliconchip.com.au
or devices powered up and down.
Another suggestion is to provide
mood lighting or even to switch lights
on and off over the course of a day when
you are away from home, so that it looks
like somebody is still there.
Not only will you achieve a much
more realistic light pattern than with
a switchboard (the usual method), you
can also have music playing to make
you home look really occupied!
We’ve designed the switching so
that theoretically other mains devices
(eg, small motors, etc) can also be controlled but of course, if this is done,
“dimming” via phase control must not
be attempted! It really is intended to be
used with resistive loads, à la lights.
How it works
Refer to Fig.1, the block diagram.
At the heart of the project is the
dsPIC33FJ64GP802 microcontroller
from Microchip. It has 64KB of FLASH
program memory, 16KB of RAM (random access memory) and will processs
up to 40 MIPS (millions of instructions
per second).
This IC is responsible for controlling all the functions of the sequencer,
including music playback and Triac
triggering/phase control (see panel).
During a light show, the dsPIC chip
reads one WAV audio file at a time from
the attached MMC/SD/SDHC card and
plays it back using its internal digitalto-analog converter (DAC). The output
of the DAC goes through a filter which
removes some of the digital noise.
The resulting signal level is around
1V RMS, which is compatible with
most amplifier “aux” (line level) inputs.
As well as a hifi/stereo power amplifier,
it could be connected to an FM transmitter, headphone amplifier, mixer, etc.
Power for the master module comes
from a 9V AC plugpack. There are two
reasons why we are using an AC plug-
pack rather than DC.
Firstly, we need to know when the
mains zero-crossing events occur to
enable phase control of the lights, for
brightness adjustment.
Secondly, this makes it easy to
generate balanced supply rails for the
audio filter op amps. A higher voltage
plugpack cannot be used as that risks
exceeding the op amp supply ratings.
The power consumed from the
plugpack depends upon how many
slave modules are connected and the
specifics of the light sequence but as
a rough guide, with one slave module
and eight active light channels it can
be expected to be below 250mA/2.5W.
The zero-crossing detection is done
by IC1’s internal comparator. This
compares a reduced amplitude signal
from the plugpack AC output to a halfsupply rail, resetting a timer each time
they cross.
By measuring how long this timer
Inside one of the slave units.
It’s basically a mains
switching box, under the
control of the signals sent
by wire from the master
sequencer unit. Each of the
eight channels has its own
Triac with interference
suppression and an IEC
mains output socket.
Front panel LEDs
can mimic the
mains output.
siliconchip.com.au
October 2010 39
runs, IC1 can determine the mains
frequency (50Hz or 60Hz). It needs
to know this in order to convert the
desired phase angle for each light to a
time delay for Triac triggering.
D3
9V
AC
IN
A
User interface
The behaviour of the master module
is controlled in two ways. Firstly, its
default setting are specified in the optional configuration file which is stored
on the MMC/SD/SDHC card.
This allows you to determine
whether the music files are played
40 Silicon Chip
OUT
IN
REG2 LM3940T
+6V
GND
2200 F
16V
CON1
IN
+3.3V
OUT
GND
100 F
100 F
D1
Synchronised sequence
playback
When the microcontroller opens a
WAV file for output, it also looks for a
file with the same name but a different
extension (.lsq). This file contains the
light sequencing information which
you have prepared to demonstrate your
lighting brilliance (OK, pun intended!).
It is processed at the same rate as
the WAV file is played so that they
remain synchronised. The information
it contains indicates when to switch
lights on and off, when to change
their brightness and what the new
brightness settings are – either a fixed
percentage of full brightness or indeed
fading up/down.
At the appropriate times during each
mains half-cycle, IC1 sends serial data
out over the RJ45 jack connection. This
is carried to each slave module in turn,
where the serial data is latched and
used to determine which Triacs to trigger. As a result, IC1 controls the lights
in each slave module as determined
by the sequence file.
This sequence file is generated with
the Windows software we have developed, which will be available from the
SILICON CHIP website next month (at the
same time as the article containing the
construction details).
We will also provide source code
for this software for any users who are
interested in porting it to other operating systems like Mac OS X or Linux.
The light sequence can be generated
manually, by using the GUI to indicate
at which point in the music to change
the output light states.
Or, to save time, the control for some
light channels can be automatically
derived from the music itself over a
given time period, with adjustable parameters to determine how it behaves.
The result can be used as-is or can be
further edited to your satisfaction.
REG1 7806
K
A
V+
K
+6V
470 F
25V
470 F
25V
D2
K
+3.3V
A
10k
3k
V–
27k
4.7 F
28
AVdd
1nF
4
Vdd MCLR
RB2/AN4
RB0/AN2
RB3/AN5
NP
3.0k
3k
390
D4
K
A
RB4
RB5
10k
RB7
IRD1
100nF
3
5
1
3
RA0/AN0
Vdd
15
SD CARD
SOCKET
17
18
+3.3V
CLK
21
DATA OUT
22
100nF
RB5
SC
100
3 x 100
14
16
2
23
DAC1R+
RB6
DAC1R–
RB8
RB9
24
10k
10k
10k
10k
Vcap 20
RB10
CLK1
RB11
27
Vss
8
9
X1
24.576MHz
CLK0
10
Vss
19
33pF
CON4
2010
11
26
DAC1L–
AVss
WP
7
IC1
dsPIC33FJ64GP802 DAC1L+ 25
12
CS
DATA IN
6
RA1/AN1
47k
CARD DET
CD
100nF
RB1/AN3
2
10k
100nF
1
13
33pF
DIGITAL LIGHTING CONTROLLER – MASTER UNIT
Fig.2: the master unit circuit. At its heart is IC1, a dsPIC running at around
40MHz. IC2 provides gain and filtering for the audio output. Communication
with slave units is via CON3 while the music and sequence data are read from
the card plugged into CON4.
back in order or randomly, which file
to start with, whether playback starts
immediately when power is applied or
must be triggered manually and several
other options which control the slave
unit behaviour (more on those later).
Further control of the master module
is made via the infrared remote control.
Available functions include stopping,
starting and pausing playback, changing audio tracks, adjusting the volume,
playing a specific track, changing the
playback order and so on.
The default remote control codes
are set up to suit common universal
remotes but they can also be changed
using the configuration file.
Cabling
We chose Cat5 cable to connect the
slave modules because it is readily
available in a variety of lengths, can
be made to length, has an appropriate
number of conductors (eight) and is
weatherproof.
This should enable constructors to
easily connect multiple slave modules
in different locations, to control a large
array of lights.
Because the serial data is buffered by
each slave module, this does not limit
the total cable length and so 30m cable
siliconchip.com.au
+3.3V
TO
SLAVE
MODULE(S)
1
2
3
4
5
6
7
8
V+
+6V
10k
CON3
RJ-45
10k
220
A
LED9
K
IC2: TL072
3
2
8
10 F
1
IC2a
13k
150pF
10k
15nF
10k
15nF
AUDIO
OUTPUT
CON2
100nF
5
6
100
10 F
7
IC2b
3.5mm
STEREO
JACK
Slave control
100
4
13k
10 F
13k
150pF
13k
10 F
V–
10 F
LED
D1–D3: 1N4004
A
K
K
A
runs between each unit are possible. In
fact longer cable runs may work fine
but 30m is the longest pre-formed cable
that is commonly available.
Our test set-up is as follows. We ran
a 2m Cat5 patch cable from the master
unit to a wall socket which was wired
to another wall socket approximately
20m away. Including the vertical runs
and other diversions the actual cable
run is at least 25m. We then connected
a 5m Cat5 patch cable from the other
wall socket to the slave unit.
There were no apparent serial data
errors over this distance and the voltage drop on the 6V line was acceptable
siliconchip.com.au
7805, LM3940T
IRD1
1
2
GND
IN
3
to perform all these tasks is complex.
We will not go into great detail in this
article, however the source code will
be available for download along with
the HEX file.
During playback, both the WAV and
sequence files are read off the MMC/
SD/SDHC card synchronously, ie, the
software waits for each data packet to
arrive. Therefore, the other functions
which must be handled simultaneously – DAC output, infrared sensing,
zero crossing detection, phase control,
etc – must be interrupt driven.
Direct Memory Access (DMA) is
used for the DAC output and SD card
access to improve efficiency.
A number of software modules are
required to enable the various functions.
These include the MMC/SD/SDHC
card driver, FAT file system support,
WAV file reader, DAC driver, sample
rate and clock speed setting functions, infrared decoding, mains phase
synchronisation and serial output,
audio state playback logic and slave
chain length sensing (which uses the
internal ADC).
GND
OUT
(a little over 100mV with all eight
lights on). Four such cable runs would
produce a total of around 400-500mV
loss on the 6V line.
In normal circumstances, assuming
typical device characteristics, this
will leave a high enough voltage at the
last slave to reliably trigger its Triacs.
However to be safe it is best to keep the
total cable run under 50m if possible,
especially if wall sockets are involved.
Firmware
While the hardware of both the master and slave modules is fairly straightforward, the software required for IC1
The reason that the software calculates the number of attached slaves is
that if there are only one or two, it can
use the lowest possible serial frequency (72kHz) and only needs to transmit
16 bits (one word) per trigger point.
With three or four slaves, the serial
frequency is increased to 96kHz so that
32 bits (two words) can be transmitted at each trigger point and will be
finished before the next trigger point
is reached.
These trigger points are spaced approximately half a millisecond apart
and there are up to nineteen trigger
points per mains half cycle. In order
to allow for smooth brightness control
(256 levels), the trigger point used for
a given light is “dithered”, ie, it is
rapidly toggled back and forth to give
intermediate brightness levels.
Because of the filament heat persistence and the persistence of our
vision, this rapid brightness variation
is not visible. This scheme reduces the
required serial rate and makes the microcontroller’s job easier as it can more
often send the trigger even for multiple
lights together in a single command.
In choosing when to trigger a given
TRIAC, the microcontroller also takes
account of the fact that the amount
October 2010 41
10k
CON1
CHAIN LENGTH SENSE
IN FROM
CONTROLLER
1
2
3
4
5
6
7
8
+3.3V
SER DATA
+6V
GND
RJ-45
13
SER DATA
MASTER CLEAR
14
12
100
10
11
IC2e
IC2f
IC4: 74HC04
2
1
SCLK
9
3
100
IC2d
IC2a
LATCH
100nF
8
4
5
IC2c
100
6
7
IC2b
+6V
100 F
16V
100nF
100
100 F
16V
IC5
ULN2803
10
COM
16
10
11
14
12
13
10k
10k
10k
10k
Vdd
MR
Q0
Q1
SRCK
Q2
Q3
DS
15
1
2
3
IC3 Q4 4
74HC595
5
Q5
LCK
Q6
Q7
Q7'
OE
6
7
9
8 8B
8C 11
7 7B
7C 12
6 6B
6C 13
5 5B
5C 14
4 4B
4C 15
3 3B
3C 16
2 2B
2C 17
1 1B
1C 18
Vss
8
SC
DIGITAL LIGHTING CONTROLLER SLAVE UNIT
LED1
A
47
K
K
A
47
47
A
47
47
K
K
A
A
K
K
A
47
47
A
K
A
47
E
9
ERRATA: when operating the unit with four slaves, it may be necessary to leave
the 10kW “chain length sense” resistor off one of the four slave boards for correct
operation. You can check this by plugging in three slaves, then four; if it works
with three but not four, remove that resistor from the fourth slave.
2010
K
BTA41–600B
LEDS
K
A
A1
A2
G
Fig.3: the slave unit uses IC1, a serial-to-parallel latch, to decode the control data. Its outputs drive IC3, an eight
Darlington array, which switches current through the optocoupler LEDs (OPTO1-8). These control TRIAC1-8 and
ultimately the lights. The optocouplers and TRIACs are both equipped with snubber networks to prevent false
triggering and an LC filter to reduce radiated EMI. IC4 buffers the serial stream to the next slave unit.
of power delivered does not vary linearly with the trigger phase angle. It
has a lookup table which allows it to
calculate the percentage of full power
that a light will receive for each given
trigger period .
This is compared to the desired
brightness level and the dither error
from the last trigger event in order to
42 Silicon Chip
calculate the appropriate trigger point.
Because the master module senses
mains zero crossings via its AC plugpack supply, by default it assumes that
the slave modules are all on the same
mains power phase as it is.
This will be true in the vast majority of cases as most residences use
a single phase for all power outlets.
While it is possible to run the controller across multiple phases (indeed,
the software can handle this) in the
interests of safety and simplicity we
do not recommend operation on more
than one phase.
Another configuration option which
affects slave behaviour is the filament
preheat control. Filament preheating
siliconchip.com.au
CON2
1
2
3
4
5
6
7
8
SCLK
SER DATA
+6V
LATCH
GND
OUT TO
OTHER MODULES
+3.3V
CHAIN LENGTH SENSE
MASTER CLEAR
RJ-45
+6V
OPTO1
MOC3021
1
360
6
47nF
275VAC
X2 G
4
2
360
6
TRIAC1
BTA41
–600B
A1
39
10nF
275VAC
X2
100 H
100nF
275VAC
X2
OUTPUT 1
N
A
470
47nF
275VAC
X2 G
4
2
A2
E
OPTO2
MOC3021
1
470
A2
TRIAC2
BTA41
–600B
A1
39
10nF
275VAC
X2
100 H
100nF
275VAC
X2
OUTPUT 2
N
A
E
(TRIAC SWITCHING CIRCUITS 3–7
NOT SHOWN)
OPTO8
MOC3021
1
360
6
2
4
470
A2
47nF
275VAC
X2 G
TRIAC8
BTA41
–600B
A1
39
10nF
275VAC
X2
100 H
100nF
275VAC
X2
OUTPUT 8
N
A
E
NOTE: ALL WIRING
AND PARTS IN THIS
SHADED AREA
OPERATE AT MAINS
POTENTIAL. CONTACT
COULD BE FATAL!
FUSED MALE
IEC CONNECTOR
WITH SWITCH
F1*
* FUSE F1 RATING:
10A FOR 230V,
15A FOR 120V
means that when lights are off, their
power will not drop to zero.
Instead, the filaments are run just
below red heat which means that high
repetitive surge currents are largely
eliminated when they are being turned
on and off frequently.
Two options are provided. One
specifies which outputs have lights
siliconchip.com.au
E
A
N
that require filament preheating and
the other determines what percentage
of full power is delivered during the
off-state.
Circuit description
Refer to Fig.2 for the master unit
circuit diagram. Power from the 9V
AC plugpack is delivered via CON1
then rectified separately for two supplies. Diodes D1 & D2 form a full-wave
voltage doubler, charging the two
470F filter capacitors to generate an
unregulated split supply of approximately ±13V. This is used to power
the op amps.
At the same time, diode D3 halfwave rectifies the AC input, charging
a 2200F filter capacitor for the digital
supply. This is regulated to 6V by
REG1 and powers the optocouplers
in the slave modules.
It is further regulated (by REG2)
down to 3.3V for the remaining digital
components, including microcontroller IC1 and the digital logic in the
slave modules.
The 6V rail voltage is dropped by
D4 and then further by the 390
resistor to provide a 4.5-5.5V supply
for the infrared receiver. This assumes
that its current consumption is in the
range of 0.5mA-1.5mA, which is that
of the receivers specified in the parts
list. The 390Ω resistor and the 100nF
capacitor filter its supply so that any
digital switching spikes do not upset
its internal amplifier.
Pins 4 and 5 are connected to IC1’s
internal voltage comparator and this
is used for mains zero crossing detection. The AC input voltage is divided
(with a 10:1 ratio) by the 27kΩ and 3kΩ
series-connected resistors, resulting
in a 0.9-1.1V AC sine wave at their
junction.
Two 3kΩ resistors hold pin 4 of IC1
at approximately 1.65V (half the 3.3V
supply). The reduced amplitude sine
wave is AC-coupled to pin 5 of IC1
and also biased to the 1.65V level via
a 10kΩ resistor.
For half of each mains wave, the
voltage at pin 5 is higher than the voltage at pin 4 and the rest of the time it
is lower. IC1’s comparator generates
a software interrupt every time this
changes, allowing it to synchronise
a timer to the zero crossing event. In
reality, the voltage at pin 4 does not
stay at exactly half supply as current
flows back through the 10kΩ biasing
resistor but this does not affect the zero
crossing detection.
Since comparators tend to have an
offset voltage between their inputs,
the zero crossing detection is only
accurate to within about ±2%. This is
taken care of by the software with the
insertion of a “dead zone” around the
zero crossing point. The 1nF capacitor
between pins 4 and 5 suppresses mains
October 2010 43
Phase controlled Triacs,
serial data
SERIAL CLOCK PULSES (TRAILING EDGES MARK POTENTIAL TRIGGER POINTS)
In essence, this Digital Lighting Controller can be thought of as a multi-channel
light dimmer, all under the control of the
dsPIC micro which in turn is responding
to commands written for a particular piece
of music stored on the SD card.
But how do the light dimmers work?
Just the same as the light dimmers in
your home, they are based on a Triac, a
four-layer semiconductor device that can
switch high voltage AC. When triggered,
a Triac stays on until the voltage across
it drops to zero or reverses.
We vary the power fed to the lamps by
triggering the Triac earlier or later in each
mains half-cycle; the more power the lamp
gets, the brighter it will be. This is known
as “phase control” as we are varying the
portion of the mains waveform which the
lamps receive.
The accompanying diagram illustrates
Triac triggering on 230VAC mains waveforms, A, B and C. A corresponds to high
power since the Triac is on for most of the
time. B corresponds to slightly less power,
as the Triac is triggered later in each AC
half cycle. And C corresponds to the lowest power normally used in the Controller,
equivalent to the “filament preheating”
referred to elsewhere.
Note that while only three Triacs are
depicted here, the Controller can drive
up to 32 channels (in four slave units).
The serial data stream at the top of
the diagram is fed to the serial-to-parallel
latch (IC5) and the trailing edge of each
data pulse defines the start of a gate
signal fed to each Triac. Each Triac’s gate
signal (trigger) is on for the time between
successive serial data pulses or around
0.5ms. Each Triac stays on for the rest of
the half-cycle due to its latching action.
and power supply noise, preventing
false comparator triggering.
Infrared receiver IRD1 detects infrared light pulses at the appropriate
frequency (around 36kHz). Its logic
level output goes straight to IC1’s RA1
input (pin 3). This pin is configured to
generate an interrupt on a level change
and this triggers a decoding sequence
whenever infrared pulses are received.
The MMC/SD/SDHC card socket
CON4 is wired directly to IC1, which
uses an internal SPI peripheral to communicate with the card. The MMC/
SD/SDHC card is powered from the
regulated 3.3V rail. Pull-up resistors
44 Silicon Chip
0
5
10
LAMP
POWER
A
15
20
TIME IN MILLISECONDS
EARLY TRIGGERING: HIGH LAMP POWER
LAMP
POWER
TRIAC
TRIGGERING
TRIAC
TRIGGERING
(TRIAC GATE PULSES)
LAMP
POWER
B
LATER TRIGGERING: LOWER LAMP POWER
LAMP
POWER
TRIAC
TRIGGERING
TRIAC
TRIGGERING
(TRIAC GATE PULSES)
LAMP
POWER
LATE TRIGGERING: LOW LAMP POWER
LAMP
POWER
C
TRIAC
TRIGGERING
TRIAC
TRIGGERING
(TRIAC GATE PULSES)
are provided for the card’s CS and
DATA OUT pins in order to ensure it
is not activated at the times when IC1
is not operating (eg, when it is powering up or reset).
Input RB5 (pin 12) has a weak internal pull-up enabled. The card socket
connects its card detection (CD) pins
together if a card is inserted, pulling
IC1’s pin 12 low and triggering its
communication initialisation routine.
Audio output
Audio output is generated from IC1’s
internal 16-bit DAC and then passes
to IC2, a dual op amp. The left/right
DAC outputs are differential, meaning
that when DAC1L+ swings up, DAC1Lswings low.
For best audio quality, these signals
should be subtracted to form the final
audio output. IC2a and IC2b are configured as differential amplifiers with
a gain of 1.3 (13kΩ/10kΩ), resulting
in an output level of around 1V RMS.
The two 10F capacitors in series
with the 13kΩ resistors charge to the
DAC’s average output voltage and form
a virtual ground for the differential
amplifier input dividers. They result
in a high-pass filter with a -3dB point
at around 1Hz.
siliconchip.com.au
Parts List – Digital Lighting Sequencer/Controller
Master module
1 PC board, coded 16110101, 148 x 80mm
1 front panel label, 145 x 20mm
1 2.5mm PC-mount DC socket (CON1)
1 3.5mm PC-mount stereo switched socket
(Jaycar PS0133, Altronics P0092) (CON2)
1 low profile RJ-45 socket (Altronics P1448) (CON3)
1 surface mount MMC/SD/SDHC card socket
(Altronics P5720) (CON4)
1 24.576MHz crystal
1 ABS plastic instrument case, 86 x 155 x 30mm
(Altronics H0377)
4 nylon washers
4 No.4 x 9mm self-tapping screws
1 9V AC plugpack 500mA+
(Altronics M9231, Jaycar MP3027)
1 SD, MMC or SDHC card, at least 1GB recommended
15cm tinned copper wire
1 28-pin DIP socket
2 M3 x 6mm machine screws
2 M3 shakeproof washers
2 M3 nuts
1 mini TO-220 heatsink (Jaycar HH8502, Altronics
H0630)
Semiconductors
1 dsPIC33FJ64GP802 microcontroller (IC1) programmed with 1911010A.hex
1 TL072 dual op amp (IC2)
1 infrared receiver (IRD1)
(Jaycar ZD1952, Altronics Z1611/Z1611A)
1 7806T regulator (REG1)
1 LM3940IT-3.3 regulator (REG2)
1 green 5mm LED (LED9)
4 1N4004 diodes (D1-D4)
Capacitors
1 2200F 16V
2 470F 16V
2 100F 16V
4 10F 16V
1 1 0F 16V tantalum
1 4.7F non-polar (NP)
5 100nF MKT
2 15nF MKT
1 1nF MKT
2 150pF ceramic
2 33pF ceramic
WARNING!
This is a mains-operated device.
Construction should not be attempted unless
you have knowledge of and experience in
building mains-powered projects.
The slave unit has areas of the PC board where
components and tracks are at mains potential.
Contact with live wiring could prove fatal.
siliconchip.com.au
Resistors
1 47kΩ
1 27kΩ
3 3kΩ
1 390Ω
4 13kΩ
1 220Ω
11 10kΩ
6 100Ω
Slave module
(parts for one module [eight channels] only)
1 PC board, code 16110102, 216 x 157.5mm
1 plastic instrument case, 260 x 190 x 80mm
(Jaycar HB-5910, Altronics H0482)
1 aluminium rear panel for above case, 2mm thick
1 front panel label, 240 x 71mm
1 rear panel label, 240 x 71mm
2 low profile RJ-45 sockets (Altronics P1448)
8 100H 5A mains-rated inductors
(Jaycar LF1270, Altronics L6622)
4 heavy-duty PC-mount TO-3P heat sinks
(Jaycar HH8526, Altronics H0667)
5 2-way mini terminal blocks (5.08mm pin spacing)
1 1.5mm panel snap-in male IEC mains connector
with fuse and switch (Altronics P8341)
8 chassis-mount female IEC mains connectors (Altronics P8326)
15 blue fully-insulated 6.4mm female spade crimp lugs
17 red fully-insulated 6.4mm female spade crimp lugs
1 chassis-mount male spade lug
1 5.3mm eyelet crimp lug
20 small nylon cable ties
6 No.4 x 9mm self-tapping screws
22 M3 x 10mm machine screws
24 M3 shake-proof washers
24 M3 nuts
2 10A M205 fuses (1 spare)
1.2m mains-rated green/yellow (earth) wire
1.1m mains-rated light blue (neutral) wire
0.8m mains-rated brown (active) wire
40cm tinned copper wire
15cm x 2.5-3mm diameter fibreglass sleeving
(Jaycar WS5504, Altronics W0852)
Cat5, 5e or 6 cable with length to suit installation
Semiconductors
1 74HC595 serial-to-parallel latch IC (IC3)
1 74HC04 hex inverter IC (IC4)
1 ULN2803 octal Darlington array (IC5)
8 red 5mm LEDs (LED1-8)
8 MOC3021 Triac optocouplers (OPTO1-8)
8 BTA41-600B insulated tab 40A Triacs (Triac1-8)
Capacitors
2 100F 16V
8 100nF MKT X2 250V AC
2 100nF MKT
8 47nF MKT X2 250V AC
8 10nF MKT X2 250V AC
Resistors
5 10kΩ
8 470Ω
8 47Ω
8 39Ω
8 360Ω
4 100Ω
October 2010 45
The bootloader
The master module firmware includes a “bootloader”. This
allows the software on the master module to be updated without
requiring a programming tool.
When the device powers up it looks for a HEX file on the
memory card. If it is present, the contents are read and verified,
then written into the FLASH program memory.
The main program runs after the programming is complete,
or immediately if there is no HEX file. The main program can
re-program the bootloader if necessary, allowing the whole chip
to be updated.
The FLASH memory is divided in two. The bootloader resides
at the end of memory, (addresses 0x9000 – 0xABFF, 10.5kB). The
main program is at the start (addresses 0x0000-0x8FFF, 54kB).
The bootloader program incorporates the MMC/SD/SDHC card
reader code along with the FAT file system and FLASH memory
programming routines. Because the interrupt vector table is
stored in FLASH memory at 0x0000-0x01FF and therefore is part
of the main program, the bootloader does not use any interrupts.
Because the reset vector (which must point to the bootloader)
is within the interrupt vector table, when the first page of memory
is programmed, the reset vector address is overridden.
If the reset vector were corrupted during the programming
process, eg due to a power failure, the bootloader would no
longer work. Before re-programming it, the bootloader program
checks that AC power is present via the zero crossing detection
circuitry.
The 2200F capacitor provides enough power to finish programming even if AC power is lost after that point. A similar
check is made in the main program before re-programming
the bootloader.
The 150pF capacitors in parallel with the 13kΩ feedback
resistors roll off the op amp gain to form a low-pass filter
with a -3dB point around 80kHz.
This active filter removes much of the high frequency
switching noise from the delta-sigma DAC architecture,
which is mostly above 2MHz (for CD quality audio).
The output of each differential amplifier is AC-coupled
to make it ground-referenced, then further filtered with a
passive low-pass RC filter consisting of the 100Ω resistors
and 15nF capacitors. This is more effective than the active
filter at frequencies above IC2’s bandwidth (2.3MHz at this
gain setting) which can be coupled via the 150pF capacitors.
The 100Ω resistors also isolate IC2’s outputs from any
cable capacitance and provide current limiting should
the outputs be shorted to ground or to each other. CON2
is the audio output connector and accepts 3.5mm stereo
jack plugs.
Crystal X1 provides a reference frequency to IC1 for the
DAC timing. This allows it to operate the DAC at a frequency
very close to the sample rate of the file being played back.
IC1 operates at 39.552MHz when the audio sampling rate
is 44.1kHz, 22.050kHz (half rate) or 11.025kHz (quarter
rate). This is divided by 14, 28 or 56 to provide the DAC
oversampling clock, which is 64 times the sample rate. The
sample rate error is less than 0.1%.
Alternatively, IC1 operates at 39.936MHz for sample
rates of 48kHz, 24kHz (half rate) or 12kHz (quarter rate).
This is divided by 52, 26 or 13 (respectively), resulting in
exactly 64 times the sample rate. For 32kHz sample rate,
the clock is 38.912MHz and the divider is 19, also resulting
46 Silicon Chip
in an exact DAC clock.
While IC1 runs from the 3.3V supply, its core actually
runs at 2.5V. This is generated by an internal regulator. Its
output is filtered by the 10F tantalum capacitor connected
between pins 19 and 20.
The master module communicates with the slave(s) via
8-pin RJ-45 connector CON3. This provides the low voltage
slave power supply, serial communications and slave chain
length sensing. 3.3V is provided for the slave digital logic
(pin 3) and 6V for driving the optocouplers (pin 6) plus a
common ground (pin 8).
The same connector is used for the serial communication
with data (pin 5) and clock lines (pin 4), chip select/latch
(pin 7) and master clear (pin 2). Pin 1 is for chain length
sensing and is used by the master module to determine
how many slaves are connected. Each slave module has
a resistor between this pin and the 3.3V supply and these
form a voltage divider in combination with the 10kΩ resistor on the master board.
Each serial output has a 100Ω resistor between the microcontroller output and the connector pin. This combines
with the cable capacitance to form an RC filter which helps
to limit reflections and ringing in the cable as well as reduces electro-magnetic interference (EMI) from the cables
by limiting the signal rise and fall times.
Normally, Cat5 cable is used for high speed network
signalling and the twisted pairs in the cable are driven
differentially. This allows for high speed communication
with minimal crosstalk and interference.
However, we are not using differential signalling so we
must limit the serial speed in order to maintain sufficient
signal integrity. This is not a problem as a serial clock of
100kHz is sufficient for this application.
LED1 provides the only direct user feedback from the
master module and is driven from pin 2 of IC1. It can be
turned on or off, set to an intermediate brightness or flashed
at various rates to convey different information to the user.
Slave module circuit
The slave module receives serial data from the master
module to control when each of the eight Triacs are triggered during each mains half-cycle. A 74HC595 serial-toparallel latch IC (IC3) decodes this serial data. Each of the
incoming lines is terminated with a 10kΩ resistor to help
to drain the cable capacitance when a line is driven low.
The latch drives a ULN2803 octal Darlington transistor array (IC53) which acts as a current buffer to provide
sufficient drive strength for the optocoupler LEDs. These
optocouplers have two purposes. Firstly, they isolate the
low voltage signal side of the circuit from the mains side
so that lethal voltages can not be conducted back to the
master module over the Cat5 cable (or shock somebody
touching the connector).
Secondly, they make triggering the Triacs easy as all that
is required is for sufficient current to pass through their
internal infrared LED. The minimum guaranteed trigger
current is 15mA and the 74HC595 is not rated to provide
this much current directly, hence the Darlington array.
When an output from IC1 goes high, the Darlington in IC3
sinks current via the associated LED, 47Ω series resistor
and optocoupler from the 6V rail.
The worst-case voltage drop across each Darlington at
15mA is 1.0V, for the LED around 2.5V and the optocoupler
siliconchip.com.au
The rear panel of the slave unit is
pretty spartan, containing only the
eight IEC mains output sockets. These
are used mainly for their size – they’re
a lot smaller than standard 3-pin
power outlets. You will need to make
up (or buy) some IEC-to-3 pin plug
adaptors if your power leads aren’t
terminated in IEC plugs.
1.5V. With a the 6V supply rail at 5.7V (due to regulator
tolerances and cable drops), this means that the voltage
across each 47Ω resistor will be 0.7V resulting in very close
to 15mA through the chain.
It’s very unlikely that any particular unit will have all
worst-case parts so in reality there is a fair margin for
voltage drops across the Cat5 cables. Since the Triacs are
only triggered for around 5% of each mains half-cycle, the
100F bypass capacitors in the slave unit should prevent
excessive drops on either rail.
Triac control
When the LED in an optocoupler is turned on, its small
internal Triac will conduct bidirectionally. This allows current to flow from the incoming mains active line, through
the 470Ω and 360Ω series resistors and then into the connected 40A Triac gate. This will trigger that Triac which will
conduct for the remainder of the mains half cycle. Thus,
the earlier in the half cycle that the Triac is triggered, the
higher the RMS current through the load.
Because the Triacs have a latching action, the trigger
current does not need to be provided for very long. Each
trigger pulse lasts for around 0.5ms.
The 470Ω resistors and 47nF X2 capacitors at each
optocoupler act to limit the rate of change of the voltage
across its internal Triac, ie they function as a snubber.
This prevents spurious triggering of the internal Triac
(and hence the associated 40A Triac) due to mains noise
or electromagnetic interference.
Similarly, the 39Ω resistors and 10nF capacitors connected in series across each BTA41 Triac limit the dV/dt
rate across the Triac terminals to prevent unintentional
triggering from mains supply noise and such. This is
especially important when the Triac is driving an inductive load, such as a halogen transformer, as the switch-off
spike when the load is disconnected can easily result in
the Triac being triggered at the start of the next cycle when
it should not be.
The 100H inductors and 100nF X2 capacitors form an
LC filter which limits the inrush current to the load when
the associated Triac switches on. This is primarily to prevent magnetic radiation from the mains leads connecting
each load, which can be quite severe when applying phase
control to loads such as incandescent lamps. This is due to
the high inrush currents when the filament is cold.
While each Triac is rated at 40A, the entire slave module is powered from a 10A input socket with appropriate
fuse. In addition, other components in the mains power
path (such as the inductors) are rated at 5A, so this is the
maximum current per output.
There are two reasons why we are using 40A Triacs desiliconchip.com.au
spite the much lower continuous rating. The first is that
when an incandescent lamp is switched on from cold, its
filament resistance is a lot lower than when it is at operating
temperature. A 230V AC 150W lamp can be expected to
have an overall resistance of around 350Ω at full power. It
will therefore draw about 230/350 = 657mA RMS. However
when the filament is cold, eg when switched on initially,
the resistance can be 10% of this or less. This will result in
an instantaneous current in excess of 6A and even higher
for larger lamps or several in parallel.
Even higher currents can occur when a PAR (parabolic
aluminised reflector) light fails. The filament can become
disconnected at one end and flail around, possibly shorting against the support wires. In excess of 20A can flow
before the stem fuse blows. We don’t want to burn out a
Triac under this condition so we have made sure that they
will survive such an event.
One further point regarding the Triacs: they only latch
with a certain minimum current flow. In the case of the
BTA41 this is no more than 80mA. This is the reason why
we have specified a minimum load of 25W per output.
Otherwise, early or late in the mains cycle when the instantaneous mains voltage is relatively low, the Triac may
fail to latch, resulting in an incorrect brightness level on
that output.
Daisy-chained slaves
The remaining circuitry in the slave module allows for
slave daisy-chaining. Up to four slave modules can be connected to a single master module. To ensure that the same
length of cable can be run between slave units as can be
used between the master and the first slave, we buffer the
serial signals using a 74HC04 hex inverter IC (IC4).
The SCLK, LATCH and MASTER CLEAR signals are
passed through directly from one slave to the next. Each
is inverted twice, in order to buffer the signal but preserve
the polarity. As with the master module, there are 100Ω
series resistors between the buffer and the output RJ-45 jack.
The serial data stream itself comes from the Q7’ output of
IC1 and via another 100Ω series resistor. This output from
this pin is delayed by eight clocks relative to the serial input.
As a result, when 16 or 32 data bits are shifted through
the slave module chain, each serial latch ends up with a
different set of eight bits – the first slave latches the first
eight, the second slave the second eight, etc. This allows
the master to control each slave individually with a single
serial sequence.
That’s it for this month. Next month we will show you
how to build the master and slave modules and explain
how the firmware and PC software works. We will also
provide a location to download the PC software.
SC
October 2010 47
|