Pulse Sensor

Download as pdf or txt
Download as pdf or txt
You are on page 1of 111

HEART RATE MONITOR

NORISH BIN MOHD SARIFE


52252209349

Report Submitted in Fulfillment of the Requirements


For the Bachelor of Computer Engineering (Hons)
Malaysian Institute of Information Technology,
University Kuala Lumpur

MAY 2013
COPYRIGHT PAGE

Declaration of Copyright and Affirmation of Fair Use of Unpublished


Research Work as stated below:

Copyright @21/05/2013 by Norish Bin Mohd Sarife (52252209349)


All rights reserved for Heart Rate Monitor

No part of this unpublished research may be reproduced, stored in a retrieval system, or


transmitted, in any form or by any means, electronic, mechanical, photocopying,
recording or otherwise without the prior written permission of the copyright holder
except as provided below:

i. Any material contained in or derived from this unpublished research may only be
used by others in their writing with due acknowledgment.

ii. MIIT UniKL or its library will have the right to make and transmit copies (print
or electronic) for institutional and academic purpose

iii. The MIIT UniKL’s Library will have the right to make, store in a retrieval
system and supply copies of this unpublished research if requested by other
universities and research library.

iv
DEDICATION

I would like to dedicate this thesis to my parents whom have supported me


throughout the four years in the university and to whom I am forever grateful. The work
I have done on this project is dedicated to them. Thank you for the support, love, faith
and trust. I am truly blessed as a family. I also want to dedicate this report to our entire
lecturer. Thank you for the guide and support that you have showed me.

v
ACKNOWLEDGEMENT

In this opportunity, I would like to be thankful to The Almighty Allah because


within the time given I had completed Final Year Project 2 and also completed the eight
semester of Bachelor of Computer Engineering (Hons).

The main purpose of doing this project is to fulfill the requirement to complete
the course and to gain knowledge thus applying what we have learned during classes in
our project. There were a lot of new things that I have learned during the research and
analysis for this project.

Second, I would like to express my gratitude and thanks to my supervisor, Miss


Hannah Binti Sofian, for his professional guidance, wisdom, endurance, advices,
motivation and encouragement throughout the project.

I also would like to thank the FYP coordinator of Networking Systems, Mdm
Jasrina Binti Jaffar for her guidance and support. Grateful thanks also go to Mr Sayed
Aziz Bin Syed Hussin and Mdm Jasrina Binti Jaffar my first and second reader for
taking the time to read this report. Thank you for your support, criticism, advice and
supervision and not forgetting my fellow classmates whom supported me in every way.

Finally, I really appreciate to have this responsibility to finish this project. This
task has taught a lot of lesson and knowledge which would be valuable to me in the
future.

vi
TABLE OF CONTENTS

Page no

Title Page i

Declaration page ii

Approval iii

Copyright Page iv

Dedication v

Acknowledgement vi

Table of Content vii

List of Table xi

List of Figures xii

List of Abbreviations xiv

Abstact xv

Abstrak xvi

CHAPTER I: INTRODUCTION 1

1.1 Introduction 1

1.2 Objective 2

1.3 Problem Statement 2

1.4 Project Significant 3

1.5 Project Scope 3

1.6 Limitation of Project 4

vii
CHAPTER II: LITERATURE REVIEW 5

2.1 Introduction 5

2.2 Heart Rate 5

2.3 Types of Heart Rate Monitors 6

2.4 Introduction to Heart Rate Monitor concept 7

2.5 The Related Studies of Heart Rate Monitor 7


2.5.1 Cardiac waveform: key to efficient heart rate monitoring 7
2.5.2 Electrocardiographs 8
2.5.3 Photoplethysmography 10
2.5.4 Pressure sensing method 11
2.5.5 Phonocardiograph 12

2.6 Hardware and Software technology background 14


2.6.1 Universal asynchronous receiver/transmitter 14
2.6.2 Data Logger 14
2.6.3 Microcontroller 15
2.6.4 Visual Basic 16

2.7 Summary 16

CHAPTER III: RESEARCH METHODOLOGY 17

3.1 Introduction 17

3.2 Information Gathering 17

3.3 Structured Model 18


3.3.1 Planning 19
3.3.1.1 Brainstorming session 19
3.3.1.2 Study, research and analysis project title 19
3.3.2 Design 20
3.3.3 Testing 20
3.3.4 Troubleshoot 21

viii
3.4 Block Diagram 22

3.5 GUI/HMI Flowchart 24

3.6 Hardware Requirements 25

3.7 Software Requirements 29

3.8 Budget and Costing 31

3.9 Project Timeline 32

CHAPTER IV: PROTOTYPE/PRODUCT DEVELOPMENT 33

4.1 Introduction 33

4.2 Software Tool for GUI or HMI 33

4.3 Software Tools to Write Program 37

4.4 UART Setting 41

4.5 Programming the Microcontroller 43

4.6 Data Transmit 48

4.7 Printed Circuit Board (PCB) Layout and Schematic Design 50


4.7.1 Design of the schematic using Proteus Software 50
4.7.2 Design of the Printed Circuit Board (PCB) 52
4.7.3 Completing the circuit 53

4.8 Monitoring System (Visual Basic) 54


4.8.1 HRM Main Form 54
4.8.2 HRM Communication Port Form 57

4.9 Complete Product 58


4.9.1 Complete Circuit 58
4.9.2 Complete Heart Rate Monitor model and circuit 59

ix
CHAPTER V: TESTING AND RESULTS 60

5.1 Introduction 60

5.2 Heart Beat Sensor 60

5.3 PIC 16F877A Controller 61

5.4 System Operating Test 66

5.5 GUI/HMI Software 67

CHAPTER VI: CONCLUSION AND SUGGESTION 72

6.1 Introduction 72

6.2 Conclusion 72

6.3 Suggestion 73

REFERENCES 74

Appendix A: GANTT CHART


Appendix B: PROJECT POSTER
Appendix C: PIC16F87XA DATA SHEET
Appendix D: HEART RATE MONITOR CODING
Appendix E: PIC PROGRAMMING

x
LIST OF TABLES

Page no

Table 3.1: Assembly versus other high level language 29


Table 3.2: Budget and Costing 31
Table 5.1: Functionality Testing 71

xi
LIST OF FIGURES

Page no

Figure 2.1: ECG waveform 8


Figure 2.2: ECG system using system on chip 9
Figure 2.3: Photoplethysmograph 10
Figure 2.4: Oscillometric pulses 11
Figure 2.5: HR monitor using pressure sensor and system on chip 12
Figure 2.6: Heart sounds 13
Figure 2.7: Phonocardiograph using a PSoC System on Chip architecture 13
Figure 3.1: Structured Model for HRM project 18
Figure 3.2: HRM block diagram 22
Figure 3.3: GUI/HMI project flowchart 24
Figure 3.4: PIC Microcontroller 27
Figure 3.5: Schematic Design MAX232 28
Figure 4.1: Start the installation 34
Figure 4.2: Install Visual Basic 6.0 Enterprise Edition 34
Figure 4.3: Choose Common Install Folder 35
Figure 4.4: Setup in progress 35
Figure 4.5: Need to restart Windows 36
Figure 4.6: Start installation 37
Figure 4.7: Select a setup type 38
Figure 4.8: Choose destination location 38
Figure 4.9: Installation in progress 39
Figure 4.10: Successfully install 39
Figure 4.11: Setup has finish installing 40
Figure 4.12: PIC Flowchart 42
Figure 4.13: PIC microcontroller programming process 43
Figure 4.14: Select devices 44
Figure 4.15: Select language tool suite 44
Figure 4.16: Locate new MPLAB project 45
Figure 4.17: Select existing assembly code/project 45
Figure 4.18: Project wizard is now completed 46
Figure 4.19: Assembly language 46
Figure 4.20: Build succeeded 47
Figure 4.21: PIC boot loader device 47
Figure 4.22: Super Term 2.21 48
Figure 4.23: Send data 48
Figure 4.24: LCD display 123NORMAL 49
Figure 4.25: Schematic Design Heart Beat Sensor 51

xii
Page no

Figure 4.26: Schematic Design main circuit 51


Figure 4.27: PCB Design Back 52
Figure 4.28: PCB Design Front 52
Figure 4.29: HRM Main Form 54
Figure 4.30: HRM Communication Port Form 57
Figure 4.31: Complete circuit of the project 58
Figure 4.32: The complete project that connect to the computer 59
Figure 5.1: Output voltage 61
Figure 5.2: Heart beat sensor 61
Figure 5.3: Checking input voltage at Diode 62
Figure 5.4: Checking 5VDC at resistor 62
Figure 5.5: Operating voltage at pin 11 63
Figure 5.6: Operating voltage at pin 32 63
Figure 5.7: Checking voltage at LCD 64
Figure 5.8: 5VDC operating voltage at LCD 64
Figure 5.9: Checking IC MAX232 operating voltage at pin 16 65
Figure 5.10: Checking voltage at PIC16F877A 65
Figure 5.11: LCD message during start up 66
Figure 5.12: “No Input” message on LCD 66
Figure 5.13: Communication settings 67
Figure 5.14: No heart beat input 68
Figure 5.15: Heart beat input 68
Figure 5.16: Data logging table result 69
Figure 5.17: Normal result with 72 BPM 69
Figure 5.18: Normal result with 66 BPM 70
Figure 5.19: Heartbeat record 70

xiii
LIST OF ABBREVIATIONS

Abbreviation

Central Processing Unit CPU


Direct Current DC
Light-Emitting Diode LED
Personal Computer PC
Programmable Interface Controllers PIC
Universal Serial Bus USB
Heart Rate Monitor HRM
Visual Basic VB
Graphic User Interface GUI
Human Machine Interface HMI
Beats per Minute BPM
Liquid-Crystal Display LCD
Analog-to-Digital Converter ADC
Electrocardiogram ECG
Buffer Amplifier BUF AMP
Inverting Amplifier INV AMP
Universal Asynchronous Receiver/Transmitter UART
Dual UART DUART
Microcontroller MCU
Integrated Development Environment IDE
Rapid Application Development RAD
Emergency Mode EMG MODE
Light Dependent Resistors LDR
Printed Circuit Board PCB

xiv
ABSTRACT

This project consists of two subsystems, which are hardware system and software system.
Basically, the hardware system consists of microcontroller and other electronic circuits
for detecting the heart pulse rate. The heart pulse rate scanning is base on the use of
LDR sensitivity. The PIC will be able to detect the pulse change, counting the pulse per
minute, send to PC through serial data communication and also display the actual status
on LCD. The software system consists of application program that connect and receive
data through serial, display the result per minute and heart rate status information with
data logging capabilities. There are a number of methods that can be used to detect the
presence of the heart pulse. For example, the ECG wave can be used to produce a
synchronized pulse corresponding to each beat of the heart. Other techniques utilize
pressure differentials due to the pulse or optical methods that cause the pressure pulse
to interfere with a light beam. This project using super bright red LED. The LED is use
as the transmitter and the LDR is use as the receiver. Once the circuit is given a 5 Volt
DC supply, The LED will continuously flash red light onto the LDR surface. This
indicates that the circuit works and after programming the PIC it can produce output for
Heart Rate measurement. The last part of this project is to design and develop Human
Machine Interface (HMI) running on windows base platform with the capability to
display the heart beat pulse signal (digital) and the heart beat pulse per minute with
normal and abnormal status information. This project is done for the use as a future
reference for those who want to do a research on heart rate monitor system.

xv
ABSTRAK

Projek ini mengandungi dua subsistem, iaitu sistem perkakasan dan system perisian.
Umumnya, sistem perkakasan terdiri daripada mikropengawal dan litar-litar yang lain
untuk mengesan kadar degupan jantung. Pengimbasan kadar degupan jantung adalah
berdasarkan penggunaan sensitiviti LDR. PIC akan dapat mengesan perubahan nadi,
mengira nadi per minit, hantar ke PC melalui komunikasi data bersiri dan juga
memaparkan status sebenar pada LCD. Sistem perisian terdiri daripada program
aplikasi yang menghubungkan dan menerima data melalui serial, memaparkan hasil per
minit dan maklumat status kadar jantung dengan keupayaan data logging. Terdapat
pelbagai kaedah yang boleh digunakan untuk mengesan kehadiran degupan jantung.
Sebagai contoh, gelombang ECG boleh digunakan untuk menghasilkan gelombang
degupan jantung yang seragam untuk setiap degupan jantung. Kaedah lain adalah
dengan memanfaatkan kebezaan yang disebabkan oleh degupan atau kaedah optik yang
boleh menyebabkan tekanan degupan mengganggu pancaran. Projek ini menggunakan
LED merah yang sangat terang. LED digunakan sebagai pemancar dan LDR adalah
digunakan sebagai penerima. Apabila litar diberi bekalan 5 Volt DC, LED akan terus
memancarkan cahaya merah ke permukaan LDR. Ini menunjukkan bahawa litar
berfungsi dan selepas pengaturcaraan PIC ia boleh menghasilkan output untuk
pengukuran kadar jantung. Bahagian terakhir projek ini adalah merekabentuk dan
membangunkan Human Machine Interface (HMI) yang berjalan pada platform windows
dengan keupayaan memaparkan signal (digital) denyutan jantung dan denyutan jantung
per minit dengan maklumat status normal dan tidak normal. Projek ini dilakukan
sebagai rujukan di masa depan bagi mereka yang ingin melakukan penyelidikan
mengenai sistem heart rate monitor.

xvi
CHAPTER I: INTRODUCTION

1.1 Introduction

Telemedicine is the most important step in cutting costs and increasing service
quality in health care. The traditional telemedicine systems mostly enable
communication between health professionals in order to give doctors in remote locations
access to specialist’s knowledge and monitoring of patients remotely for home care or
emergency applications. Essentially, these systems provide an extension of hospital
environment and connect diagnostic equipment at home with hospitals using fixed
telephone or satellite networks. Although these systems provide many benefits for its
users there are still many limitations.

One of the main limitations is the lack of mobility that hinders their usage in
many scenarios. Besides that, a more general problem of today’s health care is the
insufficient availability of data conceding the status and medical history of the patient,
both to the medical personnel and to the patient himself. Frequent measurements of vital
signs could give indications about the current status of chronic illnesses and are
necessary for optimization of the treatment, but would incur significant cost.

Recent advancements in development of wide area wireless technologies have


made possible development of new generation of telemedicine systems that should
provide mobile, wearable and flexible health monitoring systems. Such systems will
enable constant monitoring of health data and constant access to the patient regardless of
patient’s current location or activity and with a fraction of cost of the regular face-to-
face examination.

1
1.2 Objective

The main objectives of this project are to design and develop hardware base on
PIC 16F877A microcontroller with the capabilities to detect heart beat pulse from
human body and transmit and receive data between PC using serial data communication
interface.

To design and develop PIC program that can calculate the heart beat pulse
receive and transmit the data to the PC for monitoring purpose. Finally to design and
develop Human Machine Interface (HMI) running on windows base platform with the
capability to display the heart beat pulse signal (digital) and the heart beat pulse per
minute with normal and abnormal status information.

Basically, the system consists of software and hardware system. The software
consists of Visual Basic program to display the output on computer. At hardware part,
system consists of heartbeat sensor module, microcontroller circuits, LCD for quick
display and MAX 232 module.

1.3 Problem Statement

From the patient's view, the existing care system creates an uncomfortable
feeling because they cannot move freely throughout the monitoring progress. Patients
should be in the hospital and if patients with serious heart problems, they are more
limited area of within the designated wards only.

In addition, patients also need make an appointment with the doctor before the
checkup and sometimes it’s very difficult to do because of the vacancy doctors and
patients different. Patient's emotional state should also be considered during the meeting
with doctor because there is a fear or phobia patients during trips to the doctor and have
patients who are afraid to come to the hospital while giving effect to the data taken by
the doctor.

2
1.4 Project Significant

This portable system will be useful whenever there is need for a low cost and low
power monitoring system.

 Provide Immediate notification of abnormalities


 User friendliness
 Accessibility
 Possible markets:

Third world countries

• Poor Medical Infrastructure, facilities and equipment


• Unreliable power supply
• Warfront
• Quick, portable monitoring

1.5 Project Scope

The scope of the project covers the design of the following:

Hardware Controller

 The heart beat scanning mechanism is base on the use of LDR sensitivity.
 The PIC will be able to detect the pulse change, counting the pulse per minute, send
to PC through serial data communication and display the actual status on LCD.
 2 way communications are available between hardware controller and PC.
 User only needs to place his or her thumb and the controller will automatically give
the result after several seconds.

3
GUI/HMI

 Receive data through serial, display the result per minute and heart beat pulse
animation signal or graph.
 Heart rate status information with data logging capabilities.

This project also makes use of MPLAB assembly language programming to


program microcontroller and use LCD for quick display before transfer data to computer
via MAX232.

1.6 Limitation of Project

The main challenge for this project is system running on power supply. If the
power supply run out of power the system is non functional.

Another challenge is the unstable and high sensitivity nature of the Light-
dependent resistor alternatively called an LDR. LDR can be sensitive to high levels of
ambient infrared light example strong sunlight. If this maybe the case try excluding the
light by covering the sensor with some dark fabric example by placing your hand inside
a cloth bag.

4
CHAPTER II: LITERATURE REVIEW

2.1 Introduction

Previously this Heart Rate Monitor project has been done by other student. The
different with this project it is embedded system where the heart rate device itself
interfacing with computer to receive data through serial, display the result per minute
and heart beat pulse signal or graph and also heart rate status information with data
logging capabilities.

In order to gain a better understanding of this project, a research was done on the
topic of this project. The research was found from journals, articles, books and web sites
from the internet.

2.2 Heart Rate

Heart rate is the number of heartbeats per unit of time, typically expressed as
beats per minute (BPM). Heart rate can vary as the body's need to absorb oxygen and
excrete carbon dioxide changes, such as during physical exercise or sleep.

The measurement of heart rate is used by medical professionals to assist in the


diagnosis and tracking of medical conditions. It is also used by individuals, such as
athletes, who are interested in monitoring their heart rate to gain maximum efficiency
from their training. The R wave to R wave interval (RR interval) is the inverse of the
heart rate.

5
2.3 Types of Heart Rate Monitors

Modern heart rate monitors usually comprise two elements: a chest strap
transmitter and a wrist receiver or mobile phone (which usually doubles as a watch or
phone). In early plastic straps water or liquid was required to get good performance.
Later units have used conductive smart fabric with built-in microprocessors which
analyze the EKG signal to determine heart rate.

Strapless heart rate monitors now allow the user to just touch two sensors on a
wristwatch display for a few seconds to view their heart rate. These are popular for their
comfort and ease of use though they don't give as much detail as monitors which use a
chest strap.

More advanced models will offer measurements of heart rate variability, activity,
and breathing rate to assess parameters relating to a subject's fitness. Sensor fusion
algorithms allow these monitors to detect core temperature and dehydration.

Another style of heart rate monitor replaces the plastic around-the-chest strap
with fabric sensors - the most common of these is a sports bra for women which include
sensors in the fabric.

In old versions, when a heart beat is detected a radio signal is transmitted which
the receiver uses to determine the current heart rate. This signal can be a simple radio
pulse or a unique coded signal from the chest strap (such as Bluetooth, ANT or other
low-power radio link) the latter prevents one user's receiver from using signals from
other nearby transmitters (known as cross-talk interference).

Newer versions include a microprocessor which is continuously monitoring the


EKG and calculating the heart rate, and other parameters. These may include
accelerometers which can detect speed and distance eliminating the need for foot worn
devices.

6
There are a wide number of receiver designs, with various features. These
include average heart rate over exercise period, time in a specific heart rate zone,
calories burned, breathing rate, built-in speed and distance and detailed logging that can
be downloaded to a computer.

2.4 Introduction to Heart Rate Monitor concept

The pulse rate will be detected by using heart beat sensor. The data from this
module will be sent to the Analog Digital Converter to convert a continuous quantity to
a discrete time representation in digital form and will be sent to microcontroller and use
LCD for quick display before transfer data to computer via MAX 232. Finally Visual
Basic program will view the output from the devices connection.

2.5 The Related Studies of Heart Rate Monitor

2.5.1 Cardiac waveform: key to efficient heart rate monitoring

Heart rate is one of the most frequently measured parameters of the human body
and plays an important role in determining an individual’s health. Heart rate
measurement is becoming a part of the typical consumer lifestyle, and many
electronic devices such as iPods, exercise equipment, and mobile phones are
becoming able to accurately measure heart rate. This functionality, however, does
not come without added cost. By using multifunctional devices, developers can
reduce the price of introducing new features such as these.

Various methods used to measure heart rate include Electrocardiography,


Photoplethysmography, Oscillometry (Blood pressure monitor method) and
Phonocardiography. Each of these methods measures different phenomenon that
occur in human body during the heart beat or cardiac cycle to determine heart rate.

7
2.5.2 Electrocardiographs

The contraction and relaxation of cardiac muscles causes blood to flow in and out of
the heart. During each cardiac cycle, a group of tissue in the heart called the sino
atrial node (a.k.a. the pacemaker of heart) generates electrical impulses that spread
all through the heart and cause rhythmic contraction and relaxation of heart
muscles. These electrical impulses can be detected by placing electrodes in specific
points in human body. An electrocardiogram (ECG) captures this varying electrical
impulse so shows the overall rhythm of the heart.

This method requires placement of two or more electrodes on specific points of the
human body. The ECG signal is characterized by six peaks and valleys labeled with
successive letters of the alphabet: P, Q, R, S, T and U (Figure 2.1). The P-peak is
produced by muscle contraction of the atria. The R-peak shows the ending of atrial
contraction and the beginning of ventricular contraction. Finally, the T-peak marks
the ending of a ventricular contraction. The magnitude of the R-peak normally
ranges from 0.1 mV to 1.5 mV.

Figure 2.1: ECG waveform

The average heart rate is calculated by first measuring the time interval, denoted RR
interval, between two consecutive R peaks and taking the average reciprocal of this
value over a fixed window, usually 15, 30 or 60 seconds. This average is then

8
scaled to units of beats per minute (bpm). R-peak is a part of the RQS complex
which represents ventricular depolarization. A typical ECG is invariably corrupted
by (i) electrical interference from surrounding equipment (e.g. effects of the
electrical mains supply), (ii) measurement (or electrode contact) noise, (iii)
electromyogram noise (muscle contraction), (iv) movement artifacts, (v) baseline
drift and respiratory artifacts and (vi) instrumentation noise (such as artifacts from
the analog-to-digital conversion process).

Before calculating the heart rate, we must processing the ECG in the analog
(amplification, common mode voltages suppression and filtering) and digital
(digital filtering) domains. Most of these functions can be performed by the
microcontroller in real time. Figure 2.2 shows an implementation of a ECG heart
rate monitor. The INSAMP rejects the CMRR and the signal is pre-amplified to
improve noise immunity.

Figure 2.2: ECG system using system on chip

An antiphase signal is also used. This circuit consists of a buffer amplifier (BUF
AMP) and an inverting amplifier (INV AMP) that applies an inverted version of the
common-mode signal to the hands, with the aim of canceling interference. On the
output of this circuit there is a voltage level shift to automatically detect the
moment hands are placed on the electrodes. The threshold circuit and comparator
detect this moment.

9
From the output of the INSAMP, the EKG signal passes through a high pass filter
and is buffered by the BUF AMP. Then the signal is digitized via an ADC. Later
the digitized signal passes through various filters and pulse calculation routines to
calculate the heart rate.

2.5.3 Photoplethysmography

During each cardiac cycle, the blood vessels pulsate in order to carry blood to/from
different parts of the human body. When light radiation such as infrared is passed
through a blood vessel in a finger or ear lobe, the received light signal from
finger/earlobe are periodic and vary due to the rhythmic flow and absorption
properties of blood. This optical variation is employed to make
Photoplethysmographs.

Photoplethysmography is of two types of transmission and reflection based on the


place from which the light sensed. In this implementation, an IR LED is excited by
a modulated signal to avoid low-frequency interference, and the received light from
finger or ear lobe is sensed by a photodiode which is filtered using a band pass filter
with synchronous demodulator which is in sync with the modulator, Figure 2.3.
This is digitized by an ADC and passed through software filters to shape the pulse.
The heart rate is determined using a software peak detector.

Figure 2.3: Photoplethysmograph

10
2.5.4 Pressure sensing method

The rhythmic contraction and relaxation of the heart exerts a change in blood
pressure along the walls of the blood vessels. As a result, the blood vessels pulsate
in rhythm to the beat of the heart. This pulsation of blood vessels can be sensed by
pressure or piezo sensors placed at appropriate places on the human body like the
wrist. This variation in pressure is used in a blood pressure monitor to measure the
heart rate. Figure 2.4 shows the pulsation of blood vessels in an arm using pressure
sensor with filtering and amplification. These pulses are called oscillometric pulses
and are measured in automatic blood pressure monitors.

Figure 2.4: Oscillometric pulses

The pressure signal from the blood vessel is read by a pressure sensor. The signal is
later amplified and filtered to separate the heart beat signals. Later the signal is
digitized using an ADC. A timer is used as a reference to calculate the heart rate.

11
Figure 2.5: HR monitor using pressure sensor and system on chip

2.5.5 Phonocardiograph

The opening and closing of valves in the heart produces sounds during contraction
and dilation which is normally audible through a stethoscope. These sounds are
rhythmic to heart beat and can be sensed using microphones. Apart from the normal
heart sounds (S1 and S2-Lub and Dub), abnormal sounds called murmurs can also
be recorded. Normal heart sounds are used to determine the heart rate. The normal
heart sounds and different murmurs have different spectral characteristics so with
proper filtering the abnormalities of the heart can be visualized. This acoustic
property is used in phonocardiographs to determine the heart rate. Figure 2.6 shows
normal and abnormal heart sounds.

12
Figure 2.6: Heart sounds

Heart sound signals can be detected using a sensitive microphone connected to the
diaphragm. The electrical signals from the microphone are amplified and can be
passed through a noise filter to remove external noises. Significant murmurs and
rhythmic Lub and Dub sounds can be filtered from the ADC data using digital
filters so that the Lub and Dub signals can be used for the heart rate calculation,
Figure 2.7.

Figure 2.7: Phonocardiograph using a PSoC


System on Chip architecture

13
2.6 Hardware and Software technology background

2.6.1 Universal asynchronous receiver/transmitter

A Universal Asynchronous Receiver/Transmitter, abbreviated UART is a piece of


computer hardware that translates data between parallel and serial forms. UARTs
are commonly used in conjunction with communication standards such as EIA, RS-
232, RS-422 or RS-485. The universal designation indicates that the data format
and transmission speeds are configurable. The electric signaling levels and methods
(such as differential signaling etc.) are handled by a driver circuit external to the
UART.

A UART is usually an individual (or part of an) integrated circuit used for serial
communications over a computer or peripheral device serial port. UARTs are now
commonly included in microcontrollers. A dual UART, or DUART, combines two
UARTs into a single chip. Many modern ICs now come with a UART that can also
communicate synchronously; these devices are called USARTs (universal
synchronous/asynchronous receiver/transmitter).

2.6.2 Data Logger

A data logger (also data recorder) is an electronic device that records data over time
or in relation to location either with a built in instrument or sensor or via external
instruments and sensors. Increasingly, but not entirely, they are based on a digital
processor (or computer). They generally are small, battery powered, portable, and
equipped with a microprocessor, internal memory for data storage, and sensors.
Some data loggers interface with a personal computer and utilize software to
activate the data logger and view and analyze the collected data, while others have a
local interface device (keypad, LCD) and can be used as a stand-alone device.

14
Data loggers vary between general purpose types for a range of measurement
applications to very specific devices for measuring in one environment or
application type only. It is common for general purpose types to be programmable;
however, many remain as static machines with only a limited number or no
changeable parameters. Electronic data loggers have replaced chart recorder in
many applications.

One of the primary benefits of using data loggers is the ability to automatically
collect data on a 24-hour basis. Upon activation, data loggers are typically deployed
and left unattended to measure and record information for the duration of the
monitoring period. This allows for a comprehensive, accurate picture of the
environmental conditions being monitored, such as air temperature and relative
humidity.

2.6.3 Microcontroller

A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on


a single integrated circuit containing a processor core, memory, and programmable
input/output peripherals. Microcontrollers are designed for embedded applications,
in contrast to the microprocessors used in personal computers or other general
purpose applications.

Microcontrollers are used in automatically controlled products and devices, such as


automobile engine control systems, implantable medical devices, remote controls,
office machines, appliances, power tools, toys and other embedded systems.

15
2.6.4 Visual Basic

Visual Basic (VB) is a third-generation event-driven programming language and


integrated development environment (IDE) from Microsoft for its COM
programming model first released in 1991. Visual Basic is designed to be relatively
easy to learn and use. Visual Basic was derived from BASIC and enables the rapid
application development (RAD) of graphical user interface (GUI) applications,
access to databases using Data Access Objects, Remote Data Objects or ActiveX
Data Objects, and creation of ActiveX controls and objects. Scripting languages
such as VBA and VBScript are syntactically similar to Visual Basic, but perform
differently.

A programmer can put together an application using the components provided with
Visual Basic itself. Programs written in Visual Basic can also use the Windows
API, but doing so requires external function declarations. Though the program has
received criticism for its perceived faults, from version 3 Visual Basic was a
runaway commercial success and many companies offered third party controls
greatly extending its functionality.

The final release was version 6 in 1998. Microsoft's extended support ended in
March 2008 and the designated successor was Visual Basic .NET (now known
simply as Visual Basic).

2.7 Summary

After going throughout all this data collections, and by referring to the previous
project that have been done, it’s decided to proceed with the project. Based on the author
research and study, this HRM project benefits from other previous project also, the idea
to enhance the project can be obtained from the input from the supervisor and the reader.

16
CHAPTER III: RESEARCH METHODOLOGY

3.1 Introduction

In this research methodology, researcher must select the appropriate


methodology for this project. The methodology chosen will guide the researcher in
finishing the project successfully and achieving its objectives. Once the topic is chosen,
a lot of study will be made how to solve possible problem such as this research will need
a lot of testing and analysis in order to gather as much as possible information about
how to develop a Heart Rate Monitor system. In this design phase, a single approach has
been decided to be used, which is implementation.

3.2 Information Gathering

After the topic was approved by the supervisor, the researcher has started to
gather all information needed to begin this research. There are some methods being used
for information gathering such as study, research and analysis project title. This method
can be done by referring to:

 Internet
There are some websites on the Internet that can be utilized in order to obtain some
knowledge about the project.

 Article
The researcher also found some articles written by other researchers from around the
world.

17
 Journal
Journal can be found in an education environment such as the library whereby the
researcher could make references regarding the topic.

3.3 Structured Model

The structured model had been chosen as the method for this project. Structured
development is a deliverable project work elements shown in graphical display to
organize and subdivide the total work scope of a project where each phase of
development has different goals.

It consists of four phases including Planning, Design, Testing, and Troubleshoot.


The orderly sequence of development phases is to ensure the sufficiency of
documentation and design reviews that helps to increase the quality, reliability, and
maintainability of the developed HRM system.

Figure 3.1: Structured Model for HRM project

18
3.3.1 Planning

In the Planning phase, the objective and scope of the project is described. The design
and requirement for the project is identified and the project cost estimate is prepared.
This project initiation includes finding the background of research and problem
statement; determine the significance of research, and completing the literature
review. The methodologies used in planning phase are:

 Conduct brainstorming session.


 Study, and research and analysis project title.

3.3.1.1 Brainstorming session

Brainstorming is the process to find the detail of the design and the
technique how to develop the system. After that, it needs to be organizing
and priority based on the results. The following basic rules for
brainstorming ensures better results:

 Start out by clearly stating the objective of the brainstorming session.


 Generate as many ideas as possible.
 Find the better ideas to develop the system.

3.3.1.2 Study, research and analysis project title

The starting point for many projects is often similar to an existing system.
Comparable and observe products and systems contain working versions
of good ideas for gathering information to develop project title. Even if
the current systems are trying to solve slightly different problems, they
often provide valuable clues as to what need to do. The method is
outlined:

19
 Read, record and analysis book, journal, article, magazine and
website about the project title to comprehend what is the Heart Rate
Monitor concept and how does it works.
 Classify all of the types of information in the document. (User,
system requirements, design elements, plans, background material,
irrelevant detail).
 Planning the project architecture based on research.

3.3.2 Design

In this phase, student needs to design and choose the appropriate hardware and
software to build the Heart Rate Monitor. The circuits must be built with a right
schematic so that it can connect smoothly with the computer to display the signal
output in beats per minutes. A schematic shows how electronic components are
connected in an electronic circuit.

Like a map, it uses symbols to represent components, such as resistors and


capacitors, and lines to show how those components are connected to one another.
The student needs to prepare with all related component and devices such as PCB
(printed circuit board), PIC microcontroller (Peripheral Interface Controller), power
supply, heart beat censor module, computer with visual basic and others. The
construction is an important phase because it has to meet the requirement and must
be function. The development of the system is discussed in next chapter.

3.3.3 Testing

The testing phase deals with issues of fuctioning each part of the hardware with the
applicable visual basic application whether its function or not, assessing whether
the objective of the project has been met or not. Testing phase stated as the process
of validating and verifying the project:

20
 To meet the technical project requirements that guided its design and
development.
 To work as expected.

3.3.4 Troubleshoot

In the final stage, troubleshoot the system to define the strength and weaknesses of
this project. Search for the source of a problem so that it can be solved, and the
project can be made operational again. Troubleshooting is needed to develop and
maintain the Heart Rate Monitor system in good conditions.

21
3.4 Block Diagram

LCD DISPLAY (2x16)

Heart Beat
sensor with
OP-AMP
LM 358 PC
PIC Max 232
16F877 Interface PC
MICROCHIP circuit

Reset MICRO
Button CONTROLLER
Selector
Switch MODE

Figure 3.2: HRM block diagram

Heart Beat Sensor

 Capable to detect heart pulse base on illumination change during blood pressure. The
LDR then will detect this change and the output at pin 7 of LM358 will also change.
At every heart beat pulse, there will be a change in output voltage generated by the
LM358

PIC 16F877A

 40 pins Microcontroller unit (microchip): main CPU in order to calculate the pulse
rate, LCD display and data communication between PC

22
Max 232 Interface

 Used as interfacing unit for data exchange between PIC and PC as the characteristic
of the serial data signal are different at both side (PIC and PC).

Reset Button

 Used to reset program executed by PIC 16F877A

Switch MODE

 Used to switch mode either in EMG mode or PC mode. EMG for the emergency
mode where user can monitor heart beat without any connection to PC using LCD
display but cannot save the data. For the PC mode user can use the Heart Rate
Monitor interface with display the result per minute, heart beat pulse animation
signal or graph and heart rate status information with data logging capabilities.

23
3.5 GUI/HMI Flowchart

Start

Initialize Main Form


UART function

Log Data result and status

NO
Display “No Heart Serial Data
Beat Detected” received?

YES

Collect all data,


Display Heart Beat Pulse per
minute,
Graph/Heart beat animation

Heart Beat > or < Display ABNORMAL status


than NORMAL?

YES
NO

Display NORMAL status

Timer Out for Data


Logging?

YES
NO

End

Figure 3.3: GUI/HMI project flowchart

24
3.6 Hardware Requirements

The hardware part will be explained first as this project comprise of several
important hardware and the fact that the hardware part are designed and built first before
anything else. Below show the hardware that was used to build this project:

 PIC 16F877
 LDR sensor
 Regulator LM7805
 LED
 Max232 Interface IC
 DB9 male/female
 Capacitor
 Resonator 4Mhz
 IC base socket 40 pin/18 pin
 PCB board
 LM 358
 LCD 2x16
 Resistor/Variable Resistor
 Diode 1N1001

Introduction to Sensors

A sensor is a device that produces a measurable response to a change in a


physical condition, such as temperature or thermal conductivity, or to a change in
chemical concentration. Sensors are particularly useful for making in measurements
such as in industrial process control.

Sensors are an important part to any measurement and automation application.


The sensor is responsible for converting some type of physical phenomenon into a
quantity measurable by a data acquisition (DAQ) system.

25
Factors to consider when choosing a sensor:

 Accuracy - The statistical variance about the exact reading.


 Calibration - Required for most measuring systems since their readings will drift
over time.
 Environmental - Sensors typically have temperature and/or humidity limits.
 Range - Limits of measurement or the sensor.
 Repeatability - The variance in a sensor's reading when a single condition is
repeatedly measured.
 Resolution - The smallest increment the sensor can detect.

Concept of LDR

Light-dependent resistor alternatively called an LDR, photo resistor,


photoconductor or photocell is a variable resistor whose value decreases with increasing
incident light intensity. An LDR is made of a high-resistance semiconductor. If light
falling on the device is of high intensity then it will lower the resistance value of the
LDR whereas if the intensity of light is low then it will increase the resistance value of
the LDR. Besides that the bigger the LDR the better sensitivity it has.

Circuit Operation

This project using super bright red LED. The LED is use as the transmitter and
the LDR is use as the receiver. Once the circuit is given a 5 Volt DC supply, The LED
will continuously flash red light onto the LDR surface. This indicates that the circuit
works and after programming the PIC it can produce accurate output for Heart Rate
measurement.

The LED emits infrared light to the finger of the subject. The LDR detects this
light beam and measures the change of blood volume through the finger artery. This
signal, which is in the form of pulses is then amplified and filtered suitably by

26
Operational Amplifiers (Op-Amps) and is fed to a low-cost microcontroller for analysis
and display. The microcontroller counts the number of pulses over a fixed time interval
and thus obtains the heart rate of the subject. Several such readings are obtained over a
known period of time and the results are averaged to give a more accurate reading of the
heart rate. The calculated heart rate is displayed on an LCD in beats-per-minute.

Microcontroller

Figure 3.4: PIC Microcontroller

This powerful (200 nanosecond instruction execution) yet easy to program (only
35 single word instructions) CMOS FLASH-based 8-bit microcontroller packs
Microchip's powerful PIC architecture into an 40 or 44-pin package and is upwards
compatible with the PIC16C5X, PIC12CXXX and PIC16C7X devices. Features of the
device:

 256 bytes of EEPROM data memory


 self programming
 ICD (in circuit debugging function)
 2 Comparators
 8 channels of 10-bit Analog-to-Digital (A/D) converter
 2 capture/compare/PWM functions

27
 synchronous serial port can be configured as either 3-wire Serial Peripheral Interface
(SPI™) or the 2-wire Inter-Integrated Circuit (I²C™) bus
 Universal Asynchronous Receiver Transmitter

For programming this project use PIC 16F877A. The reason why choose to use
this type is because of the low cost and wide availability, large user base, extensive
collection of application notes, availability of low cost or free development tools, and
serial programming (and re-programming with flash memory) capability. PIC 16F877A
has 40 pins which suite enough for the project.

MAX232

The MAX232 is an integrated circuit, first created by Maxim Integrated


Products, that converts signals from an RS-232 serial port to signals suitable for use in
TTL compatible digital logic circuits. Figure 3.5 shows the schematic design of
MAX232.

Figure 3.5: Schematic Design MAX232

28
For this project the MAX232 module functions as an interfacing unit between the
microcontroller and the computer. By using MAX232, it enables communication
between the computer and the microcontroller via serial port.

3.7 Software Requirements

MPLAB

MPLAB Integrated Development Environment (IDE) is a free, integrated toolset


for the development of embedded applications on Microchip's PIC and dsPIC
microcontrollers. Programming language use: Assembly.

Why use assembly language for this project? Table 3.1 shows assembly language
versus other high level language.

Table 3.1: Assembly versus other high level language

Assembly Others (High Level Language)


Built in assembler in MPLAB Proof working compiler: need to buy
software (too expensive)
MPLAB can be download without Using freeware compiler: Limited
any prices function and need to confirm the
functionality
Documentation to refer: Only Limited references and sample code to
Datasheet study
So many references: Note, Sample, Need to study the compiler
Instruction code details, datasheet and documentation.
etc
Reduce development time Increase development time

29
Visual Basic

Visual Basic is a programming language and development environment created


by Microsoft. It is an extension of the BASIC programming language that combines
BASIC functions and commands with visual controls. Visual Basic provides a graphical
user interface GUI that allows the developer to drag and drop objects into the program as
well as manually write program code. Visual Basic, also referred to as "VB," is designed
to make software development easy and efficient, while still being powerful enough to
create advanced programs.

30
3.8 Budget and Costing

Table 3.2 below shows the estimated budget to buy all the equipments needed in
order to initiate the project.

Table 3.2: Budget and Costing

No. Item Price (RM) Quantity Total (RM)


HARDWARE
1 Laptop Dell - 1 -
2 LDR sensor 25.00 1 25.00
4 LED 0.20 2 0.40
5 PIC 16F877A 22.00 1 22.00
6 Regulator LM7805 1.50 1 1.50
7 Max232 Interface IC 3.50 1 3.50
8 DB9 male/female 6.60 1 6.60
9 Cap 100uf 0.75 2 1.50
10 USB to Serial cable 19.90 1 19.90
11 Cap 10uf 0.30 5 1.50
12 Resonator 4Mhz 2.85 2 5.70
13 IC base socket 40 pin 0.50 1 0.50
14 LM358 0.90 1 0.90
15 LCD 2x16 25.00 1 25.00
16 Resistor 10k 0.80 5 4.00
17 PIC Burner 90.00 1 90.00
18 Box 9.00 1 9.00
19 Battery 9.90 1 9.90
20 Button reset 0.50 1 0.50
21 Switch 1.50 1 1.50
22 PCB Board 10.00 1 10.00
SOFTWARE
23 Windows XP - 1 -
24 Super Term V2.21 Freeware 1 -
25 Microsoft Visual Basic 6.0 700.00 1 700.00
26 MPLAB Freeware 1 -
TOTAL 938.90

31
3.9 Project Timeline

The duration for this project is one year. Every phase has been identified and
planned systematically to ensure the project will meet the dateline. The Gantt chart is
developed to guide and keep track of the project progress. For further description on the
project schedule, refer to the Gantt chart as provided in Appendix A.

32
CHAPTER IV: PROTOTYPE/PRODUCT DEVELOPMENT

4.1 Introduction

Based on the methodology explained in Chapter III, it is shown that are many
aspects of the project which need to be carefully considered before moving to the
development stage. This chapter explains the prototype development for Heart Rate
Monitor software and hardware. It explains the prototype modules and system interface
used in this development.

First of all, this program will start by configuring the microcontroller


(PIC16F877A). The usage of MPLAB as the software to program the microcontroller is
recommended. Followed by designing the Printed Circuit Board (PCB) of the hardware
and this can be done by using Proteus PCB Design Software. Lastly is the development
of the monitoring system. For the monitoring system student decided to use Visual Basic
(VB).

4.2 Software Tools for GUI or HMI.

The graphical user interface describes anything that application displays to the
user. It is the primary way to interact with the user and allow him or her to interact with
it. Creating great GUI's is something Visual Basic is amazing at. It can create
professional interfaces with minimal effort.

The installer of Visual Basic 6.0 software is downloaded from the official
website. Figure 4.1 shows the installation of Visual Basic 6.0 (Start the installation by
clicking “Next”) and Figure 4.2 shows Custom Server Setup Options.

33
Figure 4.1: Start the installation

Figure 4.2: Install Visual Basic 6.0 Enterprise Edition

34
From Figure 4.3 show to choose the location of the files that are common among
Visual Studio 6.0 applications. Figure 4.4 shows Visual Basic 6.0 Enterprise setup in
progress.

Figure 4.3: Choose Common Install Folder

Figure 4.4: Setup in progress

35
Figure 4.5 shows that Visual Basic 6.0 Enterprise Setup need to restart Windows
to complete the installation.

Figure 4.5: Need to restart Windows

36
4.3 Software Tools to Write Program.

MPLAB Integrated Development Environment (IDE) is a free, integrated toolset


for the development of embedded applications employing Microchip's PIC and dsPIC
microcontrollers. MPLAB IDE runs as a 32-bit application on MS Windows, is easy to
use and includes a host of free software components for fast application development
and super-charged debugging. MPLAB IDE also serves as a single, unified graphical
user interface for additional Microchip and third party software and hardware
development tools. Moving between tools is a snap, and upgrading from the free
software simulator to hardware debug and programming tools is done in a flash because
MPLAB IDE has the same user interface for all tools.

The installer is downloaded from the internet and installed in the personnel
computer. Figure 4.6 shows the installation MPLAB tools first run of it. Start installation
with click button “Next”.

Figure 4.6: Start installation

37
From Figure 4.7 shows Setup Type. User need to select a setup type “Complete”
where all program features will be installed. Figure 4.8 setup will install MPLAB Tools
v8.66 in the following folder.

Figure 4.7: Select a setup type

Figure 4.8: Choose destination location

38
Figure 4.9 below shows the program installing files and updating the registry.
This program will install HI-TECH C Compiler for the PIC10/12/16 MCUs version
9.81. From Figure 4.10 shows HI-TECH C Compiler for the PIC10/12/16 MCUs version
9.81 has been successfully install.

Figure 4.9: Installation in progress

Figure 4.10: Successfully install

39
Figure 4.11 shows setup has finished installing MPLAB Tools v8.66 and ready
to use.

Figure 4.11: Setup has finished installing

40
4.4 UART Setting

The most important configuration is UART (Universal Asynchronous


Receiver/Transmitter). UART depends on timing or the baud rate, therefore the most
important task is to configure the baud rate of microcontroller. The UART is configured
making it ready to communicate with Max 232 module. The settings are:

Baud Rate use for this project is 9600 bps

Data Bits = 8
Parity = None
Flow Control = None
Stop Bit = 1

Com Port number can be set according to the USB to serial port number. The
settings have to be done using programming language of the microcontroller. As an
example, for PIC microcontroller, developer has to use assembly language or C
language to configure these settings.

41
PIC Flowchart
Figure 4.12 shows the step of how the PIC system is working.

Start

Set PIC type


Set Configuration setting

Declare & Define register


name that will be use in
the main program

Set/Define which pin as


input and Output

Initializing Process
(LCD & UART function)

YES
Start Counting Pulses Heart Beat Pulse
detected?

NO
NO Timer Out? LCD Display No INPUT

YES

Display Result & Send


Data to PC

End

Figure 4.12: PIC Flowchart

42
4.5 Programming the Microcontroller

MPLAB software: Development tools use to develop the PIC program for the
hardware controller heart rate monitoring system.

Assembled Machine Code


Assembly Generated
Language HEX files
ASM files
(Using MPLAB)
ASM
(Auto Generated) Assembled

Download Hex
To Microcontroller IC
High level Compiled
Language
(C, Basiq and etc)
Compiler

Figure 4.13: Programming process

Figure 4.13 shows the stage of process to program the PIC microcontroller.

 The program is written using any microcontroller programming software.


 The “.hex” file is written into PIC microcontroller.
 The PIC microcontroller now can be used in real world.

The first step is to install the software, featuring on how to setup MPLAB and
boot loader for the purpose of programming and burning the program into the
microcontroller. Assembly language is used as the programming language for the
microcontroller.

Before start, new folder in drive C has been created and the folder been rename
accordance to project name or title. This folder is now become project folder for ASM
code project.

43
Open MPLAB IDE free download from www.microchip.com. This step also
valid for any lower version of MPLAB software, from Figure 4.14 shows step one by
select devices. Choose the right devices base on project development. Figure 4.15 shows
step two by select language tool suite.

Figure 4.14: Select devices.

Figure 4.15: Select language tool suite.

44
From Figure 4.16 shows step three by Browse where to locate new MPLAB
project and write a name for the project. Recommended: select the project folder that has
created. Figure 4.17 shows step four where user need to select existing assembly
code/project (the assembly code) and click “add” to insert to new MPLAB project.

Figure 4.16: Locate new MPLAB project

Figure 4.17: Select existing assembly code/project

45
Figure 4.18 below shows Project wizard is now completed. Check the summary
and click “Finish”. From Figure 4.19 shows one of the program codes for PIC
microcontroller using MPLAB IDE software. The program is in “.asm” file. The “.asm”
file program can be edited. The source code is based on assembly language
programming.

Figure 4.18: Project wizard is now completed.

Figure 4.19: Assembly language

46
Figure 4.20: Build succeeded

Figure 4.20 show that PIC coding for HRM build succeeded. Program written in
assembly language, a low level programming language that can be converted to machine
language, may be edited with a text editor and run using an assembler program. To build
new project, go to menu “Project” and click on “Build All”. Click on “Absolute” and it
will show the succeeded result after Build process. Hex File generated after succeeded
build. (This is the machine code for the project). After succeeded build, by using PIC
boot loader device it will transfer the Program to PIC Microcontroller. Figure 4.21
below shows the hardware that is used to program the PIC microcontroller.

Figure 4.21: PIC boot loader device

47
4.6 Data Transmit

Data transmit from PIC to PC monitor by 3rd party serial monitoring software
running on windows platform Super Term 2.21 (super terminal). Figure 4.22 shows data
“X,1” represent Heart Beat Signal detected. Figure 4.23 data receive from PC and
display to LCD.

Figure 4.22: Super Term 2.21

Figure 4.23: Send data

48
Transmit data test by using 3rd party serial monitoring software. Figure 4.24
shows Data from PC was successfully received and display to LCD.

*123NORMAL/
“*” and “/” represent start and stop byte.

Figure 4.24: LCD display 123NORMAL

49
4.7 Printed Circuit Board (PCB) Layout and Schematic Design

About Proteus PCB Design Software

Proteus PCB design combines the ISIS schematic capture and ARES PCB layout
programs to provide a powerful, integrated and easy to use suite of tools for professional
PCB Design.

All Proteus PCB design products include an integrated shape based auto router
and a basic SPICE simulation capability as standard. More advanced routing modes are
included in Proteus PCB Design Level 2 and higher whilst simulation capabilities can be
enhanced by purchasing the Advanced Simulation option and/or micro-controller
simulation capabilities.

The products are offered at a number of levels which offer increasing levels of
functionality and design capacity.

4.7.1 Design of the schematic using Proteus Software

Firstly we need to design the Schematic of the PCB. It will show how the
component will be connected to each other. Figure show the complete design of the
schematic.

From Figure 4.25 shows the schematic of heart beat sensor consist 8 resistors and 1
variable resistor, 1 IC LM358 (OP-Amp circuit), 3 LED's including 1 super bright
LED, 3 capacitors and 1 Light Dependent Resistor (LDR). Figure 4.26 shows
schematic design main circuit using Proteus software.

50
Figure 4.25: Schematic Design Heart Beat Sensor

Figure 4.26: Schematic Design main circuit

51
4.7.2 Design of the Printed Circuit Board (PCB)

After completing the first phase which is designing the schematic design of the
circuit, we will move to the second phase. The next phase is to design the PCB by
referring to the schematic that have been complete.

Figure 4.27: PCB Design Back

Figure 4.28: PCB Design Front

52
From design Figure 4.27 and Figure 4.28 we can see the microcontroller (PIC) was
placed at the center of the PCB because the PIC itself will work as the brain of the
circuit. Then there are two outputs from the PCB which goes to the LCD and
MAX232 use as interfacing unit. Then it also showed a few component including
LEDs, resistors, switch and others in the right place.

4.7.3 Completing the circuit

After completing the designing for the schematic and the Printed Circuit Board, it is
time to go to the next phase which to complete the circuit. It including to etching
the circuit and all the soldering process. Etching is a printmaking process that dates
back 500 years. The etching process involves sheets of metal, usually made of
copper or zinc, and acid used to etch the print onto the metal. The artist can use
complicated methods to create different effects, but always relies on acid to etch the
plate. The more complicated the etching, the more time consuming and expensive it
will be.

53
4.8 Monitoring System (Visual Basic)

For the monitoring system GUI, the software that will be use is Visual Basic 6.0.
In VB, a programmer can put together an application using the components provided
with Visual Basic itself. Though the program has received criticism for its perceived
faults, from version 3 Visual Basic was a runaway commercial success and many
companies offered third party controls greatly extending its functionality.

4.8.1 HRM Main Form

The monitoring system will be done as a simple monitoring system, where user can
monitor their own heartbeat.

Figure 4.29: HRM Main Form

54
There are 2 forms that being use to create graphic user interface for Heart Rate
Monitor project they are Form 1 and Form 2. Figure 4.29 above show Form 1 or
Main Form that consist some function, one of the function is to display the result
per minute.

 Comm Setting

Command Button used for show Form 2. It is enable setting for communication
port.

 Time and Date

Used Label to display time and date. It is one of the additional functions. Format for
date "dd/mm/yyyy" and time "hh:mm:ss".

 Beat Test

Another one of additional function is Beat Test. Command Button used to test the
functional of Heart Rate Monitor GUI without input data from hardware device.

 Beat/Min

Using Text Box to display heart beat per minute in digital form. Text setting used
“000”.

 Heart Beat Signal

Picture Box used for real time graph animation on heartbeat signal.

55
 Heart Beat Status

Shape and Label are used to display either Heart Beat Detected or No Heart Beat
Detected. If reading not equal empty or “000” then display Heart Beat Detected.

 Manual Save

Command Button used to manual update for data logging. Record data path is
“\Result.log”.

 Recording Time

Recording time can be set by user in seconds.

 Indicator

Using Shape and Label to show status of heartbeat either Abnormal if rate < 50 and
if rate > 100 (Red Indicator) or Normal if rate > 50 and if rate < 100 (Green
Indicator). Else set as No Input.

 Data Logging Table Result

Label and List Box are used to create Table Result. Date and time, BPM and heart
beat status can be saved automatically based on the Recording Time setting.

56
4.8.2 HRM Communication Port Form

Figure 4.30: HRM Communication Port Form

 Comm Settings

Form 2 where it enables serial communication port setting on GUI. The interfaces
have 4 option of Baud Rate to used 9600 bps, 19200 bps, 38400 bps and 57600 bps.
Baud Rate used for this project is 9600 bps.

The coding for the Heart Rate Monitor system will be provide at The Appendix

57
4.9 Complete Product

After completing all the process, put aside the complete circuit to get a picture of
it. Then the complete circuits were put in the Heart Rate Monitor model that was made
from two small boxes, one for the main circuit including PIC and others, and the other
one for the sensor circuit. The assembling process didn’t need any screw or nail because
it just done by a glue and tape.

4.9.1 Complete Circuit

Figure 4.31: Complete circuit of the project

From the Figure 4.31 it shows picture of the complete circuit of the project. From
the picture HRM circuit is divided into 2 boards of circuit including the main circuit
which consist the microcontroller (PIC), LED, resistors, MAX232 with RS232 DB9
for PC mode, LCD for EMG mode, selector switch mode and also a reset button.
The other circuit board is for the LDR sensor, it built in separate way because it is

58
for comfort the user with flexible sensor device when it will be use for measuring
heart beat from the finger and it need the user in relax condition.

4.9.2 Complete Heart Rate Monitor model and circuit

Figure 4.32: The complete project that connect to computer

After complete the circuit, the circuit needs to be put in the model box. As shown in
figure above, we can see that there are 2 boxes separate with 2 different circuits,
main circuit and sensor circuit. The LCD is for EMG mode.

Beside the model, there is a laptop which is used as the monitoring system (Heart
Rate) GUI in VB. The laptop was connected to the design model through the
MAX232 by a serial data cable.

59
CHAPTER V: TESTING AND RESULTS

5.1 Introduction

This chapter discusses the testing method employed in the development of Heart
Rate Monitor system. Various testing method relevant to the project are discussed.
Result analysis where the analysis includes all the selected guidelines considered
relevant to the prototype quality. Testing is important since the primary purpose is to
detect software and hardware failures such that the defects may be uncovered and
corrected.

5.2 Heart Beat Sensor

Heart beat sensor is design to give digital output of heart beat when finger is
placed on it. The IR LED is use to illuminate a human finger with infrared light. The
light intensity is then modulated by blood pressure changes within the finger before
striking the photo resistor or LDR. The sensor then converts the changing light intensity
into a proportional voltage containing two components below:

 A large DC offset corresponding to the average light intensity


 A small varying signal caused by changing blood pressure

When the heart beat detector is working, the beat LED flashes in synchronization
to the human heart beat. It works on the principle of light modulation by blood flow
through finger at each pulse. In order to make sure that the heart beat sensor was
successfully design and developed, 2 method of testing have been done as shown in the
picture below.

60
a. From Figure 5.1, Using Digital Multimeter to get output voltage. Voltage test on the
output pin 7 of LM358. DC power supply used 9 volt to 12 volt.

Figure 5.1: Output voltage

Low pulse voltage = 0.921v


High pulse voltage = 2.717v

b. Figure 5.2 below show that finger is place between LED and LDR sensor and the
LED flashing in synchronization with the human heart beat.

Figure 5.2: Heart beat sensor.

5.3 PIC 16F877A Controller

Before continue to the software development of PIC16F877A source code, the


hardware functionality of PIC16F877A controller must be working in perfect condition
otherwise we will facing a lot of problem during software testing and development
stages. There are several important testing that can be use to prove that the hardware is
working in accordance to the design.

61
a. Figure 5.3 shows multimeter reading input voltage at Diode. 9VDC to 12VDC
incoming: Power Supply base on LM7805 regulator unit.

Figure 5.3: Checking input voltage at Diode

b. 5VDC operating voltage on LM7805 output as shown in Figure 5.4.

Figure 5.4: Checking 5VDC at resistor

62
c. Figure 5.5 and 5.6 shows 5VDC operating voltage from LM7805 supply to VDD pin
of PIC16F877A (pin 11 and pin32).

Figure 5.5: Operating voltage at pin 11

Figure 5.6: Operating voltage at pin 32

63
d. From Figure 5.7, 5.8 and 5.9 shows 5VDC operating voltage from LM7805 supply
to VCC pin of 2x16 LCD and MAX232 interface circuit.

Figure 5.7: Checking voltage at LCD

Figure 5.8: 5VDC operating voltage at LCD

64
Figure 5.9: Checking IC MAX232 operating voltage at pin 16

e. Figure 5.10, 5VDC supply to MCLR (master clear) pin 1 of PIC16F877A

Figure 5.10: Checking voltage at PIC16F877A

65
5.4 System Operating Test

The main function of the PIC controller are to detect the pulse rate signal
generated by the heart beat sensor LM358, counting the pulse in order to get the BPM
result and transmit the data to the PC through MAX232 serial interfacing circuit. Then,
the reply status from PC will be display to LCD unit.

Figure 5.11: LCD message during start up

Figure 5.12: “No Input” message on LCD

66
From Figure 5.11 shows LCD message during start up and Figure 5.12 shows
“No Input” message on LCD when there is no finger placed at the sensor unit.

5.5 GUI/HMI Software

a. Figure 5.13 shows Serial Communication Port Setting on GUI for Heart Rate
Monitor. Setting used as below:

Figure 5.13: communication settings

Baud Rate use for this project is 9600 bps


Data Bits = 8
Parity = None
Flow Control = None
Stop Bit = 1

Com Port number can be set according to the USB to serial port number

67
b. Figure 5.14 shows Main Form display result during no heart beat input on Heart Rate
monitor GUI.

Figure 5.14: No heart beat input

c. Figure 5.15 shows Main Form display result during heart beat Input detected. Heart
beat signal animation was successfully generated base on heart beat signal received
from PIC controller. Heart beat status can be save automatically base on the
Recording Time setting.

Figure 5.15: Heart beat input

68
d. Figure 5.16 shows data logging table result on VB. Its record all data input from
sensor.

Figure 5.16: Data logging table result

e. Figure 5.17 below show that the GUI display is running in synchronization with the
PIC controller reading. Normal result with 72 BPM value and Indicator turn to green
color.

Figure 5.17: Normal result with 72 BPM

69
Figure 5.18: Normal result with 66 BPM.

Figure 5.18 above shows Normal result with 66 BPM value and Indicator turn to
green color. Formula use to calculate BPM: Sample time = 10s Counting how many
beat detected within 10s then: BPM = Total Beat x 6.

Figure 5.19: Heartbeat record

From Figure 5.19 above shows line charts result for heartbeat record every 10
seconds in BPM from 3 random persons.

70
Table 5.1: Functionality Testing

No Feature Tested Functions to be tested Results

Test 1 Test 2 Test 3

1 Sensor operating - Voltage test on the output - PASS - PASS - PASS


voltage pin 7 of LM358
2 PIC16F877A - Voltage test on the output - PASS - PASS - PASS
Controller (main LM7805, PIC16F877A,
circuit) LCD and MAX232
3 Connection - Advanced Port Settings - FAIL - FAIL - PASS
computer and set COM Port Number to
circuit hardware COM 2 / COM 10
4 Data transmit and - Hardware sensor circuit. - FAIL - PASS - PASS
receive LDR and LED check.
5 GUI/HMI Heart - Monitor by serial - PASS - PASS - PASS
Rate Monitor data monitoring software.
input

Table 5.1 shows the functionality tested for this project. All the test functionality
was tested thoroughly. During the 3rd test, there were defects found in connection
between computer and circuit hardware functionality. The computer was trying to
connect to circuit hardware using USB to serial data converter were failed. Problem
detected, having issue or conflict with Communication Port. Errors while making
connection at Ports (COM&LPT) and test were conduct by configure setting
Communication Port for serial communications (COM1) result error. Next test 2
configure setting (COM2) still Communication Error. Test 3 problem solve with
Advanced Port Settings set COM Port Number to COM10 result no error. On the 1st, 2nd
and 5th test all the steps tested were passed. 4th test, data transmit from PIC to PC monitor
by 3rd party serial monitoring software fail. Problem detected LDR and LED soldering
loose. Solution solders back LDR and LED.

71
CHAPTER VI: CONCLUSION AND SUGGESTION

6.1 Introduction

This chapter discusses the suggestion of future work for the project and
conclusion will be made according to the project development. This thesis has discussed
the development of the sensor module, main circuit and interfacing with computer.

6.2 Conclusion

The design of a low-cost microcontroller based device for measuring the heart
pulse rate has been described. The device has the advantage that it can be used by non-
professional at home to measure the heart rate easily and safely. With this system the
patient will be more proactive with their doctor because it appears prevention is better
than cure. Here I can say that this Heart Rate Monitor project have achieved all of its
objectives.

An important factor to finish this project is the overall processes that have been
considered. Enough knowledge is required along the process. Earlier preparation is
needed for the components that are limited. More components should also be ready as a
precaution from unpredictable situation such as components burned and not in good
condition. Some suggestion has been made for the limitation of heart beat sensor
accuracy due to the LDR mounting and light exposure (sensitive to light).

Lastly, taking into account issues related to the completion of the project, it is
hereby suggested that the project be continued and further developed in the area of
software and hardware enhancement.

72
6.3 Suggestion

In order to improve the project function and implementation in the future, several
suggestions are proposed:

1. Use of mobile phone to replace personal computer. There are many types of
mobile phone with Bluetooth features. Research should be done to find new
method in order make this system functions using mobile phone. If the mobile
phone replaces the computer, the system will be more convenient and practical.

2. Use of different types of techniques to detect the heart rate. There are number of
methods and technique to detect the heart rate, for example ECG and optical
sensor. This kind of method is more accurate than this project method. But the
main problem is that, this method is more difficult to design and implement.

73
REFERENCES

[1] Evangelos Petroutsos,(1998), Mastering Visual Basic 6.0, In Sybex (Ed).


0782122728

[2] Peter Spasov (2005), Microcontroller Technology, Fifth edition, Sir Sandford
Fleming College: Prentice Hall.

[3] Pulse Detector Through Difference Amplifier by Norwahidah Mohd Noor


Fakulti Kejuruteraan Elektronik & Kejuruteraan Komputer Kolej Universiti
Teknikal Kebangsaan Malaysia 2006.

[4] Home Patient Monitor by Idriah Safriza UniKL BMI in Medical Electronics
Engineering and Legenda Group of Colleges in Higher National Diploma
Electrical and Electronics Engineering.
http://idriah-safriza.blogspot.com

[5] Design Standard for Rigid Printed Boards and Rigid Printed Board Assemblies.
IPC. September 1991. http://classes.soe.ucsc.edu

[6] Microchip Technology Inc. PIC16F877A Data Sheet: 28/40/44-Pin Enhanced


Flash Microcontrollers
http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf

[7] ENGN3227, Analogue Electronics Heart Rate Monitor by Ken Li CHONG


u2554259 David HOLDEN u2544548 Tim OLIN u2560340.
http://wwwnskelectronic.in/heart_beat.html

[8] MPLAB® X Integrated Development Environment (IDE)


http://www.microchip.com/pagehandler/en-us/family/mplabx/

74
[9] Universal Asynchronous Receiver/Transmitter (UART)
http://www.quicklogic.com/assets/pdf/data_sheets/QL_UART_PSB_DS_RevC.p
df

[10] Sana M. Ceesay., Adrew M. Prentise., & Keeneth C.Day. (2002). The use
of heart rate monitoring in the estimation of energy expenditure a validation
study using indirect whole-body calorimetry, 175-186

[11] Juul Achten., & Asker E. Jeukendrup. (2003). Heart Rate Monitoring. Vol
33, Issue 7, pp 517-538.

[12] John, E. S ., Stephan , A. and David, C. (1993) Pulse Oximetry Through Spectral
Analysis, University of South Florida Department of Anesthesiology, University
of South Florida Center for Microelectronics Research.

[13] M. Malik, "Guidelines: Heart rate variability Standards of measurement,


physiological interpretation, and clinical use", Eur Heart J., vol. 17, pp354–38,
1996.

[14] Microsoft Visual Basic 6 Deluxe Learning Edition Michael Halvorson (Author),
Microsoft Press (Publisher)

[15] (2004). Max232, Max 2321 Dual EIA-232 Drivers/ Receivers, Texas Instruments
Incorporated
http://www.ti.com/lit/ds/symlink/max232.pdf

[16] Jojo., ( 2011). PIC Tutorial – 16F877


http://www.circuitstoday.com/pic-tutorial-16f877

75
[17] Wendy.B., (2012). Heart Rate Monitor
http://walking.about.com/od/prpedometer/fr/dashtrak.htm

[18] Sharief F. Babiker,. Liena Elrayah Abdel-Khair,. & Samah M. Elbasheer.


(2011). Microcontroller Based Heart Rate Monitor using Fingertip Sensors.
UofKEJ Vol. 1 Issue 2 pp. 47-51

[19] (2002). Microchip.MPLAB® C17 C COMPILER USER’S GUIDE, Microchip


Technology Inc.(1-360), from
http://ww1.microchip.com/downloads/en/DeviceDoc/51290a.pdf

[20] V.Ryan., (2000-2008). Light Dependant Resistor(LDR).World Association


Technology Teachers, (1-3), from
http://www.technologystudent.com/pdfs/ldrsht1.pdf

76
APPENDIX A: GANTT CHART
APPENDIX B: PROJECT POSTER
APPENDIX C: PIC16F87XA DATA SHEET
APPENDIX D: HEART RATE MONITOR CODING
Communication Port Form Coding

Private Sub Command1_Click()


If Option1(0).Value = True Then Form1.MSComm1.Settings = "9600,n,8,1"
If Option1(1).Value = True Then Form1.MSComm1.Settings = "19200,n,8,1"
If Option1(2).Value = True Then Form1.MSComm1.Settings = "38400,n,8,1"
If Option1(3).Value = True Then Form1.MSComm1.Settings = "57600,n,8,1"

Form2.Hide
Call Form1.openCom(Val(txtPort.Text))
Form1.Show
Unload Form2
End Sub

Private Sub txtPort_Change()


If Val(txtPort.Text) <= 0 Then txtPort.Text = 1
If Val(txtPort.Text) >= 50 Then txtPort.Text = 50

End Sub

Main Form Coding


'Use for real time graf animation on heart beat signal

Private Sub Command1_Click()


xmax = 0
ymax = 0
zmax = 0
xmin = 0
ymin = 0
zmin = 0
txtMax(0) = Str(xmax)
txtMin(0) = Str(xmin)
txtMax(1) = Str(ymax)
txtMin(1) = Str(ymin)
txtMax(2) = Str(zmax)
txtMin(2) = Str(zmin)
Line1(0).Y1 = Shape1(0).Top + Shape1(0).Height
Line1(0).Y2 = Line1(0).Y1
Line2(0).Y1 = Shape2(0).Top
Line2(0).Y2 = Line2(0).Y1
Line1(1).Y1 = Shape1(1).Top + Shape1(1).Height
Line1(1).Y2 = Line1(1).Y1
Line2(1).Y1 = Shape2(1).Top
Line2(1).Y2 = Line2(1).Y1
Line1(2).Y1 = Shape1(2).Top + Shape1(2).Height
Line1(2).Y2 = Line1(2).Y1
Line2(2).Y1 = Shape2(2).Top
Line2(2).Y2 = Line2(2).Y1
End Sub
Private Sub Command2_Click()
Form2.Show
End Sub

Private Sub EXIT_Click()


End
End Sub

'Manual button update for data logging

Private Sub Save_Click()


Open App.Path & "\Result.log" For Append As #1
Print #1, "" & lblDate & " -- " & lblTime & " -- " & Rate & "bpm " &
LblStatus Close #1
Call UPDATE2
End Sub

Private Sub TEST_Click()


Dim buffer As String
Dim cul_beat As Integer
Dim Rate As Integer

Label10(5).Caption = "HEART BEAT DETECTED"

'If reading not equal empty or 000 then display "HEART BEAT DETECTED"
hd_Beat = True
hd_draw = True
BeatCal.Text = Val(BeatCal.Text) + 1

If (Val(BeatCal.Text) > 0) And (Val(BeatCal.Text) < 2) Then


TimeStart(3).BackColor = &HFF00&
SampleTime.Enabled = True
End If

Private Sub UPDATE2() 'Data logging for heart beat reading and status
lstLateRecord.Clear
Open App.Path & "\Result.log" For Input As #1
Do Until EOF(1)
Line Input #1, tmpVar
lstLateRecord.AddItem (tmpVar)
Loop
Close #1
End Sub
Private Sub Timer1_Timer()
'set time and date
lblDate.Caption = Format(Now, "dd/mm/yyyy")
lblTime.Caption = Format(Now, "hh:mm:ss")

If Not Rate = "" Then

If Rate > 100 Then 'Heart beat normal and abnormal setting
Indicator.BackColor = &HFF&
LblStatus.Caption = "ABNORMAL"
MSComm1.Output = "*" & Rate & "#" & LblStatus & "/"
Exit Sub
End If

If Rate < 50 Then


Indicator.BackColor = &HFF&
LblStatus.Caption = "ABNORMAL"
MSComm1.Output = "*" & Rate & "#" & LblStatus & "/"
Exit Sub
End If

Indicator.BackColor = &HFF00&
LblStatus.Caption = "NORMAL"
MSComm1.Output = "*" & Rate & "#" & LblStatus & "/"
Exit Sub
End If

LblStatus.Caption = "NO INPUT"


MSComm1.Output = "*" & Rate & "#" & LblStatus & "/"
End Sub
APPEDNDIX E: PIC PROGRAMMING
;----------------------SET PIC = 16F877----------------------------------------------------------------------
----
;-------------------------------------------------------------------------------------------------------------------
---

list p=pic16f877a
include p16f877a.inc
__config 0x1E72
errorlevel -302 ;Suppress bank warning

;-------------------------------------------------------------------------------------------------------------------
---
;Declare variable use to store memory data
;-------------------------------------------------------------------------------------------------------------------
---

CBlock 0x20
N ; Delay registers.
N1
count1
counta
countb
countc
FIXDELAY
visdelay
dataL
COUNTER1
COUNTER2
A1
A2
A3

rxtime1
rxtime2

M1
M2
TH
TL
TXSW

RXD

A0
TmmerXX
Pcounter
PcounterTemp
ENDC
;-------------------------------------------------------------------------------------------------------------------
---
;Program Start
;-------------------------------------------------------------------------------------------------------------------
---

org 0x00

start call initports ; Initialize Ports as output/inputs.


call setupUART ;Initialize UART function
call INITLCD ; Initialize LCD
call clrscreen ; Clear LCD SCREEN
call standby
call SECOND_1 ;3s delay before start main program
call SECOND_1
call SECOND_1

movlw A'0'

movwf A1
movwf A2
movwf A3
movwf A0

;-------------------------------------------------------------------------------------------------------------------
---
;Start Of Main Program
;-------------------------------------------------------------------------------------------------------------------
---
LP
call CLRDATA ;Clear all LCD data
btfss PORTA,1 ;Check for MODE SWITCH??
goto SelfRunning ;INDIVIDUAL MODE??? then jump to
"SelfRunning

;----------------------------PC MODE--------------------------------------------------------------------------
------
call DisBPM ;PC MODE?? then proceed next instruction
call visualdelay

LPx movlw A' ' ;Clear Data BPM


movwf A0
movwf A1
movwf A2
call receive ;Check Data receive from PC??
movwf RXD
movf RXD,w
xorlw A'*' ;Check for Start Byte "*"
btfss STATUS,Z
goto SendP ;No?? then check for Heart beat signal
;-------------------------------------------------------------------------------------------------------------------
-----------------------
;Continue PC MODE
LoopRX1 call receive ;Data received?? then collect all data until "#"
movwf RXD
movf RXD,w
xorlw A'#'
btfsc STATUS,Z
goto EndDisplay ;If "#" received then goto EndDisplay
movf RXD,w ;No ?? proceed next Data..
movwf A0
LoopRX2 call receive
movwf RXD
movf RXD,w
xorlw A'#' ;If "#" received then goto EndDisplay
btfsc STATUS,Z ;No ?? proceed next Data..
goto EndDisplay
movf RXD,w
movwf A1
LoopRX3 c all receive
movwf RXD
movf RXD,w
xorlw A'#' ;If "#" received then goto EndDisplay
btfsc STATUS,Z ;No ?? proceed next Data..
goto EndDisplay
movf RXD,w
movwf A2 ;Last Data received...
goto EndDisplay

;-------------------------------------------------------------------------------------------------------------------
---

EndDisplay
movf A0,w ;Finalize data received
xorlw A'0'
btfss STATUS,Z
goto ProceedDis
movf A1,w
xorlw A'0'
btfss STATUS,Z
goto ProceedDis
movf A2,w
xorlw A'0'
btfss STATUS,Z
goto ProceedDis
call CLRDATA
call DisBPM ;If value = 000 then display NO INPUT
call visualdelay
goto SendP ;Go to Send Data to PC
ProceedDis
call DisLCD ;Display BPM reading
call nextline
LoopData
call receive ;Wait for Status reply from PC
movwf RXD
movf RXD,w
xorlw A'/'
btfsc STATUS,Z
goto EndDisplay1
movf RXD,w
call PUTCHAR
goto LoopData
EndDisplay1
call visualdelay
goto SendP ;Send beat signal to PC

;-------------------------------------------------------------------------------------------------------------------
---

SendP
btfss PORTA,0 ;Check for Heart Beat signal.
goto LPx ;No?? go back to LPx to check data from PC
call SendPulse ;Yes detected....then send data to PC
goto LPx

;----------Send Data to PC------------------------------------------

SendPulse
movlw A'X'
call transmit
movlw A','
call transmit
movlw A'1'
call transmit
call Delay_T
return

BacktoMAIN
call clrscreen
call DisPCMode
call SECOND_1
goto start

;-------------------------------------------------------------------------------------------------------------------
---
;Self Running MODE
;-------------------------------------------------------------------------------------------------------------------
---

SelfRunning
call clrscreen ;Clear All Data
call DisEMGMode
SelfR
call SECOND_1
movlw A'0'
movwf A2
movwf A1
movwf A0
movlw d'40'
movwf TmmerXX
movlw d'0'
movwf Pcounter
call DisLCD
call visualdelay
call SECOND_1
LoopSelfRunning
call Delay_T
btfsc PORTA,1 ;Check for MODE switch again??
goto BacktoMAIN
btfss PORTA,0 ;Check for Beat Signal??
goto skipcount
call IncPulse ;Calculate Total Beat within 10s

skipcount
decfsz TmmerXX,1
goto LoopSelfRunning
goto BPMRESULT

IncPulse
incf Pcounter,1
return

SelfRR movlw A'0'


movwf A2
movwf A1
movwf A0
movlw d'40'
movwf TmmerXX
movlw d'0'
movwf Pcounter
goto LoopSelfRunning

BPMRESULT
movlw A'0'
movwf A2
movwf A1
movwf A0
movf Pcounter,w
movwf PcounterTemp
movlw d'6'
movwf TmmerXX
call CLRDATA
LoopBPMR
call INCPlse
decfsz PcounterTemp,1
goto LoopBPMR
decfsz TmmerXX,1
goto LoopAgainx
goto DisBPMx

LoopAgainx
movf Pcounter,w
movwf PcounterTemp
goto LoopBPMR

DisBPMx movf Pcounter,w


xorlw d'0'
btfsc STATUS,Z
goto NoInp
call DisLCD
call visualdelay
goto SelfRR

NoInp call DisBPM


call visualdelay
goto SelfR

INCPlse incf A2,1


movf A2,w
xorlw A':'
btfss STATUS,Z
return
movlw A'0'
movwf A2
incf A1,1
movf A1,w
xorlw A':'
btfss STATUS,Z
return
movlw A'0'
movwf A1
incf A0,1
movf A0,w
xorlw A':'
btfss STATUS,Z
return
movlw A'9'
movwf A2
movwf A1
movwf A0
return
;------------------END OF MAIN PROGRAM---------------------------

CLRDATA movlw A'0'


movwf F6
movwf F4
movwf F5
movwf F0
movwf F1
movwf F2
movwf A1
movwf A2
movwf A3
movwf A0

return

;--------------------------------------------------------------------------------

return
Dec3x decf F2,1
movlw A'9'
movwf F1
movwf F0
return

;--------------------------------------------------------------------------------
SEND
return

;-------------------------------------------------------------------------------------------------------------------
-----
; END OF MAIN PROGRAM-------------------------------------------------------------------------------
--------------------
;-------------------------------------------------------------------------------------------------------------------
-----

;-------------------------END OF MAIN PROGRAM---------------------------

You might also like