This is only a preview of the May 2002 issue of Silicon Chip. You can view 28 of the 96 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 "PIC-Controlled 32-LED Knightrider":
Items relevant to "The Battery Guardian":
Items relevant to "Build A Stereo Headphone Amplifier":
Items relevant to "Automatic Single-Channel Light Dimmer; Pt.2":
Purchase a printed copy of this issue for $10.00. |
More LEDs, more patterns, more exciting than ever
32-led
Flashing LED displays are always intriguing, particularly if
they emulate the KnightRider car from the old TV series. This
KnightRider light chaser includes 12 different lighting patterns
using 32 LEDs for a big and impressive display. Not restricted to
KnightRider use, the display can be used as a rear window brake
light or as an eye-catching conversation piece at parties or even
on retail displays.
By JOHN CLARKE
24 Silicon Chip
www.siliconchip.com.au
I
the other in May 1996. Both of these
Our latest version of KnightRider
n the early 1980s there was a TV
used 16 LEDs and had a single fixed
has twice as many LEDs, 32, and a
series called KnightRider. Its “star”
scanning display pattern.
number of different display patterns
was a rather clever car going by the
are available which are selectfetching name ‘Kit’.
ed using a pushbutton switch.
Mind you, Kit was no
There are four scanning seordinary car. It had powers
quences, a chaser and a strobe.
and abilities far beyond those
Ds
LE
32
of mortal cars. Kit could talk,
If you mounted the display
*
including medleys
s,
rn
tte
pa
y
pla
drive itself and supposedly
on
your car’s parcel shelf, you
dis
D
LE
* 12
d
see using a row of lights on
could
also use it as a brake
ee
sp
rn
tte
pa
* Adjustable
the front which ‘scanned’ from
light.
ss
tne
igh
br
side to side to simulate moni* Adjustable LED
The patterns
toring what was ahead.
* 12V operation
While the KnightRider TV
The four scanning patterns
series has long since ceased,
include the traditional moveBut both of these were in the days
such scanning lights have
ment of LEDs from left to right and
before microcontrollers – or at least becontinued appeal and we have pubfrom right to left which is repeated
fore microcontrollers were commonly
lished two different KnightRider light
to simulate scanning across a field
used in projects.
displays, one in November 1988 and
in front of the LEDs. Pattern 2 begins
Features
Fig.1: in this circuit, the 32 LEDs are arranged in an array, driven in
their various patterns by the PIC microcontroller.
www.siliconchip.com.au
May 2002 25
with two LEDs in the centre LEDs
which then spread (light up) to the
left and right and contract back to
the centre.
Patterns 3 and 4 are similar, with
pattern 3 moving from the centre to the
outside and then back to centre again.
Pattern 4 starts from the outside LEDs
and moves to the centre and then back
the outside again.
Chaser sequences include a right
to left movement and a left to right
movement. The strobe patterns can
be at a regular or random flashing rate.
For brake light use, there are two
patterns. The first lights all LEDs initially for a minimum of about 18 seconds (depending on the speed setting)
and then the LEDs randomly switch
off until they are all out. Alternatively,
you can just have all LEDs lit while
ever the brake is applied.
The KnightRider PC board measures 210 x 72mm. All 32 LEDs mount
horizontally along one edge of the PC
board. There are two trimpots, one to
adjust the LED scanning rate and the
other to adjust display brightness. A
pushbutton selects the display pattern
while a LED next to the switch flashes
once or more to indicate the pattern
that has been selected.
Circuit description
Apart from the 33 LEDs, the
KnightRider uses relatively few components and is based around IC1, a
PIC16F84 microcontroller. This provides all the LED patterns.
The PIC16F84 has 18 pins, 13 of
which can be used as inputs or outputs. For our circuit we are using 12
as outputs to drive the LEDs and one
as an input and an output to monitor
the pattern select switch and drive the
pattern LED. Fig.1 shows the circuit
details.
Multiplexed rows and columns
While the 32 LEDs are physically
arrayed along one side of the PC board,
they are actually connected as a matrix of four columns and eight rows,
as shown in Fig.1. The eight rows are
driven directly from IC1 (RB0-RB7)
while the four columns are driven by
four transistors, Q1-Q4. These transistors are switched by the RA0, RA1,
RA2 and RA3 outputs of IC1.
When the RA0 output (pin 17) is
pulled low by IC1, transistor Q1 is
switched on and applies power to the
anodes of LEDs 1-8. A low output on
any of the RB outputs will drive the
LED connected to it via its series 150Ω
resistor. For example, if RB0 goes low,
LED1 will light.
The RA0 line is kept low for a short
time before this goes high to switch off
Q1. Thus LEDs1-8 are switched off.
The RA3 line (pin 2) is then brought
low to drive Q2 and the anodes of
LEDs 9-16. Now any low RB outputs
will then light up LEDs 9-16. Similarly,
RA2 (pin 1) is brought low to drive
Q3 and LEDs 17 to 24 and then RA1
(pin 18) is pulled low to drive Q4 and
Scope 1: The upper trace is the oscillator waveform at
pin 16 (OSC IN). This is a classic sawtooth expected from
a relaxation oscillator. The lower trace is the waveform
at pin 15 (OSC OUT) which in this RC mode is a square
wave at one quarter the oscillation frequency.
26 Silicon Chip
LEDs 25-32.
This cycle repeats endlessly with
each column of eight LEDs being lit at
a very fast rate so that the LEDs appear
to be continuously lit rather than only
being on for some of the time. This
system of driving the LEDs is called
“multiplexing”. Its big advantage is
that it saves power and drastically
reduces the number of connections
required. If the LEDs were not multi-plexed we would need 33 separate
lines (32 actives and one common)
whereas with multiplexing we can
drive the 32 LEDs using only 12 lines
connected in the matrix.
Brightness control
Overall LED brightness is controlled
with trimpot VR2. This varies the
voltage at pin 3 of IC2 from 5V down
to about 2.4V when the wiper is at its
lowest point. Op amp IC2 operates
as a unity gain buffer amplifier, with
transistor Q5 providing extra current
drive capability.
If the emitter of Q5 is at 5V, the
LEDs will be driven at maximum
brightness. Typical LED current will
be (5V - 1.8V)/150Ω, or 21mA. This is
the pulse current, not average current.
The pattern select switch S1
connects to RA4 of IC1. This pin is
normally held at 5V via the 10kΩ
pullup resistor. When S1 is pressed,
LED33 lights and RA4 is pulled low.
This is recognised by IC1 as a switch
closure and the next pattern in the
sequence of 12 is selected. When the
Scope 2: These traces show the time duration between when
power is applied to the circuit and when the LEDs light
for the brake light pattern selections. Top waveform is the
applied voltage and when this goes high, there is some 67ms
before the LEDs light. This is fast enough to display almost
instantly the brakes are applied.
www.siliconchip.com.au
15pF
DEEPS
VR1
50k
0.1F
K
K
4.7k
150
LED31
150
LED30
150
IC1
PIC16F84
LED29
150
LED28
1
10F
1k
A
22k
68k
150
10k
150
NRETTAP
Q6
BC328
150
150
LED27
LED26
LED25
LED24
LED23
S1
LED22
LED33
10k
LED21
10F
Q5
BC338
10F
+
LED18
LED17
LED16
LED15
THGIRB
Q3
BC328
VR2
50k
LED14
LED13
Q2
BC328
680
680
LED12
LED11
Q1
BC328
680
LED10
LED9
12050180
Q4
BC328
680
2002 C
LED19
10F
1
LED20
47k
IC2
LM358
1k
LED32
LED8
LED7
REG1
10F
LED6
LM7805
+12V
+12V
LED4
16V
ZD1
LED3
10
1N4004
KNIGHT RIDER
LED2
D1
LED1
A
0V
GND
LED5
100F
A
Fig. 2: here’s the full-size PC board component overlay, with a matching photo to make assembly a breeze!
switch is released, IC1 flashes LED33
to indicate the pattern selected. For
example, pattern 2 is indicated by
two flashes.
Note that the RA4 pin is an open
drain output when configured as an
www.siliconchip.com.au
output. This allows RA4 to drive
LED33 when pin 3 is low. When RA4
is set high, the open drain connection
means that it becomes a high impedance output which is pulled high via
the 10kΩ resistor. In this condition,
IC1 can monitor RA4; if it is pulled
low, that indicates that the switch is
closed.
No crystal required
Most PIC circuits use a crystal for
May 2002 27
Parts List –
KnightRider
1 PC board coded 08105021,
210 x 72mm
1 heatsink, 19 x 19 x 10mm
1 2-way PC-mount screw terminal
1 snap-action PC pushbutton
switch (S1)
1 M3 x 6mm screw and nut
4 adhesive rubber feet
1 350mm length of 0.8mm tinned
copper wire
Semiconductors
1 PIC16F84P (IC1) programmed
with Knight.hex
1 LM358 dual op amp (IC2)
1 7805 regulator (REG1)
5 BC328 PNP transistors (Q1-Q4,
Q6)
1 BC338 NPN transistor (Q5)
1 16V 1W zener diode (ZD1)
1 1N4002 diode (D1)
33 5mm red high-brightness LEDs
(LED1-LED33)
Capacitors
1 100µF 16VW PC electrolytic
5 10µF 16VW PC electrolytic
1 0.1µF MKT polyester (code
100n or 104)
1 15pF NP0 ceramic (code 15p
or 15)
Resistors (0.25W, 1%)
1 68kΩ
1 47kΩ
1 22kΩ
2 10kΩ
1 4.7kΩ
2 1kΩ
4 680Ω
8 150Ω
1 10Ω
2 50kΩ horizontal trimpots
(code 503) (VR1,VR2)
the internal oscillator but this circuit
does not require precision timing. For
these situations, the PIC can be set
up as a relaxation oscillator (similar
to the 555) whereby a capacitor connected to pin 16 is charged from the
positive supply (+5V) via a resistance
and then discharged via an internal
transistor.
In this case we connected a 15pF
capacitor to pin 16, charged from +5V
via trimpot VR1 and a 4.7kΩ resistor.
The classic sawtooth waveform of the
oscillator can be seen in the top trace
of Scope 1.
28 Silicon Chip
Interestingly, the waveform at pin
15, OSC OUT, is not the same as at pin
16. Instead it is a square wave at one
quarter the frequency.
Frequency of operation can be varied from about 4MHz when VR1 is set
to minimum resistance, down to about
500kHz when VR1 is at maximum
resistance.
Transistor Q6 and its associated
resistors provide a reset for IC1 when
the supply is below a certain voltage.
This ensures correct start up for IC1
when power is applied.
The circuit can be powered from a
12V battery, DC power supply or DC
plugpack. Diode D1 gives reverse polarity protection while the 10Ω resistor
and zener diode ZD1 provide transient
protection.
The 12V supply is filtered with a
100µF capacitor before being applied
to REG1, a 5V regulator. Its output is
decoupled with a 10µF capacitor to
ensure stability.
Software
The software required to provide
the various LED display patterns was
written to minimise the number of instruction codes. This is because there
are only 1024 bytes of memory and we
would quickly run out of space if we
were to list each individual LED and
its state during a pattern sequence.
This normal approach involves using
a lookup table.
Instead of using a lookup table, the
software makes note of the fact that
much of the sequence is repetitive
and only a short list of LED switching
operations is required. This list is
used in various ways to generate the
required pattern.
The efficiency of this approach is
evident by the fact that we managed
to include some 12 distinct patterns
into the software with some space
left over. In contrast, if we had used
a lookup table it would have only
allowed one or maybe two patterns
at the most.
The full software listing for the
KnightRider is called knight.asm; it
(and the .hex file) is available from our
website – www.siliconchip.com.au
Construction
The KnightRider is constructed on a
PC board coded 08105021 and measuring 210 x 72mm. Begin construction
by checking the PC board for shorted
tracks or any breaks in the copper
pattern. Check the pattern against the
published artwork to verify that it is
correct. Repair any defects on the PC
board before starting assembly.
Fig.2 shows the component overlay
for the PC board.
First, install all the links on the
PC board. Then install the resistors,
using the colour codes shown in the
parts list as a guide to selecting the
values. You can also check each value
with a digital multimeter to be sure
that you have the correct resistor for
each position. The diodes can be
installed next, taking care not to confuse zener diode ZD1 with standard
diode D1.
IC1 is mounted using a socket while
IC2 can be soldered directly into the
PC board. The 3-terminal regulator
is mounted horizontally, so carefully
bend the regulator leads before inserting them into the relevant holes
on the PC board. It is mounted onto
a small heatsink and secured with an
M3 screw and nut.
When installing the five transistors,
make sure that the BC338 is placed in
the Q5 position.
Next, install the capacitors. The
codes of low value types are listed in
the parts list. The electrolytic capacitors will have their values marked in
µF; be sure to orient them correctly.
Switch S1 should be installed with
the ‘flat’ side oriented as shown Fig.2.
Insert LED 33 with the anode (longer
lead) placed toward the VR1 side of
the PC board. Trimpots VR1 and VR2
and the PC-mount terminal block can
then be soldered into place.
Finally, the 32 LEDs can be installed
along the edge of the board. They are
placed with the anode leads (longer
lead) to the left.
You can preform all the LED leads
by cutting a length of cardboard 10mm
wide. Place the LED across this with
the anode to the left and bend the leads
downward. This will allow the LEDs
to be inserted into the PC board with
sufficient clearance for the LED body
to just protrude over the front edge of
the PC board.
Check your work carefully for correct orientation of the capacitors, for
the correct transistors in each place
and the correct orientation of IC2 and
the socket for IC1. Do not install IC1
yet.
Testing
Now apply power to the +12V and
www.siliconchip.com.au
TABLE 1: PATTERNS AVAILABLE
K
Type
1
Scan
LEDs move from left to right and then right to left
yes
2
Scan
LEDs move symmetrically from centre to outside
and from outside to centre
yes
3
Scan
LEDs move symetrically from centre to outside
yes
4
Scan
LEDs move symetrically from outside to centre
yes
Patterns 1, 2, 3 & 4 selected in sequence
with change every power up
yes#
1
6
Medley 8 cycles of pattern 1
16 cycles of pattern 2
16 cycles of pattern 3
16 cycles of pattern 4
7
Chaser LEDs chase from right to left
yes ##
8
LEDs chase from left to right
yes
9
Strobe
All LEDs on then off at regular rate
10
Strobe
All LEDs on then off at random rate
yes
11
Random LEDs lit at random until all on,
then off at random until all off
yes
12
Medley
100 cycles of pattern 7
100 cycles of pattern 8
20 cycles of pattern 9
20 cycles of pattern 10
2 cycles of pattern 11
yes+
13
Brake
All LEDs on at power-up for 18s minimum
then off at random until all off
no
14
Brake
All LEDs on at power up and remain on until
power off
no++
yes
1
BRIGHT
08105021
C 2002
#
##
+
++
Chaser
PATTERN
5
Scan
Pattern Description Repeat
SPEED
No.
(of selected pattern)
(Medley repeats of patterns 1, 2, 3 & 4)
(Medley repeats of patterns 7, 8, 9 & 10)
(only lights again after power off and on again)
GND
+12V
0V supply terminals and measure the
voltage between the metal tab of REG1
and pin 14 of the IC1 socket. This
should be +5V. If this is correct, disconnect power and insert IC1, making
sure it is oriented correctly.
Apply power again and check that
the LEDs start to light up and produce
a chasing pattern. The initial pattern
is the KnightRider chaser (Pattern 1)
with the LEDs moving from left to right
and from right to left.
www.siliconchip.com.au
Check that you can adjust
the speed with trimpot VR1
A
KNIGHT RIDER
and vary brightness with
VR2.
You can test for the other Full-size PC board artwork. Use this to check
patterns by pressing the commercial boards or to make your own board.
pattern switch. Each time
you press the pattern switch, LED33 trimpot (VR1) so that you can easily
count the number of flashes from
will flash the required number of times
and then the selected pattern sequence LED33.
will start to run.
Table 1 shows the 14 patterns
You may need to adjust the speed available.
SC
May 2002 29
|