Make sure you're fit -with this BBC Micro pulse monitor
So you think you could run a mile and not end up panting like
marathon man?
By MIKE COOK
LOOK at it from my wife's point of view. She enters the kitchen
to see me rummaging through the cupboards with yellow plastic
clothes pegs hanging from my left ear and right little finger.
What is she supposed to think? "I know this might look
odd", I say. "Oh, no", she says smiling nervously
and backing away, "I am sure they will let you wear what
you want when they have taken you away".
It took quite a lot of fast talking to explain that I was merely
trying out part of this month's Body Building exercise.
This is really for the experimenters -a pulse measuring system.
It allows the micro to monitor your pulse rate and give an indication
of blood flow.
To do this there is no need to make any electrical connection
with the skin as we can utilise a property of the blood.
Normally your fingers are not transparent, but if you shine
a strong light through them you can see a dull red light. The
more blood there is, the stronger the colour.
As blood is pumped along, the amount in any one part of the
body varies with the pulse rate.
This is the principle of operation of this month's exercise,
only instead of using visible light we shall use infra red.
It turns out that the skin will let in infra red light more
easily than the visible variety, and also efficient infra red
detectors and emitters are freely available at reasonable cost.
So the object is to illuminate the hand with infra red light
and measure how much gets through.
We can do this in two ways, either by transmission or by reflection.
Using the transmission method the detector and the emitter are
placed on opposite sides of the finger.
This is where the plastic clothes peg comes in. First I bent
the spring so it was not too painful when clamped on. Then I drilled
a hole on one side and pushed the dome part of the LED through.
It was fixed in place using epoxy adhesive to flood the convenient
recess on the back of the peg. I removed the other side of the
peg using a sharp knife and inlaid the detector, again fixing
with epoxy.
Finally I painted the set epoxy black to help prevent ambient
light interference. The basic idea can be gleaned from Figure
I.

Figure I: Transmission clothes peg method
If you prefer, you can use reflection. To do this the detector
and emitter are placed side by side in a suitable holder and the
finger is placed on top of them. See Figure II.

Figure II: The reflection method
Whichever method you use, if there is artificial light about
it is likely to cause interference.
This is because a light bulb is fed with alternating current,
which causes its light output to vary at the same frequency.
We do not normally notice this as the variation is too rapid
for our eyes to
cope with. However the sensitive detector we are using is capable
of picking it up, with the result that a 50Hz signal will be superimposed
over the required signal.
To prevent this we must shield the sensor. This can be done
by wrapping some black cloth around the peg and fastening it up
with a small piece of Velcro.
In fact you might like to construct the detector and emitter
in a band of thick cloth that you just wrap around your finger.
By using silicon rubber compound you can easily make a comfortable
unit. Silicon rubber is often sold in tubes for sealing baths
and it comes in a variety of colours, but you should choose black
to cut out stray light.
Alternatively if you are using the reflection method you can
construct a cover. In any event this is only necessary if you
operate the detector near artificial light.
My method of coping with this when developing the prototype
was to stick it up my jumper - but that's another story!
So how does the detector respond to light? To understand this
we need to look at a little semiconductor physics, but that is
not as frightening as it sounds.
The detector is really a PIN diode, and this diode is made up
of three different types of semiconductor material.
The first is known as P-type as it conducts electricity with
positive charge carriers. These are known as "holes",
which in reality means the absence of an electron.
The second type of semiconductor is known as N-type as it conducts
electricity with negative charge carriers or electrons.
The third is Intrinsic semiconductor material which has no charge
carriers in it and will not normally conduct electricity.
Thus a PIN diode (P-type, Intrinsic, N-type) is composed of
a layer of each type of semiconductor.
Figure III shows a cross section through the diode which is
reverse-biased, in that no current is flowing through it and an
electrical charge is across it.

Figure III: Electron/hole production in a PIN diode
Now if a photon of light (a photon is just a small package)
enters the Intrinsic region of the diode it could collide with
the atoms and bash them about so much that an electron would be
dislodged.
This would in effect create an electron hole pair. This pair
would not recombine as the charge across the diode sweeps them
into the appropriate side.
Remember that like charges repel and unlike charges attract.
This has the effect of generating a small amount of electricity
every time some light enters the Intrinsic region.
The amount of electricity is so small that it has to be amplified.
In this project we are not interested in the amount of light entering
the detector, only in the changes in that light, as these correspond
to the pulse.
Therefore the signal is AC coupled into the amplifier. Figure
IV (on next page) shows the full circuit diagram, which consists
of a high gain differential amplifier and a threshold detector.
Figure IV: The heart rate monitor
A differential amplifier will only amplify the difference between
two inputs. As the detector is a long way off at the end of the
wire it can pick up mains signals, or hum.
However as each wire picks up the same amount of interference,
this will be a common signal.
We only want to amplify the difference between these two wires,
which will be our pulse. So each wire from the detector is fed
into a non-inverting amplifier Al and A2 (see The Micro User December
1983 for a full explanation of how that works).
If the signal in each amplifier is the same then the gain will
be one, because there will be no reduction in the amount of signal
fed back to the negative input. We say it acts as a voltage follower.
However if the signals are different only a fraction will get
back to the negative input, and so the amplifier will have some
gain.
Therefore the first two amplifiers produce a gain of one for
common signals and a high gain for difference signals. This gain
can be adjusted by VR1.
The two signals are fed into a third amplifier, A3, which in
essence is an inverting differential amplifier.
In theory this will only pass difference signals and reject
all common ones. In practice there is some leakage of common signals
due to the internal design of the amplifier and the tolerance
of the components.
To see how this works we first have to consider the workings
of an inverting amplifier. Figure V shows one. Its great advantage
is that it is easy to calculate its gain.

Figure V: An inverting amplifier
If, say, one volt positive is applied to the input then as it
is the negative input, the output will start to go negative.
As the other input is tied to earth, the output will go negative
to such an extent that the potential divider action of the two
resistors produces the same voltage on the negative input.
So the input voltage pulls up the input to the amplifier and
the output goes low enough to balance this out.
The gain is simply the ratio of the two resistors RA/RB so if
we chose 10k and 1k resistors respectively we would have a gain
of 10.
Coming back to Figure IV this balancing act is performed not
about earth but about the point of the common signal. So the output
of this amplifier can be fed through to the analogue input port
at the back of the micro.
The diode D1 removes half a volt from the signal and R8 and
R9 make it suitable for feeding into the computer.
As this is an inverting amplifier the signal is upside down,
which has to be compensated for in the software.
This arrangement alone would allow us to plot a profile of our
pulse, but the pulse rate is an important measurement and, as
we have an amplifier over — there are four in a package — we can
also build a threshold detector.
This is connected to the computer via the fire button input
on the analogue input port. The amplifier A4 is connected as a
comparator with hysteresis (see the March 1984 article for an
explanation of hysteresis).
The output from the pulse amplifier is taken through a diode
to prevent any feedback affecting the pulse's shape.
It is then smoothed by capacitor C3 to remove any signals from
artificial light sources. In the absence of any signal this capacitor
will charge up through R10.
However when a negative pulse is produced the voltage on this
capacitor drops. This voltage is taken through Rl1 to the input
of A4.
When this voltage is above that at the negative input, the output
will go high.
This will feed back a little more voltage to the input via R14
which means the voltage will have to drop further than the switch-on
threshold point in order to reach the switch-off threshold point.
This is known as hysteresis. The size of the hysteresis is governed
by the ratio of R14 and R11.
As the size of the pulse may vary, VR2 allows the threshold
point to be adjusted to suit.
The output of the amplifier then feeds into a transistor which
connects directly to the computer's fire buttons. Across the transistor
is an LED to indicate when a pulse is received.
When the transistor is off the LED lights up. However when the
transistor is on the current is diverted away from the LED and
so it is not lit. This is known as shunting the current.
It is not very usual to do this, but in this case it ensures
a constant current is drawn from the supply. It is diverted through
the transistor or the LED, but it remains constant.
If the LED were in the collector circuit, as it was in my initial
circuit, the switching on and off would feed through pulse interference
to the other amplifiers and so distort the signal.
Finally the infra red emitter needs to be driven with about
100mA as 150mA is the absolute maximum for this device. As the
supply is five volts, this means the resistor needs to be 33 ohms.
A quick calculation will reveal that a 33 ohm resistor with
100mA flowing through it will consume 0.33 watts.
This resistor has to be capable of taking this, and therefore
must have a rating of at least half a watt. Even so it runs rather
hot to the touch.
The circuit has been laid out on a printed circuit board and
is available with all the parts, except the clothes peg, in Body
Build Pack No 11.
It connects to the analogue input port through a small length
of four way cable.
I decided to use this way of connecting to the computer rather
than the printed circuit mounted plug used in the Sound Show board
(December 1983 Micro User) to allow several heart rate circuits
to be monitored if required.
The printed circuit board has the components printed on and
so, as usual, it is just a matter of locating the components and
soldering them in.
The board has provision for mounting the emitter and detector
so that the reflective method can be used by directly placing
the finger on them. This is the method we've used on the made
up version. (See page 122 for details).
However, if you are using the clothes peg, do not mount the
emitter and detector on the board but connect them via cable and
screw connectors.
The infra red detector and emitter are shown in Figure VI. Note
they must be connected the correct way round and make sure the
sensitive face of the detector ends up next to the skin.

Figure VI: The infra red components
Use some of the four way miniature cable to make a lead to the
printed circuit board.
Ensure that the polarity-sensitive components, diode C3 and
IC1, are mounted the right way round. The correct position is
shown on the circuit board.
Having constructed the amplifier and sensor and connected it
up to the computer, it is time to check it out. A test program
is shown in Listing I.
10 MODE4
20 PRINT TAB(0,4);"HEART MONITOR T EST"
30 PPINT"Beeb Bodybuilding Course" 40 PRIHT"THE
MICRO USER April 1984"
50 PRINT"By Mike Cook"
60 PRINT:PRINT
70 *FX16,1
80 REPEAT
90 T%=0
100 TIME=0
110 MOVE 0,A%
120 FOR X%=0 TO 1279 STEP 4
130 A%=(ADVAL(1) DIV 64) EOR &3FF
140 P%=ADVAL(0) AND 1
150 IF P%=0 AND B% THEN SOUHD 1,-10 ,150,1:B%=0:T%=T%+1
160 IF P% THEN B%=1
170 DRAW X%,A%
180 FOR D=1 TO 20:NEXT
190 NEXT
200 CLS
210 REPEAT
220 P%=ADVAL(0) AND 1
230 UNTIL P%=0 OR TIME > 750
240 R%=(T%/(TIME/100))*60
250 PRINT TAB(0,33);T%;" PULSES IN ";TIME/100;"
SEC HEART RATE ";R%;"/MI N"
260 UNTIL FALSE
Listing I: Heart monitor test program
Attach the sensor to your finger. I found I got better results
with the dome of the infra red emitter pressing into the pad of
my finger and the sensor across where the fingernail starts.
Remember to shield the sensor from artificial light. Run the
program and you should see your heartbeat traced across the screen.
You have to be still, otherwise the movement of your hand gives
an interfering signal. I found sometimes that the signal was initially
not very strong but after about 30 seconds my finger "got
used to it" and produced good signals.
You can adjust the amplifier's gain by changing VR1, and when
you have a good series of peaks you can adjust VR2 to light the
LED on every pulse.
The program is designed to give a short bleep every time the
light comes on and makes your computer display look like something
oot of a hospital movie.
As well as plotting your pulse, the program also calculates
your pulse rate per minute.
Generally if this is below 50 then either the circuit is not
working properly or you are dead. I am reliably informed that
a pulse rate of over 160 also means that you are not long for
this world.
In trying this out on various friends, in some cases ex-friends,
I was surprised at how difficult it was for the infra red to penetrate
some of them.
In all cases they produced a much smaller signal than when I
tried it on myself. But then, as my wife says, I always was very
transparent.
In such cases you might achieve more success with the reflection
method described earlier.
Now like all Body Building projects the software provided is
just a beginning. So here are a few lines of explanation about
how it works so that you will be able to modify it for your own
purposes.
Line 70 ensures only one channel of the analogue input port
is active. This allows sampling to take place at the maximum speed.
Line 130 takes the sample and inverts the number to compensate
for the inverting differential amplifier we used.
Lines 150 and 160 make sure that a bleep is produced only on
the transition when the light comes on. It also keeps a count
of the pulses in that scan.
Line 140 sorts out the state of the fire button.
Line 180 introduces a small delay so that a reasonable number
of pulses are shown on the screen. You can alter it if you want
to see more of less of them.
Lines 210 to 230 wait until another pulse is produced so the
heart rate calculations are always done on a whole number of pulses.
Alternatively, if you have not yet set up the threshold of the
trigger, it will automatically initiate another scan after a certain
time has elapsed.
As the area under the curve is proportional to blood flow you
could keep a running total of all the samples to give a rough
idea of how much blood is flowing.
If you do this you can play tricks on yourself by putting the
hand not connected to the sensors in some cold water.
Your brain thinks all the body is getting colder and so will
reduce the blood flow but keep the pulse rate the same. Conversely,
if you put it in hot water the blood flow should increase.
If you are really adventurous how about devising the first ever
bio-feedback computer game?
When thinking about this I was not sure if the game should be
good for you and reduce your heart rate and so be relaxing (or
boring). Or whether to go for socially irresponsible software
and produce a game that increased your heart rate with excitement.
Whatever you decide, you might consider connecting the threshold
signal to one of the control lines on the user port and have the
computer generate an interrupt on every heart beat.
This could then use the internal timer to keep a running total
of your heart rate in a memory location that the computer would
access.
You could even build such a routine int0 an existing game and
produce a compulsory rest if it all gets too exciting.
You can also use it to see how fit you are. The quicker your
pulse rate returns to normal after some exercise the better.
I did try this on our editor, but the only time his pulse rate
increased was when it was his turn to buy a round. You can't win
them all!
See you next month.
Body Build Pack No. 11 consists of:
Rl R2 100K
C3 1uF Tantalum;
R3 5k5
C4 C5 0.1uF paper;
R4 R5 10k 1%
C6 47uF electrolitic;
R6 R7 100k 1%
D1 D2 1N4148;
R8 R9 47k
VR1 25k horizontal preset;
R10 R16 82k
VR2 10k horizontal preset;
R11 10k
IC1 LM324;
R12 7k5
T1 BC182 transistor;
R13 3k3
L1 red LED;
R14 220k
L2 infra red LED TIL38;
R15 220R
S1 infra red sensor TIL 100;
R17 R18 270k
1 12 way terminal block;
R19 R20 1k
1 15 way D-Type plug with shroud;
R22 10R
3 yards subminiature 4 way cable;
R23 R24 1m
1 printed circuit board;
C1 C2 0.luF paper.