This is only a preview of the March 2005 issue of Silicon Chip. You can view 39 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:
Articles in this series:
Items relevant to "A Lap Counter For Swimming Pools":
Items relevant to "Inductance & Q-Factor Meter; Pt.2":
Articles in this series:
Items relevant to "Sending Picaxe Data Over 477MHz UHF CB":
Purchase a printed copy of this issue for $10.00. |
A LAP COUN
for
Swimming
Pools
By RICK WALTERS
Do you swim laps of the pool to keep in shape? It is a great
form of exercise but you’ll know how easy it is to lose
count of the number of laps you have done. This PICAXEpowered counter will keep track of the number of laps
completed, leaving you to get on with the swimming.
38 Silicon Chip
siliconchip.com.au
NTER
T
HOSE FORTUNATE ENOUGH
to swim in a 50-metre pool don’t
have to count very many laps in
order to cover a reasonable distance.
For example, just 20 laps means that
you have swum a kilometre. But even
then, as you plough up and down the
pool, it is pretty easy to get distracted
and lose count. Some people cope
with the problem by swimming five
laps freestyle, five breast-stroke, five
back-stroke and so on.
The problem is worse if you’re
swimming in a 25-metre pool (as many
top-level swimmers regularly train in)
and much worse if you’re swimming
in your home pool, which may be only
10 or 15 metres long. For a 10-metre
pool, you need to do 100 laps to cover
a kilometre.
Believe us, trying to keep track of
that many laps in a home pool while
you swim back and forth is practically
impossible.
This is where our Pool Lap Counter
comes to the rescue. It will display the
number of laps you have completed on
a 2-digit or 3-digit readout, so you can
let your mind wander, do mental arithmetic or compose your new symphony
while you swim up and down.
The Pool Lap Counter consists of
two small plastic boxes. One, the
“main” box, contains the Picaxe counter circuit and 2-digit readout, while
siliconchip.com.au
the other contains a large air-switch
pushbutton which connects to the
main box via a thin air hose and actuates a microswitch when pressed. This
is to avoid an electrical connection
(even in a battery-powered, low voltage device) around the very damp(!)
chemical-laden pool environment.
If you swim more than 99 laps, you
will have to add 100 to the count or add
the third 7-segment LED display.
Two ways of counting
The way it works is as follows. You
place the air-switch at the far end of the
pool (from where you normally start).
You then dive in (or gingerly wade in),
swim to the other end and push the
button, whereupon the display indicates “01”. Congratulations, you have
completed one lap. When you swim up
and back and press the button again,
the display will indicate “03”.
In other words, the display increments by two each time the button is
pressed.
As an alternative, because this Pool
Lap Counter uses the intelligence of a
Picaxe, you can start and finish your
laps at the same end of the pool. In this
case, you push the button to start and it
displays “00”. You then swim up and back,
press the button and it displays “02” and
so on, until you are exhausted!
Eight AA cells (12V) power the
counter. To obtain a reasonable battery
life, the 7-segment displays are lit for
just five seconds each time the button
is pressed.
Of course, the counter ICs are powered while ever the unit is switched
on but this amounts to only a couple
of milliamps.
How the circuit works
Looking at the circuit of Fig.1, IC2
is a 4553 3-digit counter (normally, we
only utilise two digits) with a multiplexed output. IC2 internally selects
digit one, two or three and places the
BCD data for this digit on outputs Q0Q3. These feed IC3, a 4511 7-segment
decoder, which energises the segments
of the two digits, corresponding to the
BCD code. At the same time, output
DS1 or DS2 (pin 2 or pin 1) turns on
transistor Q4 or Q5 to power the corresponding LED display.
The 10mF capacitor and the 100kW
resistor on pin 13 of IC2 reset the count
to zero when power is applied. The
1nF capacitor between pins 3 & 4 sets
the display multiplexing frequency.
All this is fairly straightforward.
The tricky bits are carried out by IC1,
a Picaxe-08 microcontroller. Among
other things, the Picaxe needs to cater
for people who place the Lap Counter
at their start end or at the far end. As
noted above, if you place it at the far
March 2005 39
Here’s what it looks like close up. The box at left is merely the lap sensor –
hit the switch and it sends a burst of air via the clear hose to the main box,
right. This actuates a microswitch which in turn increments the count by
two. You can set the count for odds or evens, depending on which end of
the pool you mount the unit. The air hose can be quite long.
end, the Lap Counter should count to
one the first time you touch the button
and then increment by two for each
subsequent touch.
We cover both contingencies by
fitting jumper J2 for odd increments
and omitting it for even. SK1 is arranged to allow programming of the
chip “in circuit”. Jumper J1 has to be
removed to do this although with the
47kW base resistor for Q1, it is probably
unnecessary.
This method means you must remove jumper J1 (thus removing any
load from pin 7) before you can reprogram the chip.
We also use IC1 to debounce the
pushbutton microswitch S1. This
achieves two things. First, it stops
multiple counts from being recorded
because of contact bounce within the
microswitch itself. Second, it prevents
a miscount if you accidentally push the
button twice within five seconds. You
could easily do this if you come to the
end of a lap, touch the button (or plate
or whatever) and then press it again as
you push off for another lap.
Each time the Picaxe registers the
closing of the microswitch, it gener-
ates two clock pulses to increment
counter IC2.
If you look at the Picaxe listing
(LAPCOUNT.BAS), you will probably
be able to glean what it does but let’s
just briefly outline the procedure.
Each time you push the button, several
things happen. First, IC2 is incremented by two counts (or one count if it is
the first time) and then it is disabled,
preventing it from registering multiple
counts. At the same time, the display
is unblanked for five seconds so that
you can see the count.
Three outputs from IC1 are used to
achieve this procedure. Pin 6 disables
the counter by going high (for five
seconds) to turn on transistor Q2
which then pulls pin 11 (DIS) of IC2
low. Pin 5 of IC1 provides the clock
pulses which are inverted by transistor Q3 before being fed to pin 12 (CLK)
of IC2. Finally, pin 7 of IC1 unblanks
the display by turning on transistor
Q1 to pull pin 4 (BL-bar) of IC3 low
for five seconds.
The three transistors (Q1-Q3) also
provide level translation between the
5V signals from IC1 and IC2 & IC3
which run from the full 12V provided
by the eight AA cells. Regulator REG1
is fitted to provide the 5V rail for the
Picaxe.
As noted in previous issues, there
is a great deal of confusion over the
way the Picaxe ports are numbered,
for what they call pin 3 is actually
pin 4 on the IC and so on. We have
taken the liberty of renaming them in
the more conventional manner as P0,
P1, P2, etc.We have used the decimal
point (pin 8) of the units display as
a power indicator to remind you to
turn the Lap Counter off. This stays
illuminated even when the lap count
is blanked.
Air-switch
S1 is an all-plastic “air-switch”
which is normally used in spas and
other areas where water and power
don’t mix. We got it from our local
pool shop, along with a matching
microswitch and a metre of 5mm clear
plastic connecting tube. The length of
tube can be much longer – depending
on your requirements, it could be as
much as several metres.
We use it here mainly because any
electrical switch put near a pool with
(Left) the air-powered switch we
used to actuate the counter. It’s
normally used in spas and should
be available from most pool shops.
(Right): the switch fitted in an
open UB3 case. The switch just
fits in this case but you might need
to perform minor surgery on the
ridge inside the lid to make sure
it doesn’t foul the switch nut. The
length of 5mm plastic air hose can
be as long as required.
40 Silicon Chip
siliconchip.com.au
salt and chlorine would not last very
long.
When the air-switch button is press
ed it compresses small bellows which
transmit the pressure along the plastic
tube to the microswitch mounted in
the Lap Counter case.
If you don’t wish to go to the added
expense of the air-switch, you could
use a standard pushbutton in the actuator box and run a piece of light duty
figure-8 flex to the Lap Counter case.
Construction
All the circuitry for the Pool Lap
Counter is mounted on a PC board
measuring 141 x 83mm and coded
08103051. It has a notch at one end
to accommodate the microswitch and
chamfers on the four corners.
Even though most people will only
use two 7-segment displays, we have
made provision for a third display
(DS3), together with its driving transistor (Q6). If you fit the third display,
you will have to install another 10
machined pins for DS3 as well as fitting Q6. We have shown the jumper,
which connects IC2 to the base of Q6
Fig.1: the circuit consists of two basic parts – the Picaxe-08 which senses the input from S1 and a display circuit,
consisting of IC2, IC3 and giant LED displays. Display DS3 is optional and is only required if you want to count
more than 99 laps. Who do you think you are, Grant Hackett?
The main box end-on, showing the
connection for the air hose to the
pushbutton lap counter switch.
Here are the giant LED displays
we used – they’ve visible for miles
kilometres a long way! We’ve turned
one upside down so you can see the
pin arrangement. Take care: you can
get them upside down.
siliconchip.com.au
March 2005 41
DS2
DS1
CON2
220Ω
220Ω
220Ω
220Ω
IC3 4511B
100k
Q2
BC549
220Ω
47k
1n
47k
220Ω
J2
ODD
100 µF
47k
10k
10 µF
220Ω
TO
S1
1
1
1
IC2 4553B
CON1
+
47k
10k
IC1
PIC-08
PROG
E
ROF TUOTUC
22k
POWER
CON3
HCTIWSORCIM
10k
Q4
Q6
BC327 BC327
DS3
Q3
BC549
47k
100nF
REG1
78L05
47k
Q1
BC549
1.5k
Q5
BC327
Fig.2: the component
overlay shows
the position of all
components. Note
that the sockets for
the LED displays are
mounted on the track
side of the PC board.
5002 C
15030180
RETNUOC PAL
This is the completed “main box” immediately before the PC board is folded
over and mounted upside down on the four tapped pillars. The battery holders
are held in place with our highly technical (and patented) battery holder holder.
on the overlay so this link will already
be in place.
The board assembly is reasonably
straightforward but as usual, first
42 Silicon Chip
check the board for open circuit tracks
and etching faults, particularly where
the tracks go between IC socket pins.
You will most likely have to make
the cutout for the air-switch yourself.
Use a small hacksaw to make the cuts
parallel to the longer board edges then
use a large pair of bullnose pliers to
break the fibreglass away in small
pieces. If you scribe a deep line, you
will get a clean break but if it’s a bit
ragged, a quick rub with a file will give
you a neat edge.
The first components to mount are
the LED display sockets which mount
on the copper (ie, solder) side of the
PC board.
To get the spacing exact, we use the
displays themselves to hold the pins
while we “tack” the pins in. Cut the
pin strip into four pieces of five pins
and carefully align the LED pins with
the strips and push them on.
Now place the LED sockets on the
track side of the PC board – not the
component side – in the DS1 and DS2
(units & tens) positions. That done,
place the PC board on a flat surface
and solder the outside pins on each
pin strip on both the top and bottom
of the display. There is no need to
worry about the display orientation
at this stage.
Now carefully remove the displays
and solder the remaining pins. A
pointed tip on your soldering iron
will make the job easier but we managed with the usual spade tip and a
lot of care.
Cut about 2mm off each pin on each
display so that it fits flush against the
pin strip.
Now turn the board over to the
component side and fit the seven
siliconchip.com.au
Fig.3: there’s not
much wiring
required – most is
on the PC board
and what’s left uses
plugs and sockets for
convenience. Power
is switched between
the batteries simply
to make the wiring
simpler – this way
there are only two
wires to go to the PC
board.
CON2
1
2
3
4
CON3
JUMPER
SHUNT
S1
PRESSURE
SWITCH
4 x AA CELL HOLDER
4 x AA CELL HOLDER
S2
POWER
links, then the resistors, followed by
the IC sockets, jumper, transistors,
electrolytics and the three polarised
connectors.
Make sure you insert the electrolytics with the correct polarity – and
note that the 10mF electrolytic must
lie flat on the PC board to prevent it
fouling the batteries.
The 3-pin header must also lie flat on
the PC board. As right-angle connectors
are rare, put a dob of glue on the flange
and use cut-off resistor leads to connect it to the board. Only the outside
pins need to be connected. The mating
header has pin 1 marked on it when
you come to connect wires.
Next, fit the mini-shunts to J2 and, if
you are using a pre-programmed PIC,
to pins 3 & 4 of SK1.
Power switch S2 is wired between
the two AA battery holders to simplify
the wiring. Solder one lead from each
battery holder to the switch (one red,
one black) and then the other battery
wires got to connector PL3: black to
pin 3 and red to pin 1. Plug PL3 in.
Resistor Colour Codes
o
o
o
o
o
o
o
siliconchip.com.au
No.
1
6
1
3
1
7
Value
100kW
47kW
22kW
10kW
1.5kW
220W
4-Band Code (1%)
brown black yellow brown
yellow violet orange brown
red red orange brown
brown black orange brown
brown green red brown
red red brown brown
5-Band Code (1%)
brown black black orange brown
yellow violet black red brown
red red black red brown
brown black black red brown
brown green black brown brown
red red black black brown
March 2005 43
Parts List – Swimming Pool Lap Counter
1 PC board, code 08103051, 141 x 83mm
1 plastic case, 158 x 95 x 53mm;
Jaycar UB1 or equivalent
1 plastic case, 130 x 67 x 43mm;
Jaycar UB3 or equivalent
2 16-pin IC sockets
1 8-pin IC socket
1 air switch (S1) – see text
1 SPST miniature toggle switch (S2)
2 flat battery holders to suit 4 AA cells;
Jaycar PH-9204 or equivalent
8 AA cells
20/32 of IC socket strip; Jaycar PI-6470 or equivalent
1 2-pin strip 0.1-inch spacing (J2)
2 mini-shunts
1 2-pin polarised male connector
1 2-pin header (with pins)
1 3-pin polarised male connector
1 3-pin header (with pins)
1 4-pin polarised male connector
(for PIC programmer cable)
4 25mm threaded hex spacers
1 10mm threaded hex spacer
2 3mm x 20mm countersunk head bolts (air switch)
5 3 x 6mm countersunk head bolts
1 3 x 10mm countersunk head bolt
4 3 x 6 mm cheese head bolts
7 3mm nuts
6 3mm star washers
1 65 x 20mm aluminium or fibreglass (battery clamp)
Suitable length hookup wire for air switch
Semiconductors
1 Picaxe PIC-08 programmed with LAPCOUNT.BAS
(IC1)
1 4553 3-digit counter (IC2)
1 4511 BCD to 7-segment decoder (IC3)
3 BC549 NPN transistors (Q1-Q3)
2 BC327 PNP transistors (Q4-Q5)
1 78L05 5V regulator (REG1)
2 70mm 7-segment displays (DS1-2; Jaycar ZD1850 or equivalent)
1 70mm 7-segment display (optional)
Capacitors
1 100mF 16V PC-mount electrolytic
1 10mF 50V RB low leakage electrolytic
1 100nF (0.1mF) 50V monolithic ceramic
(code 104 or 100n)
1 1nF (.001mF) MKT polyester (code 102 or 1n0)
Resistors (0.25W, 1%)
1 100kW
3 10kW
6 47kW
1 1.5kW
1 22kW
7 220W
Now fit the batteries, turn the switch on and measure
the voltage between pins 16 & 8 on both IC2 & IC3 (the
meter’s red test lead goes to pin 16 in each case). It should
be slightly more than +12V. Similarly the voltage between
44 Silicon Chip
;
PICAXE-08 CODE for LAP COUNTER
; using 4553 and 4511 to drive 2 ZD1850 displays
;
;Define inputs and outputs
;
symbol msin = pin4
symbol evenodd = pin3
symbol blankdisp = 0
symbol addcount = 2
symbol odd = 1
;
;Set output states
;
high blankdisp
high odd
low
addcount
;
;
wait
3
;allow IC2 to reset
;
init: if evenodd > 0 then initeven ;if jumper missing start at 0 & inc
by 2
if msin = 0 then initodd
goto init
;
;
initodd:low odd
;else jumper fitted, IC2 pin 11 high
pause 10
;hold high for 10 mS
high odd
;then take low, 1 clocked into counter
goto unblank
;(Q2 inverts logic)
;
initeven:if msin = 0 then inccount ;wait for microswitch to close
goto initeven
;
;
inccount:high
addcount
;2 counts must be added to the
display
pause 10
;take IC2 pin 12 low for 10mS (Q3 inverts)
low
addcount ;then high for 2 mS
pause 2
;
high addcount ;then low for another 10 mS
pause 10
;
low
addcount ;then high again
goto unblank
;now show the new count
;
unblank:low blankdisp ;take IC3 pin 4 high for 5 seconds
wait
5
;(Q1 inverts logic)
high blankdisp ;turn display off
goto initeven
;wait for next closure of microswitch
pins 1 & 8 of IC1 should be within 10% of 5V.
Once these voltages are correct, turn off the power,
insert the three ICs and if you intend to program your
own PIC, do it now. Then fit J1 between pins 3 & 4 of
SK1.
Turn the power on and after a second, the decimal
point on the righthand display should light. So far so
good. Run two twisted wires from the microswitch NO
and C(ommon) contacts to the 2-pin header (PL2). The
polarity is immaterial.
Plug it in and after connecting the tubing from the airswitch pushbutton to the microswitch connector, each
push of the button should advance the counter by two
counts. After five seconds, the count should blank. Note:
the count will only advance after the 5-second delay
when the display is blank.
If everything is operating correctly, you can drill the
siliconchip.com.au
Left: this view shows the PC board mounted inside the case before the 7-segment LED displays are fitted. Note that the
display sockets are fitted to the track side of the PC board. At right is the same shot but with the displays inserted. The
decimal point goes to the bottom, as shown here
08103051
holes in the plastic case and fit the four 25mm spacers,
first fitting a 3mm nut on each of the countersunk
screws. The nut brings the front of the displays flush
with the rear of the perspex, thus holding them firmly
in place.
Mount the air-switch and power switch, fit the batteries
into the battery holders and drop them into the case, then
sit the PC board on the spacers. Adjust the spacers until
the four of them align with the board holes. A Spintite
and a little gentle leverage will do the trick. Place the
clamp strip on top of the batteries to prevent them moving, then secure the PC board using four cheese-head
machine screws and star washers.
The front panel cutout may prove a challenge. We
obtained a small piece of 3mm neutral tint perspex from
a plastics supplier and took it to an engraver who cut it
to size with a chamfer on all four sides. We carefully cut
the hole in the case lid with the reverse chamfer, thus
allowing the perspex to almost sit flush with the lid. A
few drops of superglue held it firmly in place.
C
2005
LAP COUNTER
+
CUTOUT FOR
siliconchip.com.au
MICROSWITCH
The pushbutton switch we used is great for keeping
water and chemicals away from the “works” but is not particularly convenient as far as the swimmer is concerned.
Our swimmer found it a real drag (no pun intended) to
have to stop at the end of each lap and press the button.
With a little thought, we’re sure you can come up with
a much better arrangement.
One possibility is to use a reasonably-sized hinged flap
which the swimmer merely has to make slight contact with
at the end of each lap. Given the mechanical advantage
such an arrangement could produce, a small movement
of the flap could translate into a very positive movement
against the air-switch via a suitable actuator.
Such an arrangement could also be used for swimmers
making tumble-turns. As long as the flap was anchored
securely at the end of the pool, the swimmer’s feet could
do all the switching as he/she pushed off at the end of
each second lap. Whatever you do, just make sure that it
is suitably anchored so that there is no danger of injury
to the swimmer.
We also mentioned before that you could run a much
longer air hose than the length our photos show (merely
for a convenient photo!). The pressure system is quite
E
The lap “sensor”
Fig.4: full-size PC board artwork.
sensitive, so we assume several metres would not be a
problem.
That’s it: a lap counter that will keep track for you
whether you are swimming for fitness. . . or in training
for the Beijing Olympics.
SC
March 2005 45
|