This is only a preview of the November 1999 issue of Silicon Chip. You can view 34 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. Items relevant to "A Speed Alarm For Cars; Pt.1":
Articles in this series:
Items relevant to "Railpower Model Train Controller; Pt.2":
Purchase a printed copy of this issue for $10.00. |
Looking for something different this Christmas?
Try our multi-coloured, multi-pattern LED Christmas Tree.
It will look great at the top of your Christmas tree
or in the front window.
By Les Grant*
November 1999 31
I
N NOVEMBER 1998, we published the Christmas Star as a novelty project and it proved extremely popular.
This year, our “just for fun” festive
season project is in the shape of a
Christmas Tree but the display is a lot
more diverse and interesting because
it uses bi-coloured LEDs. Not only
can each LED produce 16 different
colours, the LED Christmas Tree has
a fascinating range of ever-changing
patterns.
In fact, considering that the LEDs
are red/green types, you will wonder
how they can produce such a range of
colours; some of them are quite odd.
As with last year’s Christmas Star
project, this circuit uses just one
IC (OK, one-and-a-bit!) and yet the
patterns it produces are seemingly
endless.
How does it do it? Yes, you guessed
it. The Tree is controlled by a microcontroller but this one is different.
While it can be programmed by most
“high-end” (expensive) chip programmers, it can also be programmed (and
re-programmed) by a PC parallel port
with minimal hardware.
This makes it ideal for hobbyists.
If you have been avoiding microcon-trollers because of the cost of the
programming hardware, now there is
no excuse!
And most of the development soft-
ware can be downloaded free from the
Internet – that avoids another excuse!
Circuit description
Fig.1 shows the circuit. The key to
understanding any circuit is “divide
and conquer” – break it down into
functional blocks.
There are three main blocks in
the Tree circuit. The first, the power
supply, is straightforward. 9V DC is
applied from a plugpack to socket
SK1. Reverse polarity protection is
provided by diode D1. The 3-terminal
7805 regulator (REG1) then provides
a 5V rail for the LEDs and the logic.
Bypass capacitors C4 and C5 ensure
that the 7805 remains stable.
Next is the microcontroller IC1.
In the Christmas Star and Heart of
LEDs (May 1999) projects, we used
the Atmel AT89C2051. However, its
I/O port structure is not quite suitable
for this application so we have used
the similar Atmel AT90S2313. See
the section entitled “What’s in the
AT-90S2313” for a description of the
microcontroller.
IC2 is a 24C16 serial EEPROM
where the pattern data is stored.
While IC1 has some EEPROM on chip
(128 bytes), this was not enough for
the number of patterns we wanted to
provide.
The final circuit is the LED matrix.
At first glance, the PC board looks like
it contains 32 LEDs. In reality, there
are 64 LEDs as each is a bi-colour LED
capable of glowing red or green. 2-pin
bi-colour LEDs were chosen to reduce
the number of PC board tracks and
microcontroller output pins required.
3-pin LEDs would have been easier to
drive but would have required more
output pins from IC1.
To enable IC1 to control so many
LEDs with relatively few output pins
the LEDs are multiplexed. Multi-plexing is a switching technique whereby
each column of LEDs is activated for a
short time during which the appropriate rows are driven. This means that
individual LEDs are only turned on
for a short time. Provided the rate at
which the LEDs are turned on is fast
enough, our eyes don’t see any flicker.
So for multiplexing in this circuit,
we connect the LEDs in a matrix of
four columns and eight rows to give a
total of 32 LED packages. That enables
us to drive the whole matrix with just
12 output pins from IC1.
Note that while there are only four
columns of LEDs, we have to drive
each column twice in each multiplex
cycle so that we can activate the red
and green LEDs.
Consequently, each LED’s timeslot
is just 12.5% of the total. This is a
practical minimum duty-cycle for
adequate brightness from the LEDs.
The 100Ω resistors R6-R13 set the
What’s in the AT90S2313?
The AT90S2313 is a member of the Atmel AVR family of microcontrollers which range from tiny 8-pin packages to a
64-pin feature-packed “monster”. Here is a short summary of the features of the ’2313:
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
118 instructions, most single-clock cycle execution
32 8-bit general purpose working registers
Up to 10 MIPS throughput at 10MHz
2k bytes (1k words) of In-System-Programmable Flash for program storage (endurance 1,000 erase/write cycles)
128 bytes of SRAM
128 bytes EEPROM (endurance 100,000 erase/write cycles)
May be locked for program and EEPROM data security
1 8-bit timer/counter with separate prescaler
1 16-bit timer/counter with separate prescaler, compare and capture modes and 8, 9 or 10-bit PWM
On-chip analog comparator (rail-to-rail inputs)
Programmable watchdog timer with separate on-chip oscillator
SPI serial interface (for in-system programming only)
Full duplex UART
Low power idle and power down modes
External and internal interrupt sources
15 programmable I/O lines in a 20-pin package
2.7 - 6.0V (4MHz parts) or 4.0 - 6.0V (10MHz parts)
32 Silicon Chip
Fig.1: the micro
drives the 32
bi-colour LEDs in
a 4 x 8 matrix with
4 columns and 8
rows. Each row and
column is driven
by complementary
emitter-follower
pairs which can
sink or source
current. This is
necessary because
the bi-colour LEDs
need to be driven in
both directions.
November 1999 33
peak LED current to about 14mA.
Because there can only be eight LEDs
on at any time, the maximum current
drawn by the Tree is about 150mA.
Any 9V DC plugpack rated at 250mA
or more should be suitable. Do not use
a 12V plugpack otherwise you will
cook the 5V regulator.
Unfortunately, the microcontroller
can’t drive the LEDs directly because
its maximum current ratings would be
exceeded. So each output pin is buffered by a transistor connected as an
emitter-follower. Because each LED
package has two LEDs connected in
inverse parallel, the emitter-followers
have to be “bi-polar” so they can both
source and sink current. So two transistors are used for each output and
they are connected as complementary
emitter-followers so that they can
source or sink current.
Software
The software for the Tree was written in C and compiled by the Dunfield
Micro/C compiler which is available
from Grantronics.
As each byte of pattern data is
read in, it is processed by a simple
interpreter. Each byte is an instruction such as “set colour to red” or
“set LED 22 to the current colour” or
“pause for 500ms”. All the complex
light patterns are built up from these
and similar simple instructions. If
you want to know more about the
instruction codes, you can download
the software from www.grantronics.
com.au
Down on the assembly line
With all the technical stuff out of
the way, let’s get the soldering iron
going and start building. Your solder-
Fig.2: the component overlay for the Christmas Tree. Make sure that you insert
each LED to match the overlay otherwise the colour patterns will not be correct.
In every case, the flat on the LED faces the closest outside edge of the PC board.
ing iron should be temperature-controlled (about 600°F or 320°C) with
a fine tip.
First, check the PC board for shorts
Parts List
1 PC board with Christmas Tree
shape
1 4MHz crystal (X1)
1 20-pin IC socket
1 8-pin IC socket
1 9V 250mA DC plugpack
1 2.1mm PC mounting DC socket (or to suit plugpack)
8 100Ω 0.25W resistors
1 1µF 16VW electrolytic
capacitor
3 0.1µF monolithic capacitors
2 27pF ceramic capacitors
34 Silicon Chip
Semiconductors
1 AT90S2313 programmed
microcontroller (IC1)
1 24C16 programmed EEPROM
(IC2)
1 7805 regulator (REG1)
12 BC547 NPN transistors (Q1,3,5,7,
9,11,13,15,17,19,21,23)
12 BC557 PNP transistors (Q2,4,6,8,
10,12,14,16,18,20,22,24)
32 red/green (bicolour) LEDs
1 1N4002 silicon diode (D1)
1 1N914, 1N4148 signal diode (D2)
between tracks and broken tracks. As
usual, start with the small items such
as wire links and resistors. Next, fit
the IC sockets, crystal, small capacitors, regulator and the diodes. The
regulator should be bolted to the PC
board.
The transistors should be fitted
next. All the BC547s face one way
and all the BC557s face the other way.
Now you can fit the LEDs. Be careful
to insert them the right way and don’t
apply too much heat as the leads are
very short when the LED is pushed
down against the board.
By the way, make sure each LED is
installed the right way around. While
no damage will result if you do put
a LED in the wrong way around, the
resulting colour pattern won’t be
right. You will notice that each LED
position on the PC board has a circular
* Les Grant is the Engineering Director at Grantronics Pty Ltd.
They can supply the programmed microcontrollers and EEPROMs for $15 plus $5 for packing and postage. Send cheque or
postal order to Grantronics Pty Ltd, PO Box 275, Wentworthville,
NSW 2145. Phone (02) 9896 7150.
Complete kits for the Christmas Tree will also be available from
all Jaycar Electronics stores.
workmanship, connect a 9V DC plugpack. No LEDs should light. Measure
between pins 10 & 20 (+) of IC1. You
should have +4.8V to +5.2V.
If all is well, remove power and
plug in IC1 and IC2. Make sure they
are correctly oriented and be careful
not to bend any of their pins as you
plug them into the sockets.
Turn your Tree on and the display
sequence should start within a few
seconds.
If it doesn’t work...
Use this same-size photograph in conjunction with the PC board overlay at
left when assembling the Christmas Tree and you should have no problems.
Be careful that the two types of transistors aren’t mixed up!
outline with a flat on one side – put
each LED in so that it matches the
outline. Finally, C3 and the DC power
connector should be fitted.
Testing
Carefully check your soldering –
use a magnifying glass and a good
light. Mistakes found now are less
embarrassing than damaged components later! Don’t plug in the two
DIL ICs yet.
Do a quick continuity check using
your multimeter’s diode check range
between pin 10 and every other pin
of IC1. There should be no shorts or
diode junctions.
Reverse the probes and you should
see diodes (base-collector junctions)
on the 12 pins that connect to the
LED matrix. A similar test should be
performed with pin 20 as the common
pin. This may seem like a lot of work
but a solder blob shorting an I/O pin
to 0V or +5V may damage IC1 and
spoil your Christmas!
When you are satisfied with your
Modern electronic components
are very reliable and faulty new
components are very rare. All microcon-trollers and EEPROMs programmed by Grantronics are individually tested so problems with these
parts are unlikely.
The reality is that the most common
causes of problems are soldering, a
wrong component or wrong component orientation. So the first step in
sorting out any problems is to thoroughly check your workmanship.
After that, we need to get more logical. If a few LEDs don’t work, are they
all in a single column or row? Maybe
they only glow red and not green?
The column drivers go high and
the rows go low for red and vice versa
for green.
To help with fault finding, the first
few patterns are simple “all one colour” displays. The patterns get more
SC
interesting after that.
AVR Resources on the Internet
Manufacturer’s data sheets, application notes, free development software
and sample source code are available at: http://www.atmel.com
Sample startup code written by Dave Van Horn for the Atmel STK200 Started
Kit: http://www.dontronics.com/8515.html
More sample code and an FAQ http://www.avr-forum.com/
Email list with an active group of AVR enthusiasts
Send an email to atmel-request<at>pic.co.za with the word JOIN in the body
of the email.
November 1999 35
|