Heart beat counter

Introduction

HEART!!! It is the most vital organ in our body. It’s also the center of the blood circulation system and basically it acts as a pump to circulate the blood through vessels. The heart-beat rate, as we know,  is the number of times a person’s heart beats in a minute. We measure the heart rate in Beats per Minute (bpm).

It is one of the four vital signs that are often taken by doctors to assess the most basic functions of the patient’s body since it is an indicator to diagnose certain medical conditions. Counting the heart-beats are essential for apposite treatment.

Heart beat counters are important primary devices used in medicine and also by sportsmen. It helps to keep track of one’s Heart beat.

This project is a demonstration of measuring the Heart Beat Count using the microcontroller PIC16F877A. The device is programmed to count the number of Heart beats of the human cardiovascular system sensed by a sensor and to display the count that is obtained.

So, in this project I’m using a sound detector as a sensor because it is one of the easiest methods. Also a sound detector can be very easily used directly to measure the Heart beat itself, by placing it easily on the chest where the strongest Heart beats could be sensed. It is detected by using a microphone and then the sound signal is amplified before it is sent to the microcontroller to be counted. Since the beats are measured ‘per minute’ counter should be programmed to count the beats within a time period of 60 seconds (1 minute). Output will be displayed by the use of 3 SSDs. More details are given in the following sections.

 

 

Materials and Methods

The main objective of this my project is to count the number of heart beats per minute.  First of all the heart beat is detected with a condenser microphone. Then I’ve filtered  the signal by a high pass filter and then it is amplified. A comparator is used to get two voltage levels for the signal.

Since I have to detect the rising edges of the amplified signal, using an interrupter (CCP1 / Capture mode) in the microcontroller to detect and count the rising edges decided to be appropriate. Finally the count obtained for a programmed period of time which is for 1 minute, is displayed with the aid of the three digit seven segment display. The device is also able to clear the count and start counting again when done with one user.

The system consists of four parts. This is discussed in the Design and Construction section. Here I’m going to discuss the methods I’ve adopted and the materials I’ve used to design the circuits.

Methods

 

High – Pass Filtering

 

An electrical filter reshape/reject unwanted frequencies of a signal. The most basic high pass filter includes a capacitor and a resistor. Vout is taken from                    across the resistor as shown in Figure 2.1. In this kind of arrangement the capacitor acts as an open circuit for low frequencies and blocks any input signal. Above the cut-off frequency it allows the entire input signal to pass directly to the output. Cut -off frequency is calculated by  f =1/(2×π×R×C).

FIGURE 2.1: HIGH PASS FILTER

                                                                          

Non – Inverting Amplifying

An op-amp is used as a non inverting amplifier. Non inverting amplifying means that the input voltage signal is applied to the non-inverting terminal of the op-amp resulting an output signal which is ‘in-phase’ with the input signal. A negative feedback should be applied for the amplifier to be stable and to get a high gain. Gain is given by, Av = 1+ (RF/R2). The following is the diagram of a non inverting amp.

                                                                                      FIGURE 2.2: NON INVERTING AMPLIFIER
                                                                           

Comparators

An op amp operating in open loop configuration can be used as a comparator. When the non inverting input is higher than the inverting input of the op amp it saturates at the highest positive voltage it can output. But when the non inverting input is less than the inverting input the op amp saturate s at the lowest output voltage. So a comparator basically gives two voltage level as an output when applied a reference voltage to one of the terminals.

Interrupters (Of the PIC)

 

There are built-in interrupters in the PIC16F877A. CCP! Pin is used as an interrupter in this project. Interrupt is a signal sent to the PIC to mark an event that requires immediate attention. Interrupt requests the PIC to stop performing the current functions and to execute the special code. After it is executed the PIC starts it’s normal execution process. PIC used for the project is programmed into ‘Capture mode’ and to detect ‘every rising edge’.

 

 

Component List

 

                                                                                 Table 2.1: component list

Component

Model

Value

Amount

Microcontroller

PIC16F877A

1

Voltage regulator

LM7805

5 V (output)

1

Oscillator

4 MHz

1

Capacitor

220 uF

3

Capacitor

22 pF

2

40 pin IC base

1

Push on switch

1

Condenser microphone

0.02 V (output)

1

IC

LM324

1

SSD

C/C

3 digit

1

Transistor

BC547

3

Capacitor

0.01 uF

1

Resistor

330 Ω

7

Resistor

1 kΩ

5

Resistor

10 kΩ

2

Resistor

100 kΩ

4

Connectors

Ribbon wires

PIC16F877A

Here in my project I’m using the sophisticated microcontroller PIC16F877A. This microcontroller has 40 pins with 5 I/O ports(A, B, C, D, E). For the Heart beat counter only port D, B and RC2 pin in port C is used. RC2 pin (CCP1) is operated in ‘Capture mode’ and it is set to capture every rising edge of the input signal it receives.
FIGURE 2.3: PIC16F877A PIN CONFIGURATION

LM324 (IC)

LM324 is a low power quad op-amp device. Single supply voltage of this device is from 3 V to 32 V. 0 V can be used for (-Vss). It is a 14 pin IC. Here it is used as an amplifier as well as a comparator.
FIGURE 2.4: LM324 PIN CONFIGURATION

Algorithms and Functions

I introduced separate functions to do a specific task such as interrupting, counting, displaying the count and setting the time period.
TABLE 2.2:LIST OF FUNCTIONS IN ALGORITHM

Function

Description

interrupt isr

Interrupt the program, increase the count (number of interruptions)

separateSSD

Separate the digits in the value taken as the count

disp

Display the value taken for the count

main

Run the main program of displaying the count.

settime

Set the time for 60 secs

   
 

Design and Construction

The device is most useful when it is portable. Thus it should be light weight and it should have a power supply of its own. Also it would be in its best shape if the size of the whole device is small and when the overall cost is low. The design was created to accomplish all these necessities.

All the circuits were designed using Orcad software package. Schematics of the circuits were drawn with the aid of Capture CIS and the PCBs’ were drawn with the help of Layout Plus in Orcad 9.2. The system consists of four parts. Te following is a diagram of the three main circuits. In addition to this there is power supply unit.

Figure 3.1: BLOCK DIAGRAM

Main Circuit

 

Base of the main circuit is the PIC16F877A microcontroller. Interrupter in the PIC is used to detect the rising edges of the signal by setting the CCP1 pin to capture mode that detects every rising edge. The PIC is programmed to count the number of interruptions. The I/O ports, Port D and Port B are used to select the segments and to select the digits of the SSD separately and to display the counted value. It also contains the basic requirements to drive the PIC such as voltage regulators, oscillator and etc.

 

FIGURE 3.1: MOTHER BOARD

 

Sound Signal Amplifying and Detecting Circuit

The condenser microphone detects the sound of the beat. It is put inside the tube of a stethoscope in order to reduce background noises. Then the signal is passed through the high pass filter which includes a capacitor and a resister for further reduction of noise. LM324 IC was used as a non-inverting amplifier and also as the comparator as it has 4 op-amps. The output of this part is received by the PIC’s CCP1 pin as an input.

 

FIGURE 3.2: AMPLIFYING CIRCUIT

 

                

Seven Segment Display Circuit

The three digit SSD is connected to the D port pins to give the counter output through resistors. Cathode of each digit is connected to Port B through a transistor in order to select the digits. The count will start from ‘000’ and increase according to the number of rising edges detected within a minute. At the completion of a minute it will display the final value i.e. ‘072’.

FIGURE 3.3 : DISPLAY CIRCUIT

                    

 

Power Supply

Power for the whole circuit is supplied by two 9 V batteries in series with a center terminal ground. Capacitors are used in the power lines to smooth out the power. Voltage dividers are used to get the desired voltages for the four circuit parts separately. It is very important for the system to have a built in power supply as it is a portable device.

FIGURE 3.4: POWER SUPPLY

Results and Analysis

The signal obtained from the microphone was not clear at first. But by putting it inside a stethoscope helped greatly to overcome this problem. Also the value of the count displayed on the SSD was skipping from 4 counts for each and every pulse. Introducing a delay function to the Interrupter function solved this. Reasons for these problems are discussed in the Discussion and Conclusions.

There is still a problem when starting the device to count. The count rapidly increases in an unusual way and the value skips from 1 to a higher value (3 to 13) at once. But after that it counts the heart beats more accurately and the count increase by one per pulse.

 

TABLE 4.1: RESULTS OF DIFFERENT STAGES

Device

Measurement

Microphone

Output = 0.02 V

High pass filter

Cut off frequency = 159 Hz

Amplifier

Gain = 100

Output = 2 V

Comparator

Vref = 0.45 V

Output = 5 V (for peaks) or 0 V

SSD

The counted value i.e 073

Testing- Amplifying circuit

Testing- Heart beat counter

YouTube Video

Discussion and Conclusions

As I mentioned in the Results and Analysis there were some difficulties I faced in the process of construction. The signal detected from the microphone was not clear enough because of the background noises it picked with the signal. But by putting it inside the stethoscope, these unwanted noises were reduced to a great extent. Also the tube amplifies the sound signal a little.

The other problem I faced was the sudden leaps of the count. When the diaphragm of the stethoscope vibrates for a peak of a pulse, it vibrates another couple of times before coming to a still. These unwanted vibrations are also detected as peaks from the interrupter. Thus, in-between actual pulses the count increases. The code was written with a delay function of 800 ms as it is the standard time in between two pulses to avoid this problem.

But the count still takes a leap when the counting is started although this isn’t seen after the 1st three pulses. Then the counter counts the actual peaks and increment the value of the count one by one.

Future Improvements

Tin the current project an external comparator was used. But since the sophisticated microcontroller PIC16F877A has built in comparators it would be wiser and simple to make use of that facility. The sizes of the daughter cards could have been much smaller in order to reduce the size of the whole device.

Also I could have added a timer to set the counting time for 60 seconds. Then the code could be modified to calculate the Heart rate for a minute.

References