This is only a preview of the April 2003 issue of Silicon Chip. You can view 29 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 "Video-Audio Booster For Home Theatre Systems":
Items relevant to "A Highly-Flexible Keypad Alarm":
Items relevant to "Telephone Dialler For Burglar Alarms":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
MORE FUN WITH THE PICAXE – PART 3
This circuit
has HEART!
The PICAXE circuit this month approximates
animal breathing and heart beats to such an
extent that it seems almost alive!
T
HIS PROJECT AROSE while
discussing heart and breathing
rates with a sports medicine
workmate. It quite convincingly
generates both “heartbeats” and
breathing sounds that alter with
temperature.
Left in a darkened room, it could
easily convince the gullible that it’s a
robot taking a snooze!
For the medics (and non-medics)
amongst you, the three variables wide
ly known as TPR (Temperature, Pulse,
Respiration) are perhaps the most fundamental “what’s up with the patient”
nursing vital signs measure. As an
example, check your own pulse and
breathing rates, both while exercising
and relaxing.
The “heartbeat” LED effect is quite
entrancing, since it slowly increases in
brightness to a maximum, then fades
away again to darkness.
A normal flashing LED of course
just turns on and off , with no dimming action. The beating action here
looks most eye-catching in comparison.
It could even be used as a status
light in a more professional application, perhaps to add a “human touch”
to some otherwise bland piece of
equipment. You may even feel more
affectionate towards your photocopier
by Stan Swan
if it was fitted with one of these heatbeat circuits!
Incidentally, while this is a quite
simple, indeed simplistic, type of
project, it does point towards some of
the “grown up” uses for this type of
circuit in the real world. Many devices
use visual and aural indicators to help
us humans quickly work out what they
are doing – you can easily envisage
this type of circuit being adapted for
such a purpose.
The sensor
The sensor used – a negative temperature coefficient (NTC) thermistor
– has a resistance that decreases as
Even the one-eyed cat was
convinced . . . it was fascinated
by the breathing sound but
couldn’t quite find the person
to whom it was attached.
80 Silicon Chip
www.siliconchip.com.au
the temperature increases – and vice
versa.
This action is, of course, similar
to an LDR as we used last month –
(low resistance in bright light, high
in darkness). However, thermistors
have nothing like the rapid response
or resistance range of an LDR, so the
effects are somewhat slower and less
dramatic.
Typically, an NTC thermistor such
as the 100kΩ <at> 25oC type used here
(Dick Smith Cat. R-1895), shows a
resistance of about 300kΩ near 0oC,
reducing to about 30kΩ when warmed
to 50oC.
A suitable voltage divider network
again exploits this so that a varying
voltage from the thermistor is fed to
the pin 1 I/O channel input – see Fig.1.
Suitable juggling of the “top half”
resistor to 15kΩ yielded some six discrete steps over a 0-50oC temperature
range. If you use thermistors other than
the 100kΩ <at> 25oC type specified here,
you may have to alter this resistor – a
resistance wheel greatly eases the fine
tuning.
Pulse width modulation
The PICAXE-08 can output a Pulse
Width Modulation (PWM) signal that
effectively generates analog voltages
(0- 5V) from digital inputs – in effect
a simple Digital-to-Analog Converter
(DAC).
Rather than a neat train of fixed
width pulses, a “noisy” jumble of 0s
& 1s is produced instead. However,
the overall ratio of highs to lows is as
specified by the duty cycle.
Quite elegant uses of this analog
output can result, such as capacitor
Fig.1: without wanting to sound repetitious, you can instantly see the
similarities between this month’s circuit and the previous two: a thermistor
replaces the LDR in the input “voltage divider”.
charging (and refreshing) to a desired
level but the “heartbeat” use here just
illustrates the PWM action and syntax. (PWM will also be used in a later
PICAXE circuit involving a small DC
motor driven via a transistor).
warm lamp or cup (try to keep water
drops off the electronics of course) or
by placing the unit in the fridge.
Be sure to alert your family first
though, to avoid “there’s something
breathing in the fridge” concerns.
The program
Footnote
Perhaps the most obvious program
need is to prevent the LED action
briefly halting while the piezo sounds.
It’s rather like your heartbeats ceasing
when you breathe! “08s” execute program instructions sequentially, so this
may be hard to overcome, however.
Ample memory space is left for your
own tweaking, with any number of
refinements possible! Wider temperature ranges can be organised by a
Some users report PICAXE programming may be unreliable using
fresh battery packs, since the upper
6V operating voltage may then be
significantly exceeded.
Removing a cell or two, so that only
4.5V or even 3V is supplied, seems to
overcome this problem.
See over for program listing.
Once again, we’ve made a few changes (for clarity) from the PICnic box photo above
to the Protoboard layout at right. Follow the layout and you shouldn’t go wrong!
www.siliconchip.com.au
April 2003 81
PICAXE-08 COMMANDS USED THIS MONTH: PWM
PWM syntax takes the basic form – PWM pin, duty, cycles
(duty & cycle can be program variables or constants).
Pin refers to the PICAXE I/O output pin (0 ,1, 2, 4).
Duty (0-255) specifies the analog level desired (0-5 volts).
Cycles (0-255) specifies the number of cycles (~5ms) delivered.
Example: PWM 1, 100, 8 refers to the pin 1 I/O channel, 100/255
duty, 8 cycles (ie, 100/255 = 39% duty cycle; hence 39% of 5V =
1.96V output).
BASIC PROGRAM LISTING
(This can also be downloaded from http://picaxe.orconhosting.net.nz/heartled.bas)
‘ Demo PWM “Heartbeat/breathing “ PICAXE-08 April.03 SiChip Ver 1.0 14th Feb.03
‘ Best assembled & tested with solderless “PICNIK” box as detailed SiChip Feb.03
‘ Refer http://picaxe.orcon.net.nz for background info & potential of PICAXE-08
‘ Extra parts = 100k NTC thermistor (DSE R-1895),Red LED, 1 x 15k ,1 x 330 Ohm
‘ NTC can be moved off board, but water proof(epoxy/hot melt glue?) if outdoors
‘ New commands here = PWM , SOUND 255 (=hiss),
‘ Ref.PICAXE prog.editor.pdf help files,& BASIC Stamp 1 manuals for insights
‘ via Stan. SWAN (MU<at>W, New Zealand) => s.t.swan<at>massey.ac.nz <=
‘————————————————————————————————
‘ Byte b0= NTC measure-increases as temp rises b1= loop counter 0-255
‘ Variables b2= divided NTC measure (approx.= R) b3= “heartbeat” delay
‘
b4= loop counter 1-6 to give suitable pulse/respiration ratio
‘————————————————————————————————
‘ Lines beginning ‘ are program documentation & could be ignored if need be.
‘ Program available for web download => http://picaxe.orconhosting.net.nz/heartled.bas
‘————————————————————————————————
heartbeat:
‘ LED/PWM thermistor resistance monitoring routine
‘ approximates human TPR heartbeat & breathing!
for b4=1 to 6
readadc 1,b0
b2=b0/4
debug b0
‘ cycle heartbeat loop so approx 10 breathes/min
‘ low res.read NTC value via 15k voltage divider
‘ sub zero temps may give b0=0 & beating ceases!
‘ divide for a conveniently smaller step value
‘ show variable NTC value(s) to attached PC VDU
for b1= 0 to 255 step b2
pwm 2,b1,1
next b1
‘ counter loop so LED has multiple PWM cycles
‘ PWM pin 2 LED one cycle increasing pulse width
‘ effect is a pleasing surging brightness increase
for b1= 255 to 0 step -b2
pwm 2,b1,1
next b1
‘ When warm b2 decreases so step less/beat faster
‘ PWM pin 2 LED one cycle decreasing pulse width
‘ gives a fading brightness instead of sudden off
b3= 100/b2 *10
pause b3
next b4
‘ “invert” NTC b2 value & limit to a useful range
‘ delay decreases as temp rises
‘ continue heartbeat loop until time for breath!
sound 4,(255,80)
pause 400
sound 4,(255,40)
‘ inhale = breathe in “hiss” approx. 1sec
‘ hold 400 millisecs (seems ~normal ?)
‘ exhale = breathe out “hiss” approx. 1/2 sec
goto heartbeat
82 Silicon Chip
‘ repeat routine
Some more references
and parts suppliers
1. http://picaxe.orconhosting.net.nz – author’s enthusiastic PICAXE-08 web page.
Some
more references and
2. http://picaxe.orconhosting.net.nz/heartled.
parts
suppliers.
. . & paste.
bas – program
listing to copy
3. http://www.healthmedialab.com/html/
president/mckin3.html
– a fascinating 1901 TPR chart of then US
President McKinley,
recorded while he was hospitalised with
gunshot wound complications.
4. SILICON CHIP, February & March 2003 –
introducing PICAXE
circuits.
5. www.cpemma.co.uk/pwm.html
– typical of web sites explaining PWM.
6. Dick Smith Electronics stock 100kW/25oC
NTC thermistors – Cat. R-1890 or R-1895.
7. Dick Smith Electronics have large (heart
sized?) 10mm red LEDs –
Cat. Z-4060.
8. Oatley Electronics
(www.oatleyelectronics.com)
and Microzed (www.microzed.com.au)
now stock PICAXE-08 ICs and many
accessories.
PIC, PICAXE, mEL,
ATOM, & Various
Components
ALL IN STOCK
MicroZed Computers
Tel: (02) 6772 2777
Fax: (02) 6772 8987
WebLINK:
www.microzed.com.au
www.siliconchip.com.au
|