This is only a preview of the August 2005 issue of Silicon Chip. You can view 33 of the 112 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 "Programmable Flexitimer":
Items relevant to "Carbon Monoxide Alert":
Items relevant to "Serial LCD Driver":
Purchase a printed copy of this issue for $10.00. |
Flexitimer
An Easy-To-Program Digital Timer
This new multi-purpose timer is much more
flexible than previous designs. You can
program it for a single time period ranging
from one second to 99 minutes and 59 seconds,
or a sequence of two such (independently
programmed) time periods, or up to 99 cycles
of one or two time periods. It’s also easy to
program – just like a microwave oven.
By JIM ROWE
E
LECTRONIC TIMERS have always
been popular. In fact, there are so
many applications for this kind of
project that it’s only scratching the
surface to mention the following:
parking meter reminders, EPROM
erasure timing, darkroom printer/
enlarger timing, PC board etch timing, battery charge timing, industrial
process timing, chess and other board
game timing, debate timing and even
kitchen timing.
38 Silicon Chip
If you want to make a timer with the
widest range of applications, it needs
to have at least two independently
adjustable or “programmable” timing
periods. Ideally, it also needs to be
flexible in terms of the number of time
periods and/or time period sequences
(or cycles) that can be programmed.
Some applications need just a single
time period, timed in “single shot”
fashion, while others need a single
sequence of one time period followed
by a second (and probably different)
time period. Still other applications
may need a sequence of two time periods repeated many times, say for a
total of 20 cycles.
Previous timer designs published in
SILICON CHIP and other magazines have
provided most of these features but
at the cost of operating and programming complexity. This made them a
bit daunting to use and limited their
popularity as a result.
By contrast, this new timer is programmed in exactly the same intuitive
fashion as a microwave oven. First, it
has tens and units buttons to allow you
to key in the exact number of minutes
and seconds for the time period(s) you
want and also the number of timing
cycles you want. There are also buttons
to start and stop the timer manually
and to save its settings for the next
time it’s used and so on.
We’ve dubbed this new unit the
“Programmable Flexitimer”, because
it’s designed to provide the same
order of flexibility as the Flexitimer
siliconchip.com.au
siliconchip.com.au
August 2005 39
Fig.1: the circuit is based on a programmed PIC16F84A-04 microcontroller and this drives an LCD module, two relay driver circuits
(one for Time A and one for Time B) and a piezo buzzer circuit. It’s programmed using 10 pushbutton switches. Resistor RBL sets the
current through the backlighting LEDs on the Altronics and DSE modules (see text).
Par t s Lis t
1 Jiffy box, 158 x 95 x 58mm
4 6mm-long untapped spacers
5 12mm-long untapped spacers
1 M3 x 6mm machine screw
4 M3 x 12mm machine screws,
csk head
5 M3 x 20mm machine screws,
csk head
11 M3 nuts and star lockwashers
1 75mm length of 16-way IDC
ribbon cable
2 16-way IDC ribbon connectors
Main Board
1 PC board, code 04108051, 141
x 83mm
1 12V piezo buzzer (PB1)
1 4MHz quartz crystal (X1)
2 12V SPDT relays to suit
1 PC-mount 2.5mm DC input
connector (CON1)
2 PC-mount 3-way terminal
blocks (CON2, CON3)
1 PC-mount 16-way DIL pin
header (CON4)
1 18-pin DIL IC socket
1 TO-220 heatsink, 6021 type, 30
x 25 x 13mm
Semiconductors
1 PIC16F84A (IC1) programmed
with PICTIME2.HEX firmware
1 7805 5V regulator (REG1)
2 2N7000 MOSFETs (Q1,Q2)
1 PN100 NPN transistor (Q3)
3 1N4004 1A diode (D1,D2,D3)
Capacitors
1 2200mF 25V RB electrolytic
projects described by Rob Evans in
“Electronics Australia” back in the
early 1990s. However, this new design
is based around a programmed PIC
microcontroller chip and, as a result,
is much easier to “drive” than those
earlier timers.
Main features
Here’s a quick summary of its capabilities. First, it provides either one or
two programmable time periods (Time
A and Time B), each of which can be
set independently to any time between
one second and 99 minutes 59 seconds
– with a resolution of one second.
Second, you can set it for just a
single Time A period, or a single
40 Silicon Chip
1 100mF 16V RB electrolytic
3 100nF multilayer monolithic
2 33pF disc ceramic
Resistors (0.25W 1%)
1 100kW
1 4.7kW
4 22kW
2 10W
2 10kW
Display Board
1 PC board, code 04108052/3/4
to suit DSE, Jaycar or Altronics
LCD, 132 x 84mm – see text
1 LCD module, 2 lines x 16 chars
(see text)
1 14-way or 16-way length of SIL
or DIL pin header strip, to suit
LCD module used
10 PC-mount SPST pushbutton
switches (S1-S10)
1 90° PC-mount 16-way DIL
header (CON5)
4 M2.5 x 10mm machine screws,
round head
4 M2.5 hex nuts and lockwashers
8 M2.5 flat washers
4 M3 hex nuts (used as spacers)
Capacitors
1 10mF 16V RB electrolytic
Resistors (0.25W, 1%)
1 68kW
1 12W to suit DSE Z-4172 LCD
module (RBL) – see text
1 18W to suit Altronics Z-7011
LCD module (RBL) – see text
1 10kW mini horizontal trimpot
(VR1)
(Time A + Time B) sequence, or for
multiple Time A or (Time A + Time B)
cycles. In fact, there can be anything
from 2-99 such cycles.
Third, the timer has two internal
relays, one of which is activated during
the Time A period and the other during Time B. Both relays have a set of
mains-rated single pole, double throw
(SPDT) contacts, so they can be used
either separately or together to switch
a wide variety of loads.
Finally, the unit operates from 12V
DC, which can come from either a
battery or a plugpack power supply.
Programming
As mentioned earlier, the time
periods and cycles are programmed
very easily using four pushbuttons:
one each for tens of minutes, units of
minutes, tens of seconds and units of
seconds. The “10-minute” and “1-minute” buttons are also used to program
the desired number of cycles, when
you want more than a single cycle
(the default).
Three further buttons allow you to
set the current input as either Time
A or Time B, or to set the number of
cycles.
Another button (Enter) is then used
to save all of the current time and cycle settings in the PIC’s non-volatile
memory, so that it “remembers” them
when it’s powered up next time.
Finally, the Start and Stop buttons
do exactly as their names suggest –
ie, either start the timer operating or
manually stop it if the need arises.
All of the timer settings and operations are displayed on a small 2-line x
16-character LCD module. This makes
it really easy to operate.
How it works
Fig.1 shows the circuit details of
the Programmable Flexitimer. All of
the real work is done by microcontroller IC1, a PIC16F84A which is programmed with a dedicated firmware
program called PICTIMER.HEX.
In operation, the microcontroller
runs from a 4MHz crystal clock and
does all of the timing by counting
clock cycles – using a combination of
both hardware and software counting.
This gives a timing accuracy of better
than ±0.02%.
The 10 buttons used to program the
various settings and commands into
the PIC microcontroller are connected
in a 3 x 4 matrix configuration. As
shown, the three rows are connected
to the three most significant bits of
IC1’s Port B (RB7, RB6 & RB5), while
the four columns go to the four least
significant bits of this port (RB3, RB2,
RB1 & RB0). This allows the microcontroller to scan all the keys very
efficiently and respond quickly when
they are pressed.
The LCD module is directly driven
by the microcontroller. It’s connected
to the four most significant bit Port B
lines (RB7-RB4) and to the two most
significant bit Port A lines (RA4 and
RA3).
The two Port A lines are used to
enable the LCD controller input for
writing (EN) and to select either its
siliconchip.com.au
Fig.2: install the parts on the main PC board as shown here. Take care to ensure all polarised parts
are correctly orientated and note that connector CON4 goes in with its keyway slot to the left.
A small heatsink is fitted to REG1, so that it can handle the current requirements of backlit LCDs.
data or address/instruction registers
(RS). By contrast, the four Port B lines
are used as a data bus to feed display
character codes and position addresses
to the LCD controller, along with various other function commands.
Trimpot VR1 is used to adjust the
display contrast. It does this by varying the DC voltage applied to pin 3 of
the LCD module.
The two least significant bit Port
siliconchip.com.au
A lines (RA0 & RA1) function as outputs and are used to drive Mosfets
Q1 & Q2, which then control the two
relays. When the unit is running, the
microcontroller turns on Relay 1 (via
Q1) during Time A and Relay 2 (via
Q2) during Time B.
The remaining Port A output line
(RA2) is used to control Q3, which in
turn controls piezo buzzer PB1. In operation, output RA2 briefly goes high
and turns on Q3 to produce a short
“beep” at the end of the programmed
time period(s) or cycles.
Power supply
Power for the unit comes from a 12V
DC plugpack (or battery), with diode
D1 providing reverse polarity protection. This then feeds regulator REG1
which provides a +5V rail to power IC1
and the LCD module. The relays and
August 2005 41
Fig.3: the display board layout for the Altronics LCD modules. Install resistor RBL (18W)
only if you are using a backlit display (Cat. Z-7001) & don’t forget the backlight connections.
Fig.4: follow this display board layout if you are using a DSE LCD module. Again, resistor
RBL (12W) is installed only for the backlit display (Cat. Z-4172).
the buzzer (PB1) are powered directly
from the +12V rail after D1.
Construction
Construction of the Programmable Flexitimer is easy, with all parts
mounted on two PC boards – a main
board coded 04108051 (141 x 83mm)
and a separate display board (132 x
84mm). The latter carries the LCD and
the pushbutton switches, plus a few
42 Silicon Chip
other minor parts. These boards fit
inside a standard UB1 Jiffy box (158 x
95 x 58mm) and are interconnected by
a short 16-way ribbon cable fitted with
16-way IDC connectors at each end.
The connections to the timer relay
contacts are made via screw terminal
blocks located at one end of the main
board.
Note that there are actually three
different versions of the display board,
to suit the three different LCD modules
currently available on the Australian
market. One version (code 04108052)
suits the Z-4170/2 module from Dick
Smith Electronics; a second version
(code 04108053) suits the QP-5515/6
module from Jaycar Electronics; and
the third version (code 04108054) suits
the Z-7000A/Z-7011 module available
from Altronics Distributors.
Fig.2 shows the assembly details for
siliconchip.com.au
Fig.5: the Jaycar LCD modules have only 14 pins and don’t require an external resistor to
set the current through the backlight LEDs.
This completed display board uses the DSE Z-4170 LCD module – ie, no backlighting, so
RBL is left out. Take care to ensure that the flat side of each switch goes to the left.
the main board. Start by fitting the DC
input connector CON1 (may need to
elongate the PC board holes slightly
with a needle file before the connector lugs will pass through), then fit
the two screw terminal blocks (CON2
& CON3). Note that the latter must be
fitted with their wire entry sides facing
the edge of the board.
Next, fit the 16-way DIL pin header
CON4, making sure its locating spigot
siliconchip.com.au
slot goes towards the lefthand end of
the board. That done, fit the two wire
links, followed by the resistors and the
three diodes (D1-D3). Make sure that
the diodes are correctly oriented.
The 4MHz crystal (X1), regulator
REG1 and transistors Q1, Q2 & Q3 are
next in line. Take care with the orientation of REG1 and the transistors and be
sure to use the correct transistor type
at each location.
Regulator REG1 is installed by first
bending its pins downwards through
90° about 6mm from its body. It’s
then fitted to the PC board along with
its heatsink and secured using an
M3 x 6mm machine screw and nut,
before soldering its leads. Smear its
metal tab with heatsink compound
before mounting it, to ensure good
heat transfer.
The next step is to fit an 18-pin sockAugust 2005 43
Fig.6: here are the drilling an cutting details for the base of the case and for the lid. They are reproduced
actual size, so that you can use photocopies as drilling templates.
44 Silicon Chip
siliconchip.com.au
et for IC1 – it goes in with the “notch”
end facing the adjacent edge of the
board (see Fig.2). Follow this with the
two relays and the piezo buzzer (PB1).
There are two buzzer types commonly
available and the PC board caters for
both. It’s just a matter of fastening the
supplied unit in position using two M3
x 12mm machine screws and nuts and
soldering its leads to the board (red to
“+”, black to “-”).
In either case, the buzzer’s connection wires can be cut fairly short before
soldering, to keep the assembly neat
and tidy.
The small non-polarised capacitors
can now be fitted, followed by the two
larger polarised electrolytics. Be sure
to install the electrolytics with the
positive leads oriented as shown.
The main board assembly can now
be completed by plugging the programmed PIC16F84A chip into its
socket. It must be installed with its
notched end towards the bottom edge
of the board, as shown in Fig.2
By the way, if you’re building the
timer from a kit, the PIC will be supplied pre-programmed. However if
you’re building the timer from scratch,
you’ll need to program the chip yourself (or have someone do it for you)
before it’s plugged into the socket. The
PICTIMER.HEX program file will be
available as a free download from the
SILICON CHIP website at www.siliconchip.com.au
Display board assembly
Before installing any parts on this
board, make sure it suits the particular
LCD module you’re using. Of course,
if you’ve bought a kit, then you won’t
have any worries on this score.
Figs.3, 4 & 5 shows the parts layouts
for the Altronics, Dick Smith Electronics and Jaycar versions respectively.
Begin by installing the wire links
and the 68kW resistor, then fit the 16-
Fig.7: here are the drilling details for the end of the case, again
reproduced actual size.
way 90° DIL pin header. Follow these
with trimpot VR1 and the 10 pushbutton switches. Note that the latter are all
mounted with their “flat” side facing
towards the left.
The 10mF electrolytic capacitor is
next on the list. As shown in one of the
photos, it should be mounted “leaning
over” to the left by a small amount, to
reduce its effective height to below
10mm (to ensure it later clears the
back of front panel). Take care with
its orientation.
The next step is to fit the header strip
for the LCD module. This is a 16-way
SIL strip for the DSE module, a 7 x
2-way DIL strip for the Jaycar module
or a 14-way SIL strip for the Altronics
module. In each case, push the shorter
ends of the pins through the board
from above and solder them carefully
to the pads underneath.
Basically, there are six different
LCD modules that can be used with
this unit – three with backlighting and
three without. The three modules with
backlighting are the Altronics Z-7011,
DSE Z-4172 and the Jaycar QP-5516.
The corresponding versions without
backlighting are Altronics Z-7000A,
the DSE Z-4170 and the Jaycar QP5515. Note that the Jaycar modules
have 14 pins, while both the Altronics
and DSE modules have 16 pins.
Installing the LCD module is easy
– it slips down over the header pins
and is secured using four M2.5 x
10mm screws, lockwashers and nuts.
In addition, an M3 nut and two M2.5
flat washers are used to form a 3mm3.5mm spacer between the module
and the board at each mounting screw
point. Alternatively, you can use two
M3 “half nuts” to make the spacer at
each point.
Once the module is in position, it’s
simply a matter of soldering its connection pads to the header pins.
The display board will now be complete, except for resistor RBL which
sets the current for the backlighting
LEDs. This is fitted only if you’re
using an LCD module with backlighting but is not required for the Jaycar
LCD, since the resistor is part of the
module.
Table 1: Resistor Colour Codes
o
o
o
o
o
o
o
o
o
siliconchip.com.au
No.
1
1
4
2
1
1
1
2
Value
100kW
68kW
22kW
10kW
4.7kW
18W
12W
10W
4-Band Code (1%)
brown black yellow brown
blue grey orange brown
red red orange brown
brown black orange brown
yellow violet red brown
brown grey black brown
brown red black brown
brown black black brown
5-Band Code (1%)
brown black black orange brown
blue grey black red brown
red red black red brown
brown black black red brown
yellow violet black brown brown
brown grey black gold brown
brown red black gold brown
brown black black gold brown
August 2005 45
The main board in this prototype unit used a 78L05 regulator. It was later modified to
accept a 7805 regulator (with heatsink), so that backlit LCDs could be used.
Note that for the Altronics module,
you’ll also need to make the “A” and
“K” connections for the backlighting
power (at right).
Once the assembly is completed,
adjust contrast trimpot VR1 with a
small screwdriver to about 10° back
from fully clockwise. This will ensure
you get some kind of display when the
timer and module are first powered
up. The control can be “fine tuned”
for best contrast later, via the small
hole in the front panel.
The next step is to make the short
ribbon cable that’s used to link the
two boards. This is formed from a
75mm-length of 16-way IDC ribbon,
with a matching IDC connector at each
end – see Fig.8. The connectors fit the
opposite way around at each end, so
that the cable can link the two boards
without having to be twisted.
Preparing the box
If you’re building the timer from
a kit, the box will probably be supplied with a silk screened front panel
and with all holes pre-drilled and
cut. However if you’re building from
scratch, you’ll need to drill the box
yourself.
Figs.6 & 7 show the drilling and cut-
ting diagrams for both the box and its
lid. These are reproduced actual size,
so you can directly use photocopies
as drilling templates.
Make sure you countersink the
3.5mm holes in the bottom of the box
and also those in the lid. This can be
done with a 7mm or larger twist drill if
you don’t have a countersink bit. Also,
make sure that you cut the access holes
for the timer’s DC input connector and
terminal blocks at the right-hand end
of the box – see Fig.7.
Next, the front panel artwork can
be attached to the lid. That done, you
can cut the various holes in the label
using a sharp hobby knife.
Final assembly
The main board mounts on the
bottom of the box on four 6mm-long
untapped spacers and is secured using four M3 x 12mm countersink-head
screws and nuts (it only fits one way,
due to the asymmetrical mounting
screw positions).
By contrast, the display board is
mounted on the box lid and is secured
on 12mm-long untapped spacers using five M3 x 20mm countersink-head
machine screws, star lockwashers
and nuts. With some LCD modules,
Fig.8: follow this
diagram to fit the
headers to the
short ribbon cable
that links the two
PC boards together.
46 Silicon Chip
you may also need M3 flat washers to
augment each of the spacers, to make
sure there is enough clearance.
Your timer can now be completed by
fitting the ribbon cable between the two
boards and securing the case lid.
Using the timer
When you first connect the timer
to 12V DC power, it initially displays
“Silicon Chip FlexiTimer3” on the
LCD panel. This message then disappears after a few seconds and is
replaced with a “screen” giving you
the timer’s current settings – plus
“Stop” at lower right to show that it’s
not running.
When the timer is powered up for
the very first time, its initial settings
are these defaults: Time A programmed
to 10 seconds, Time B not programmed
at all (and not even displayed), and
the Cycles set to 1 (for a single timing
sequence). But if you program it with
other settings and save them, these
settings will appear when the timer
is next powered up.
Changing the settings for Time A or
Time B is done using the four uppermost buttons on the left – marked “10
MIN”, “1 MIN”, “10 SEC” and “1 SEC”.
Pressing any of these buttons causes
the timer to change into “Input” mode,
to allow you to key in any desired time
setting from 00 minutes and 1 second
up to 99 minutes and 59 seconds.
If you press any button too many
times, just keep pressing it until the
digit concerned reaches the maximum
and then returns to 0, after which you
can program the value you wanted.
When you have entered the time
value you want, the timer can be
siliconchip.com.au
Fig.9: this artwork can be photocopied onto an A4 label sheet, which can then be affixed to the lid after peeling
off its backing. Clear “Contact” adhesive film can then be fitted over the top, to protect it from dirt and damage.
directed to make this the setting for
either Time A or Time B, simply by
pressing either the “Time A” or “Time
B” button. It’s as easy as that.
Changing the Cycles setting is just as
easy. In this case, you use only the “10
MIN” and “1 MIN” buttons to enter the
number of cycles (from 1-99), and then
press the “SET CYCLES” button.
Once the settings for Time A, Time
B (optionally) and Cycles have been
entered, the timer can be started
simply by pressing (you guessed it)
the “START” button. You’ll then see
it counting down on the LCD panel,
where its status is also shown continuously – ie, whether it’s in Time
A or Time B and the current cycle.
When it reaches the end, it will give
a short beep from the piezo buzzer
and display “Stop” again on the LCD
panel (at lower right). This will also
happen if you press the “STOP” button, to stop the unit before the end of
the programmed time settings.
To save the current settings in
memory for use next time it’s powered
up, just press the “ENTER (SAVE)”
button when the timer is stopped. As
soon as the settings have been saved,
the message “Settings Saved” will be
displayed for a few seconds, to confirm
that it has been done.
To program Time B as well as Time
siliconchip.com.au
A, all you need do is enter its time
setting and then press the “TIME B”
button. Time B will then be enabled
and its setting displayed after Time A.
On the other hand, if you have Time
B already programmed and you want
to disable it again, simply enter a zero
time value (ie, 00:00) and again press
the “TIME B” button. The timer will
recognise the zero time setting and
Time B will be disabled and disappear
from the display.
You can use the timer’s relay contact
terminals to allow it to control all manner of things. All you need to know
is that when the timer is running the
contacts of Relay 1 are activated during
Time A, while those of Relay 2 are activated during Time B. So by connecting
to these terminals, you can arrange for
the timer to turn things on or off during
Time A and/or Time B.
Finally, note that this project should
be used to control low voltage equipment only (up to about 50V). Do not
use it to directly switch mains voltages. If you do want to switch mains
voltages, we suggest that you use this
unit to trigger an external relay which
then does the switching.
Make sure that this external relay
and any mains wiring that’s run to
it is properly anchored and isolated.
However, don’t attempt this unless
Specifications
•
•
•
•
Two independent timing
periods: Time A and Time B
Time A and Time B periods
can be set from 00min-01sec
to 99min-59sec
1-99 timing cycles or continuous cycling – see below
Relay outputs for switching
external devices
Continuous Cycling
A late software modification to
this unit involved adding a continuous cycling mode. This mode is set
simply by entering zero (00) as the
setting for “Cycles”.
The second line of the display
shows “Cont” when the timer is in
this mode. It can be returned to finite
multiple cycle mode simply by setting the number of “Cycles” to any
allowed non-zero value – ie, 1-99.
you know what you are doing and are
completely familiar with mains wiring
SC
practices and techniques.
August 2005 47
|