ecg data transfer through usb interface with auto

advertisement
ECG DATA TRANSFER THROUGH USB
INTERFACE WITH AUTO-FEEDBACK
CONTROL TO A TREADMILL
by
Leslie O. Santiaguel
A Design Report Submitted to the School of Electrical
Engineering, Electronics Engineering, and Computer
Engineering in Partial Fulfillment of the Requirements for the
Degree
Bachelor of Science in Computer Engineering
Mapua Institute of Technology
September 2011
1
2
ACKNOWLEDGEMENT
My deepest thank you, dearest Lord, for all the gifts you have given me and for
directing my path to the following persons who have been instrumental to the
completion of this design project.
To my alma mater, Mapua Institute of Technology, for having an internship
program in place with the Chung Yuan Christian University (CYCU) in
Taiwan. This affiliation served as the stepping stone to accomplishing this
research project. This would have not been possible without the efforts of Mr.
Noel B. Linsangan, who encouraged me to pursue the internship, and Ms.
Eunice Cespedes, who fixed the requirements for the internship.
To the people who have warmly welcomed me in CYCU, the Biomedical
Engineering Laboratory, Room 501. Dr. Yu-Show Tsai, laboratory
professor, was helpful enough in assigning me with a research topic and in
providing laboratory partners who could help me. James Chang taught me the
fundamentals of ECG as I am a biomedical engineering neophyte. Alan Cheng
was kind enough to let me use his hardware project on the ECG device and
microcontroller as the basis for this research. Leo Lee coached me in coding for
the waveform part in the program. Chen Yao-Tang helped me in interfacing
hardware with software by helping in the programming of the heart rate
determination. My other laboratory mates were supportive enough to encourage
3
me to go on when I felt like my project was too hard to accomplish, and were
also thoughtful enough to compliment me when I was able to perform well.
To the other Filipino Mapuans who were with me during my stay in Taiwan, I
extend my sincerest thanks as they were my family there. Being homesick was a
challenge but with their company, time seemed to pass by in a flash. My stay in
Taiwan would not have been complete if not for our shopping, travels, food trips
and exploration of the country’s cities.
To my family, parents Susana and Loreto, siblings Lorraine and Lowie, who
supported my decision in pursuing an international internship. Aside from the
financial support, my family inspired me to finish the project so I can already go
home to the Philippines and be with them again.
4
TABLE OF CONTENTS
TITLE PAGE
i
APPROVAL SHEET
ii
ACKNOWLEDGEMENT
iii
TABLE OF CONTENTS
v
LIST OF TABLES
vii
LIST OF FIGURES
viii
ABSTRACT
x
Chapter 1: DESIGN BACKGROUND AND INTRODUCTION
1
Background
Intended Application
Different Features
Major Component
Statement of the Problem
Objectives of the Design
Significance and Impact of the Design
Scope and Delimitation
Definition of Terms
Chapter 2: REVIEW OF RELATED DESIGN LITERATURES AND STUDIES
Studies on Electrocardiogram devices
Studies on Auto-feedback control
Chapter 3: DESIGN PROCEDURES
Conceptual Diagram
Block Diagram
Design Procedures
Hardware Development
Schematic Diagram
1
2
3
4
5
5
6
7
9
12
12
16
20
20
21
23
24
25
5
Software Development
System Flowchart
Chapter 4: TESTING, PRESENTATION, AND INTERPRETATION OF DATA
Hardware Test
ADC and Data Transfer Test
GUI ECG Waveform Test
Chapter 5: CONCLUSION AND RECOMMENDATION
Conclusion
Recommendation
31
31
35
35
43
46
53
53
54
BIBLIOGRAPHY
57
APPENDIX
58
Appendix
Appendix
Appendix
Appendix
A: Operations Manual
B: Pictures of Prototype
C: Program Listing
D: Data Sheets
MSP4305529 Data Sheets
TPS736 Data Sheets
INA118 Data Sheets
OPA2335 Data Sheets
59
61
64
86
87
112
120
126
6
LIST OF TABLES
Table 2.1: Paces by Incline Table
18
Table 2.1: Total Calorie Burn Table
19
Table 3.1: Bill of Materials
28
Table 4.1: Test Case Analysis Table for Serial Port
47
Table 4.2a: Test Case Analysis Table for User Input Test
48
Table 4.2b: Test Case Analysis Table for User Input Test
49
Table 4.3: Test Case Analysis Table for Conditional Test
50
Table 4.4: Test Case Analysis Table for Auto-Feedback Test
50
Table 4.5: Sample Inputs and Computations Table
52
7
LIST OF FIGURES
Figure 2.1: ECG Compression Diagram
13
Figure 3.1: Conceptual Diagram
20
Figure 3.2: Block Diagram
21
Figure 3.3: Design Procedure Flow Chart
24
Figure 3.4: Electrocardiogram Device Schematic Diagram
25
Figure 3.11: Auto-Feedback Control Flowchart
31
Figure 3.12: Graphical User Interface
32
Figure 4.1: Tapping the probe to the PCB
36
Figure 4.2: Lead V1 Oscilloscope Output
37
Figure 4.3: Lead V2 Oscilloscope Output
37
Figure 4.4: Lead V3 Oscilloscope Output
37
Figure 4.5: Lead V4 Oscilloscope Output
38
Figure 4.6: Lead V5 Oscilloscope Output
38
Figure 4.7: Lead V6 Oscilloscope Output
38
Figure 4.8: Lead I Oscilloscope Output
39
Figure 4.9: Lead II Oscilloscope Output
39
Figure 4.10: Lead V1 Matlab Results
40
Figure 4.11: Lead V2 Matlab Results
40
Figure 4.12: Lead V3 Matlab Results
40
Figure 4.13: Lead V4 Matlab Results
41
Figure 4.14: Lead V5 Matlab Results
41
8
Figure 4.15: Lead V6 Matlab Results
41
Figure 4.16: Lead I Matlab Results
42
Figure 4.17: Lead II Matlab Results
42
Figure 4.18: Sample ECG waves and Intervals
43
Figure 4.19: ADC test results
44
Figure 4.20: USB CDC API test results in HyperTerminal
45
Figure 4.21: GUI interface test screen
51
9
ABSTRACT
Electrocardiogram (ECG) is an interpretation of the electrical activity of the
heart over a period of time, as detected by electrodes attached to the outer
surface of the skin and recorded by a device external to the body. The primary
goal of this project is to create auto-feedback control of a treadmill through a
user’s heart rate that is generated from his electrocardiogram. A 12-Lead ECG in
analog circuit was used with a microcontroller to perform analog to digital
conversion and transfer data via Universal Serial Bus Communication Device
Class Application Programming Interface (USB CDC API). The ECG result is then
transferred to a host which is a personal computer that has a graphical user
interface programmed in Visual Basic. The software will then evaluate the data
transferred and display an ECG waveform. Simultaneously the GUI software can
extract the value of the user’s heart rate and compare it with different bench
marks based on the user’s information. Through the user’s information maximum
heart rate, target minimum and maximum heart rate, metabolic rate, and
calories burned will be generated. The software has tables to check for
displaying the auto-feedback control. The auto-feedback control covers the
inclination of the treadmill and the pace per mile or time of the user to achieve
better feedback with the user’s workout.
Keywords: Electrocardiogram (ECG), heart rate, Microcontroller, Auto-Feedback
Control, Universal Serial Bus Communication Device Class Application
Programming Interface (USB CDC API)
10
CHAPTER 1
DESIGN BACKGROUND AND INTRODUCTION
Background
A person’s heart rate, defined as the number of heart beats per unit of
time, is one of the medical measures being used to gauge physical wellbeing.
The heart rate is measured by finding the pulse of the body. This pulse rate can
be measured at any point on the body where the artery's pulsation is transmitted
to the surface by pressuring it with the index and middle fingers; often it is
compressed against an underlying structure like bone. There are various noninvasive methods used to obtain the heart rate, with one of the most precise
outputs being obtained from the electrocardiogram, the trace produced by
electrocardiography, a procedure used to detect heart activity thru an external
device attached to the body. The ECG produces a waveform which has various
sections and among these, the QRS section is used to detect the heart rate
(Chan & So, 2007).
Electrocardiograms have long been used to interpret and monitor the
electrical activity of the heart over a period of time. The use of the
electrocardiogram was widespread during the time of Willem Einthoven who
introduced it at a meeting of the Dutch Medical Society in 1983 using the string
galvanometer.
Later, the electrocardiogram went through innovations and
enhancements that brought about the present applications in 3-lead, 5-lead, and
11
12-lead systems to be used for the diagnosis of heart activity. The leads measure
the differences in electrical potential between two different points on the body
which are bipolar leads, or one point on the body and a virtual reference point
with zero electrical potential, located in the center of the heart which are the
unipolar leads. Moreover the 12-lead ECG offers the most comprehensive view of
the heart’s electrical activity and the 3-lead ECG is frequently used for
emergency situations, telemetry monitoring and medical procedures (Marriott,
2002).
The ECG is mainly used within medical establishment premises such as
hospitals and clinics to detect unhealthy heart activities. Most ECG systems today
are inaccessible for personal use outside the hospitals due to its physical size,
cost, weight, and difficulty in operability for ordinary people, hindering on-thedot monitoring of the heart rate and subsequently, abnormal heart activity
recognition. Various alternatives used to measure heart activity have surfaced in
the market, with the heart-monitoring watch being the most popular. However,
its output is not as precise as the ECG as there are several sources of errors, like
loose wear; and readings are not very accurate (Dr. Ingrid Waldron, 2008).
With the ECG being limited to medical premises, its purpose is also limited
to the detection of heart irregularities once a patient undergoes the procedure. If
the ECG can be made into a less bulky piece of hardware, then it can also be
used by people to proactively monitor their heart rates outside of the hospitals.
12
Moreover, not only unhealthy heart activity can be checked, but also normal
heart activity, when engaging in exercise, for instance, can be monitored.
The project has its features on both hardware and software. On the
hardware part, an analog circuit offers the capability of extracting ECG signals
from the user of the treadmill with a 12 Lead electrocardiogram. The analog
device on the printed circuit board can accommodate the following lead as inputs:
Lead I, Lead II, Lead V1, Lead V2, Lead V3, Lead V4, Lead V5, and Lead V6. And
the project offers a power efficient device since it can be powered by a battery
or from the power supplied by the USB port.
The software part of the project offers the real time acquisition of the ECG
data in a graphical user interface coded in object-oriented programming software.
The graphical user interface features the explicit inputting of age, gender, height,
weight, target zone,and treadmill’s speed. The explicit inputs and implicit inputs
which are the ECG signal from the hardware taken from the user will be used in
the following computed information: maximum heart rate, target minimum and
maximum heart rate, work-out status, metabolic rate, and calories burned per
mile. Lastly one of the main features of the project is the auto-feedback control
of the treadmill from the software’s GUI for the inclination of the treadmill based
from
the
computed
boundaries
of
the
user.
13
One of the major components is the microcontroller, MSP4305529. Its main
purpose is the acquisition of signals from the analog circuitry, then conversion of
these signals into digital form. Data transfer is accomplished thru its integrated
USB supporting USB 2.0 (Texas Instruments, 2010).
Another major component is the INA118, which is an amplifier integrated circuit
used for electrocardiogram signal acquisition. Its input, obtained thru the lead,
are tiny electrical charges produced by the human heartbeat. Its versatile 3-op
amp design supports amplifying of small electrical charges, allowing it to output
enhanced electrical charges.
As such, it is widely used in medical
instrumentation (Texas Instruments, 2009). Paired with the INA118 are the
integrated circuits OPA335 and OPA2335 which are both operational amplifiers
that will boost the output voltage acquired signal of the ECG.
Lastly, the TPS73633 is an integrated circuit, which is the main source of power
of the ECG device. It maintains the maximum voltage capacity of the ECG device
as the components used are intended for low power consumption only (Texas
Instruments, 2007). This part is necessary as the voltage obtained from the USB
port is greater than the maximum voltage capacity of the INA118 and the
microcontroller.
14
Statement of the Problem
Physical fitness is the goal of most people nowadays as aside from visual
benefits like good looks, it also allows people to be healthy. One of the measures
used to determine physical fitness is a person’s weight. Exercise is the primary
method used by people to obtain physical fitness.
One of the most popular exercise equipment is the treadmill, used to walk
or run in place at varying speeds. The misconception of people exercising thru
the treadmill is the main concern seeking to be addressed by this research. More
often than not, people who exercise thru the treadmill do not know their
minimum and maximum limitations. As such, they can’t make the most out of
their workout, by exerting less than the recommended physical effort, under
working-out or worse, exceeding their physical capabilities and harming
themselves by over working-out. Some treadmill users are not aware that
monitoring their heart rate could be a great help for them in achieving their
desired results when working out.
Objectives of the Design
1. To assemble a cost-effectiveelectrocardiogram device in a printed
circuit board with surface-mounted analog components and a
microcontroller unit.
15
2. To implement a USB CDC API feature from the microcontroller of
the ECG device to the personal computer/notebook by means of a
USB data cable.
3. To program a graphical user interface (GUI) which will display and
process the ECG data obtained from the ECG device.
4. To incorporate the hardware and software components to comeup
with a functional real time auto-feedback control software that will
control treadmill inclination to trigger the user’s workload increase
and therefore result in the burning of more calories
Significance and Impact of the Design
The project gives a big contribution to the physical fitness of the people
today. The project would help treadmill users, those who are trying to lose
weight or wanting to achieve physical fitness. The project is appropriate for use
in fitness centers or even for home/personal use because of easy operability and
all in one feature, presenting several measures such as heart rate, metabolic rate,
net calories burned, etc. The project will give users the benefit of maximizing
their workout with the use of the treadmill thru having their heart condition and
physical condition monitored real-time while they are workingout.
The project offers the fusion of biomedical engineering and physical
fitness in a very economical and compact device. Hardware-wise, the project
offers a compacted and smaller version of the electrocardiogram, compared to
the ones available in medical establishments. The project has an auto-feedback
16
control mechanism through the treadmill. As for the software, it is coded in a
straightforward fashion using the Visual Basic programming language. Compact
hardware, coupled with basic, and therefore user-friendly graphical user interface,
allows for a non-intrusive monitoring device that can be used without difficulty.
Given this, treadmill users can easily attach the heart rate detecting device to
their body and let the program perform its purpose of providing them with
feedback of their work-out rate thru various measures like the heart rate,
metabolic rate, etc.
Scope and Delimitation
The project covers the analog to digital conversion of the ECG signal from
the analog circuitry which is composed of surface-mounted components and
integrated circuits on the printed circuit board. The project covers the data
transfer of the converted signal through the feature of the MSP4305529’s USB
CDC ADI that transfers high bandwidth sending of data to the COM port of a
personal computer. Moreover the project has the software part which contains
the auto-feedback control coded in Visual Basic. The software’s graphical user
interface for the auto-feedback covers the acquiring of the basic information of
the user for the computed boundaries for the calculation of real-time autofeedback control of the treadmill. The software also covers the display of the
waveform of the transferred ECG data from the microcontroller. And through the
ECG data the software is coded with the So and Chan algorithm for the
17
extraction of the heart rate for the completeness of the auto-feedback control.
Lastly the software’s auto-feedback control GUI for the treadmill covers the
control of the treadmill’s inclination.
The software also covers the additional
features of displaying the values of maximum heart rate, target heart rates,
workout status, metabolic rate (calories burned with respect to time and heart
rate), total calorie burn per mile, net calorie burn per mile, and pace per mile.
The project limitations include the input, obtained from an ECG simulator,
PS410 as a wearable device to obtain the actual heart rate from a human subject
which was unavailable for use during the time of the research. Furthermore, data
transfer which contains the microcontroller computed heart rate will be sent in a
packet together with the ECG data which is a more precise way of acquiring the
heart rate value for the auto-feedback control. Another limitation is the type of
connection used in the project. A wired connection was used thru the use of a
USB cable even though the previous electrocardiogram device was built with
Bluetooth functionality. The Bluetooth feature from the previous device was also
similar in the approach of transferring the ECG signal from the microcontroller to
the host. The Bluetooth module will act as a wireless bridge for the data transfer
where the microcontroller will be programmed to place its acquired signal
through the TX register while if it is through a cable the microcontroller will be
programmed to place its acquired signal on the assigned buffer in the USB CDC
API feature. Another limitation is the display of the waveform of the 11 more
leads of the electrocardiogram for a more visual interpretation of the status of
18
the user. The implementation of auto-feedback controls’ treadmill inclination that
could be controlled physically and in real-time together with the software’s
computed results was also not covered by the research. The same with the
treadmill’s speed that is displayed real-time and could be controlled through the
software’s graphical user interface. Lastly a database of the user’s information
and results are also not covered by the project since the application of autofeedback is real-time to any user at a given time depending on his or her desired
results.
Definition of Terms
ECG – acronym for electrocardiogram, the trace produced by electrocardiography,
a procedure used to detect heart activity thru an external device attached to the
body (Marriott, 2002).
Heart Rate - the number of heartbeats per unit of time, usually expressed as
beats per minute (BPM) (Dr. Ingrid Waldron, 2008).
Universal Serial Bus (USB) – an industry standard developed in the mid-1990s
that defines the cables, connectors and protocols used for connection,
communication and power supply between computers and electronic devices.
(Hui Pan, 1998).
USB Data Cable – a cable which supports data transfer through an A-Style
connector and a Mini B-Style Connector and the acquisition of 5 Volts power
supply.
19
Lead – any of the conductors connected to the electrocardiograph, each
comprising two or more electrodes that are attached at specific body sites and
used to examine electrical activity by monitoring changes in the electrical
potential between them.
Integrated Circuits (IC) – an electronic circuit manufactured by the patterned
diffusion of trace elements into the surface of a thin substrate of semiconductor
material (Wylie 2009).
Operational Amplifier – produces an output voltage that is typically hundreds of
thousands times larger than the voltage difference between its input terminals
(Bryant, 2011).
Microcontroller - is a self-contained single chip processor with all constituent
subsystems of a larger computer system (Barret, 2006).
USB CDC API - The USB CDC API (USB Communications Device Class Application
Programming Interface) for the MSP430 is a turnkey API that makes it easy to
implement a simple data connection over USB between an MSP430-based device
and a USB host (Texas Instruments, 2009).
COM port - The COM port software mechanism is a popular means of
communicating with a peripheral from a PC, due to its simplicity. It was originally
designed for communication over the RS232 port, but it has now grown beyond
these hardware limitations. Often today it is used in the form of a “virtual” COM
port operating over USB or Bluetooth, interfaces which by now have mostly
20
replaced RS232 on the PC back panel. It is for specific use in the Windows
operating systems (Texas Instruments, 2009).
Visual Basic – A version of the BASIC programming language from Microsoft
specialized for developing Windows applications (Gross, 2008).
Auto-Feedback - the use of difference signals, determined by comparing the
actual values of system variables to their desired values, as a means of
controlling a system (Lewis, 1992).
Real-time – responding to input immediately
So and Chan Algorithm – algorithm used to obtain the heart rate thru QRS
detection of the ECG signal (Chan & So, 2007).
21
CHAPTER 2
REVIEW OF RELATED DESIGN LITERATURES AND STUDIES
This chapter places the current study on electrocardiogram systems into
the context of previous, related research. ECG data acquisition, transfer,
manipulation, preservation and interpretation are discussed.
The feasibility of a PC-based ECG interpreter is explored. Various
equations for computing heart rate related values are discussed. Explicit user
inputs, such as age, height, weight and gender, and implicit inputs, like time,
speed, and heart rate are taken into consideration.
Konkala (2009) proposed a PC, specifically web-based, application for ECG.
In this study, he mentions how ECG is vital in detecting and diagnosing heart
conditions. However, not everyone has access to high-cost ECG devices, and
untrained people do not know how to interpret its results. He proposes a system
that would take make the best use of the PC given that it’s being used as a tool
in several software applications. This was done by developing a web-based lab
view web browser that is able to access and control ECG data.
According to Wang and Yeh, 2008, QRS point detection in the ECG signal
has already been studied for a long time. Among the points in an ECG signal, the
most important information can be found in the the Pwave, QRS complex and T
wave. However, there are some problems encountered such as noisy ECG signals
22
and power-line interference. With these problems, the incorrect information may
be obtained.
As Mukhopadhyay and Mitra (2011) propose, ECG data should be
compressed to reduce the amount of processed data, increasing processing time
and reducing needed data storage in case of long-term ECG data recording.
Coded in the C programming language, the algorithm is tested on a variety of
pre-obtained ECG data. Before compression, detection of the significant wave
points occurs. The R-Peaks are detected at first by a differentiation technique
followed by a localization of the QRS points. The output is then analyzed whether
it’s from a QRS region or not, then is subject to a compression method
depending on the QRS region. Two compression methods are discussed, lossy
and lossless, with each having advantages over the other, including file size and
data preservation.
Since data are broken down when they are subjected to
compression, data compression is performed to integrate them into a single unit.
The output is compressed ECG data, which can either be stored or transmitted.
23
Figure 2.1 ECG compression diagram
Khalil and Sufi (2008) affirms the statement of the above project about
compression to efficiently transmit ECG data to reduce data size at a greater
extent. However, a challenge is seen if ECG data from a lot of people are being
transmitted simultaneously, data compression alone may be insufficient and
ineffective as congestion may occur, leading to data loss. This scenario can be
observed in healthcare facilities with data being obtained from several patients at
the same time. The ECG reading would have to be as accurate as possible as it is
a doctor’s basis in detecting heart activities and possibly heart abnormalities.
As for the equation in QRS detection, So and Chan (1997) researched on
the development of an affordable real-time ambulatory electrocardiogram
monitor prototype. Their system consists of an analogue signal conditioner, a
micro-controller, external RAM and ROM, and a PCMCIA flash memory card and
interfacing chip. The research carried out the ECG data compression and realtime diagnosis. Their purpose of ECG analysis, a reliable QRS detection algorithm
with as little computation as possible, was developed. Their paper reports that
their work in the development of QRS detection algorithm was successful with
respect to the first derivative method as described in the paper by Friesen et al.
The five studies above are similar to, but also different from this research.
Firstly, all researches, including this one, make use of ECG data as input with the
main purpose of preserving as much information as possible. The difference can
be noted in the data acquisition method, speed, data manipulation and storage.
24
This research obtained ECG signals from a simulator, PS410, since a wearable
device to be used by a human subject is unavailable. PS410 is proven to be a
reliable simulation device and is in fact being used to calibrate a number of ECG
devices in healthcare facilities (Texas Instruments, 2009). Next, ECG data, once
acquired, is processed real-time. Given this, there is no need for storage as data
is immediately being passed to the host computer for conversion to a readable
format, ASCII. There is also no need for storage as historical data is not needed
any more as the system requires the current body condition in order for it to give
a timely recommendation. Contributing to the accuracy of the data obtained is
the non-usage of compression algorithms, which contributes to the correctness
of the data obtained. Compression is not needed any more as data is significantly
smaller in size compared to those being obtained from hospitals, which are a
recording of long-term ECG data. On another note, noise minimization was not
performed on the obtained data as the essential ECG signal points can be
determined even with the presence of noise. Also, the researches above were
concerned mainly in the acquisition of data, and not any more with its
presentation to the research subject. This research is different as it has a
graphical user interface which would allow users to see their heart rate, along
with other measures. This supports the objective mentioned earlier about the
project being usable by persons who do not need enough medical knowledge to
interpret the ECG signals they can see, and just need the essential data, in this
case, the waveform illustration, and computed measures like heart rate, etc.
25
AUTO-FEEDBACK CONTROL
The auto-feedback control part of the project focuses on how the treadmill
will respond automatically based on the user’s needs, specifically the heart rate.
A basic and standard formula computing for the maximum heart rate of the user
is computed as Maximum Heart Rate = 220 – Age. The maximum heart rate is
then used together with a multiplier from the user’s desired target zone to define
the target zone boundaries (minimum and maximum). There are five treadmill
workouts using a heart rate monitor that help the user maximize his workout
that will give corresponding computed maximum and minimum target heart rate
(Waters, 2008). These minimum and maximum target heart rates could help the
user in determining if exercising via treadmill helps in reaching the target
workout zone. Conversely, it would if allow the user to know if the workout being
performed is too much and is stressing and straining the heart. Below are the
five different target zones:

The Healthy Heart Zone: 50% to 60% of the individual maximum heart
rate. This is a safe, comfortable zone reached by an easy walk. This is the
best zone for people who are just starting to exercise. This zone has been
shown to help decrease body fat, blood pressure and cholesterol.

The Temperate Zone: 60% to 70% of the individual maximum heart
rate. This zone provides the same benefits as the healthy heart zone, but
26
is more intense and burns more total calories. Achieved through a faster
walking speed or a slow jog.

The Aerobic Zone: 70% to 80% of the individual maximum heart rate.
This zone will improve a person’s cardiovascular and respiratory system
and increase the size and strength of the heart. Achieved through a
steady jog.

The Anaerobic Threshold Zone: 80% to 90% of the individual
maximum heart rate. This is a high intensity zone is achieved through a
“burning” run.

The Redline Zone: 90% to 100% of the individual maximum heart rate.
This zone is the equivalent of running full out, and is often used in
“interval” training. This zone should be approached with caution and can
lead to injuries when sustained for a long period.
On the other hand, another part of the auto-feedback is the equivalent
paces by incline which determines the treadmill’s mode in terms of its speed
and inclination. A table below from www.hillrunner.com is used in the project
to make the auto-feedback control for possible real-time interaction with the
user’s target-zone and heart rate.
27
Treadmill
Equivalent paces by incline
MPH
0%
1%
2%
3%
4% 5% 6% 7%
setting
5
12:31 11:44 11:05 10:32 10:03 9:38 9:16 8:56
6
10:26 9:52 9:24 9:00 8:38 8:19 8:02 7:46
7
8:56 8:32 8:10 7:51 7:34 7:19 7:05 6:53
8
7:49 7:30 7:13 6:58 6:45 6:32 6:21 6:11
9
6:57 6:42 6:28 6:16 6:05 5:55 5:45 5:37
10
6:15 6:03 5:52 5:42 5:32 5:24 5:16 5:08
11
5:41 5:31 5:22 5:13 5:05 4:58 4:51 4:45
12
5:13 5:04 4:56 4:49 4:42 4:36 4:30 4:24
Table 2.1 Paces by incline table
8%
9% 10%
8:38
7:32
6:41
6:01
5:29
5:02
4:39
4:19
8:22
7:19
6:31
5:52
5:21
4:55
4:33
4:14
Another feature of the project is computing for the metabolic rate, total
calorie burn per mile, and net calorie burn per mile. Metabolic rate is discussed
as the heart rate, a marker for metabolic rate and energetic requirements. The
metabolic rate is dependent on physical activity, which in turn is related to, and
likely determined by, the heart rate itself (Boraso, 2001). Moreover the human
metabolic rate is the rate at which our body burns calories, therefore with the
increased exercise intensity muscles burn more calories, and so the heart beats
faster to provide the oxygen necessary to convert those calories to the form of
energy that can be burned by muscles. Keytel, et al. (2005) came up with a
formula for determination of calorie burn if VO2Max, oxygen intake, is unknown:

For males: ((-55.0969 + (0.6309 x Heart Rate) + (0.1988 x
Weight) + (0.2017 x Age))/4.184) x 60 x Time

For females: ((-20.4022 + (0.4472 x Heart Rate) + (0.1263 x
Weight) + (0.074 x Age))/4.184) x 60 x Time
28
8:07
7:07
6:21
5:44
5:14
4:49
4:28
4:10
Lastly another feature of the project is giving the user the total/net calorie
burned with respect to speed of the treadmill. Walking speed is defined to be
anything less than 7 MPH while running speed is 7MPH or more. In the flow
chart below, the net calorie burn measures calories burned, minus basal
metabolism (Cameron, et al., 2004).
Running
Walking
Your Total Calorie Burn/Mile Your Net Calorie Burn/Mile
.75 x your weight (in lbs.)
.63 x your weight
.53 x your weight
.30 x your weight
Table 2.2 Total Calorie Burn Table
29
CHAPTER 3
DESIGN PROCEDURES
This chapter gives an overview of the step-by-step process that was used
in making and developing the design prototype. Two major components of the
project are the hardware and the software. A detailed explanation of the subcomponents of these components is presented below.
CONCEPTUAL DIAGRAM
User
PC
ECG Device
Treadmill
Figure 3.1 Conceptual Diagram
The diagram above in Figure 3.1 shows the conceptual diagram of the
project that helps in gathering possible design options and approaches in
developing an electrocardiogram project intended for use in application to
physical fitness. The project is composed of an ECG device that is capable of
acquiring a signal of up to 12 leads that are attached to a user’s body. The
30
device is composed of surface-mounted components and integrated circuits that
function in acquiring ECG signals from the user’s body. After acquiring the ECG
signals, the ECG device will now send the data into a personal computer through
a universal serial bus data cable which is a USB mini to a standard USB. The
ECG device also will acquire its power source through the USB data cable from
the personal computer since its components require only low power consumption.
The personal computer should have Visual Basic software installed, the program
which will be used to run the software of the project for the auto-feedback
control of a treadmill. A more detailed explanation will be discussed in the latter
part of this chapter under the design procedure section.
BLOCK DIAGRAM
USER
ECG PRINTED CIRCUIT BOARD
ECG SIGNAL
Analog
Circuitry
MSP430F5529
PC
USB CDC API
Visual Basic
GUI
TREADMILL
AUTO-FEEDBACK
CONTROL
Figure 3.2 Project’s Block diagram
The diagram above is the representation of the flow of data within the
project. The signal from the human body, acquired through leads that extract the
ECG signal, is transferred to an ECG printed circuit board that contains analog
circuitry and a microcontroller unit. The analog circuitry is connected into the
input pins of the microcontroller for the data manipulation of the acquired ECG
signal. The microcontroller is responsible for the analog to digital conversion of
31
the acquired signal and the transfer of the converted signal to the universal serial
bus cable through the MSP4305529’s feature of the USB CDC API. The personal
computer that has Visual Basic installed will receive that digitized ECG signal and
use it in computing for the auto-feedback control values of the project. A more
detailed explanation of this will be discussed in the latter part of this chapter.
Below is the flow chart of the design procedure that was used as a guide
in integrating the hardware and the software components of the project. Each
part will be further discussed in detail below.
The project started through data gathering from documents, lectures and
related literatures available in the biomedical engineering laboratory of the
Chung Yuan Christian University. Previous schematic diagrams and projects were
introduced by fellow laboratory students and were considered in conceptualizing
the planned project. Reading related literature about previous hardware devices
for electrocardiograms also contributed to coming up with the planned project.
After integrating all the data gathered, the finalized schematic diagram was
tested in simulation software, Multisim version 10. When the desired outputs and
components values were already obtained with no errors and bugs, the
schematic diagram was then transferred to another simulation software, Protel
DXP 2004. This was to surpass the limitations of Multisim as Protel DXP is a tool
which can construct the printed circuit board layout with actual components
based on the supplied schematic diagram.
board
with
manual
routing
of
After finalizing the printed circuit
components,
the
construction
of
the
32
electrocardiogram hardware device followed. Figure 3.4 is the schematic diagram
composing the electrocardiogram device. This was designed by Mr. Alan Chen, a
post-graduate student of biomedical engineering of the Chung Yuan Christian
University. The design’s schematic diagrams and PCB were allowed to be used as
the hardware of this project as they have already been proven to be working
templates and would therefore be a good foundation for developing the project.
The researcher was tasked to complete the printed circuit board by soldering the
components
and
the
microcontroller
unit’s
program.
33
DESIGN PROCEDURE
START
A
Data Gathering
(Documents , Lectures, and Related Literatures)
Microcontroller Programming
Is the data
useful ?
No
No
Is the program
successful?
Yes
Yes
Yes
Identify which schematic diagram
and components will be used .
Graphical User Interface
Programming
Simulate and Test
Software Testing
Yes
Is there any
errors and
bugs?
Is there any
errors and
bugs?
No
No
Finalize schematic
Diagram and components
No
Software/ GUI
Finalizing
Construct
Hardware
END
Is construction
Complete ?
Yes
Yes
Hardware Testing
Is there any
errors and
bugs?
Figure 3.3 Design Procedure Flow Chart
No
A
34
35
Fig. 3.4 Electrocardiogram Device
Schematic Diagram
36
37
The
schematic
diagram
above
has
sub-schematic
diagrams
for
determining the voltages on Lead RA, LA and LL. In the case of building this
project, this part of the hardware has been skipped and replaced by a jumping
wire to the next part of the schematic diagram, because the project focused on
determining the important leads and these leads are just for reference only and
these reference voltages are already provided by the PS410 ECG simulator.
Secondly, the schematic diagram above also has parts for leads V1, V2,
V3, V4, V5, and V6 since they are all referred to as unipolar leads that are
attached to the chest of the user but with varying distances to each other. The
schematic diagram consists of an instrumentation amplifier which will amplify the
signal taken from the chest of the user under extensive noises from the body.
After passing thru the instrumentation amplifier the signal will then enter as
input in an operational amplifier that will amplify the ECG signal into noticeable
voltages. The values of the resistors and capacitors completing the diagram are
all pre-computed values of the data sheets of the two integrated circuits
depending upon the needed application.
Thirdly, the schematic diagram for the leads RA, LA, and LL and the
electrode connector was also present. In this part of the schematic diagram the
voltage taken from the user of the body will pass thru two different operational
amplifier stages instead of passing into an instrumentation and operational
amplifier. The electrode connector showed in this figure is a 15-pin female
connector that will recognize the wire and leads for ECG signal acquisition.
38
Fourthly, the schematic diagram for the microcontroller unit of the
hardware and in the schematic diagram for the USB interface was also included.
The MSP4305529 has its pre-computed values for its resistors, capacitor and
oscillators prescribed in its data sheet for different applications. Part of this MCU
is the JTAG which is connected into respected pins of the MSP4305529 for
interfacing with the debugging program from the IAR embedded Workbench
software. A group of LEDs are connected to its assigned pins for testing and
verification purposes.
Lastly, there is schematic diagram for the power supply of the device. This
part was necessary in the diagram because the components and the integrated
circuit composing the diagram are all low power consumption devices.
BILL OF MATERIALS
The above schematic diagrams are provided with components supplied by
the biomedical engineering laboratory which were supplied by a recognized
company,Texas Instruments. To further explain the cost effectiveness of the
hardware part of the project, below in Table 3.1 are the prices of the materials
taken from Texas Instruments’ online ordering and shopping catalog of
components.
39
Device Description Quantity Price Per Piece
MSP4305529
1
P 1125
INA118
8
P 325
OPA335
8
P 67.5
OPA2335
4
P 90
TPS73633
1
P 45
Resistors
6 packs
P 15
Capacitors
6 packs
P 22.5
Switch
1
P 25
JTAG connector
1
P30
Parallel connector
1
P 45
USB connector
1
P 30
2 Layer PCB
1
P 1000
USB data cable
1
P 300
Total Cost
P 6275
Table 3.1 Bill of Materials
Total Cost
P 1125
P 2600
P 540
P 360
P 45
P 90
P 135
P 25
P 25
P 30
P 30
P 1000
P 300
Once construction of the hardware by soldering each component to the
circuit board was completed, the project’s hardware device was then subjected
to testing before proceeding with the programming of the microcontroller unit.
Testing the hardware was done by applying a temporary voltage source to the
circuit board and by using an oscilloscope to determine the digital output of a
lead which was displayed in waveform. The preliminary results of the hardware
testing conducted will be discussed in the succeeding chapter. When all of the 12
leads displayed a clear output on the oscilloscope, the next part of the project
was then ready for implementation, which was the programming of the
microcontroller unit.
The microcontroller used in this project is MSP4305529. The project’s
microcontroller can be programmed with the use of the IAR Embedded
40
Workbench software. The project’s program was coded in C language and was
automatically converted by the IAR Embedded Workbench into microcontroller
language. The project’s microcontroller program covers the analog to digital
conversion of the signal transferred from the analog circuitry of the 12 leads of
the electrocardiogram device and the data transfer from the microcontroller to
the PC host using the Universal Serial Bus Communication Device Class
Application Programming Interface (USB CDC API).
The 12 bit analog to digital conversion of the project was accomplished
with the help of example program number 6 of MSP430 Family User’s Guide
(Texas Instruments, 2010), which is the MSP430F552x Demo - ADC12, Repeated
Sequence of Conversions. With some modifications with the sample program, the
program successfully performed a repeated sequence of conversions using
"repeat sequence-of-channels" mode. The repeated sequence of conversions was
performed on Channels A0, A1, A2, A3, A4, A5, A6 and A7. Each conversion
result was stored in microcontroller memories ADC12MEM0, ADC12MEM1,
ADC12MEM2, ADC12MEM3, ADC12MEM4, ADC12MEM5, ADC12MEM6, and
ADC12MEM7 respectively. After each sequence, the eight conversion results were
moved to A0results[] up to A7results[]. The conversion was verified through the
IAR Embedded Workbench’s watch window in debugger mode. These results can
be seen in the succeeding chapter.
The data transfer using USB CDC API was accomplished with the help of
the MSP430 CDC Application Examples. Example number 5 which is the High41
Bandwidth Sending Using sendData_waitTilDone() was used as the foundation
program. Modifications were done with the example to fit the requirement of the
project of sending the ECG siginal continuously and real-time to the host for the
outputting of the waveform in the graphical user interface. The program
performed by filling up the buffer of the microcontroller with the results of the
analog to digital conversion results and then automatically send the data through
the COM port of the HOST contiously in the background instead of waiting for all
of the data to be received in the initial process of the application. For initial
verification of the data transfer of the microcontroller the personal computer’s
HyperTerminal was used to view the transferred data in ASCII values which
represents the result of the analog to digital conversion of the ECG signal.
After the data transfer of the ECG signal was successfully done the next
procedure of the project was the construction of the software part of the project
which is the auto-feedback control of a treadmill in a graphical user interface
program in an object oriented software, Visual Basic. Below in Figure 3.11 is the
flow chart for the auto-feedback control’s graphical user interface.
42
Software Part – Graphical User Interface
START
Input Age, Weight , Height, Gender, Target
Zone, and Treadmill Speed
Actual Heart Rate = AHR
Maximum Heart Rate = MHR
Min. Target Heart Rate = MinTHR
Max. Target Heart Rate = MaxTHR
Metabolic Rate
Total Calorie Burn
Net Calorie Burn
Work Out Status
Time
Yes
IF AHR>=MHR
No
Display Computed Values
Target Zone ++
Yes No
IF
AHR <MinTHR
No
IF
AHR >=MaxTHR
Yes
Yes
No
Work Out Status = Bad
Auto-Feedback ++
Work Out Status = Good
Work Out Status = Bad
Input User Choice
Increase Target
Zone ?
WARNING
Auto-Feedback = 0
Work Out Status = Bad
Display Computed
Values
End
43
Figure 3.11 Auto-Feedback Control Flow Chart
The software part of the project was coded in Visual Basic. The objective
of the Treadmill Auto-FeedbackControl Interface was to let users see their
current workout status into a graphical user interface. See Figure 3.12 for the
actual graphical user interface of the project.
1
11
2
12
3
13
4
14
5
15
6
16
17
18
19
7
20
8
10
9
21
22
Figure 3.12 Graphical User Interface
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
COM Port Drop Down Box
Height Text Box
Weight Text Box
Age Text Box
Gender Radio Buttons
Target Zone Combo Box and
Radio Buttons
Connect Command Button
Disconnect Command Button
End Command Button
Waveform Picture Box
Actual Heart Rate Text Box
Maximum Heart Rate Text Box
13. Target Minimum Heart Rate
Text Box
14. Target Maximum Heart Rate
Text Box
15. Work Out Status Text Box
16. Metabolic Rate Text Box
17. Total Calorie Burn per Mile Text
Box
18. Net Calorie Burn per Mile Text
Box
19. Speed Command Buttons
20. Speed Text Box
21. Pace per Mile Text Box
22. Inclination Text Box
44
The flow chart of the Treadmill Auto-Feedback Control Interface in Figure
3.11, which is mainly focused on developing an auto-feedback control, contains
different variables such as information explicitly inputted and implicitly inputted
by the user, like the data received from the electrocardiogram device. The
graphical user interface first processes and detects which COM PORT the device
is connected to. After selection of which COM PORT comes the inputting of user
information such as height, weight, age, gender, and target zone. These are
mandatory before the “Connect” button is enabled, which will establish the
connection between the ECG device and the host software. The graphical user
interface was coded in such a way that when the connection is already
established, it will save time of the personal computer, with the assumption that
when users virtually connect the device and the host software, the users would
right away proceed with their work out. The actual time of the system is saved
because the software uses the time as one variable in solving a computed value
of Metabolic Rate. The other computed information of the user will also be
flashed as soon as the input and connection are already established. The
maximum heart rate would depend on the user input of age while the target
minimum and maximum heart rate would depend on the user’s inputs of height,
weight, gender, and target zone. As soon as the electrocardiogram device sends
the ECG signal through the COM Port, the GUI’s picture box will automatically
display the corresponding waveform for the said signal. Simultaneously, the ECG
signal being sent to the COM Port will be undergoing data processing thru the So
45
and Chan algorithm for the Actual Heart Rate value extraction. This algorithm
would first detect the QRS points then save these into a data array. Next, this
will undergo slope detection and peak value using formulas, this will be
performed five times to allow for getting the mean of the slopes and peak values
obtained. When the GUI’s acquisition of actual heart rate is successful, signified
by the appearance of a value on the actual heart rate text box, the computation
for the computed boundaries of the auto-feedback control will be processed. The
computed values are the work out status, metabolic rate (calories burned with
respect to time), total calorie burn per mile, and net calorie burn per mile. The
main feature of the project’s software is integrating the computed feedback
values of a user and coming up with an auto-feedback control of a treadmill. The
treadmill’s inclination will be set to increase if the computed target minimum
heart rate is not yet achieved by the user. When the user is already above the
target maximum heart rate, a corresponding work out status will be displayed
and the software will continuously ask the user to move to the next target zone
for safety reasons. If the user is in between the target heart rates, the user will
see at the GUI the corresponding work out status, which is “Good,” because his
work out is just right. When the user decides to continue working out to the next
target zone, the auto-feedback control’s inclination will be reset, but when the
user still insists on working out on his current target zone but has reached his
maximum heart rate, the auto-feedback control will be set to zero and the
Treadmill Auto-Feedback Control Interface will automatically shut down.
46
CHAPTER 4
TESTING, PRESENTATION, AND INTERPRETATION OF DATA
In this chapter, various tests were conducted for the Treadmill AutoFeedback Control Interface and hardware parts of the project in order to
determine the functionality and reliability of the project. This is also to determine
if the stated objectives were achieved. Detailed discussions will be made for each
test for better interpretation of data.
HARDWARE TESTING
Electrocardiogram Waveform Testing
In testing the hardware, composed of surface mounted integrated circuits
and other electrical parts, resistors and capacitors, an oscilloscope was used to
determine the output signal of each lead of the electrocardiogram device. A
PS410 ECG Simulator by Texas Instruments was used to determine if the
electrocardiogram’s output waveform is correct. The PS410 ECG simulator is a
handheld device which simulates a full range of cardiac rhythms and a wide
variety of ECG conditions. The ECG simulator is well-matched with the hardware
design which consists of 12 leads.
Procedure:
47
1. Attach the power source and lead connector to the device.
2. Set up the oscilloscope with one channel.
3. Connect the ground clip to the wire of the device that is connected to the
ground.
4. Tap the probe to the end points of each lead one at a time (R76, R77,
R78, R79, R80, R81, R82, R83).
Figure 4.1 Tapping the probe to the PCB
5. See oscilloscope’s display.
Oscilloscopes Actual Waveform Results:
48
Figure 4.2 Lead V1 Oscilloscope Output
Figure 4.3 Lead V2 Oscilloscope Output
49
Figure 4.4 Lead V3 Oscilloscope Output
Figure 4.5 Lead V4 Oscilloscope Output
Figure 4.6 Lead V5 Oscilloscope Output
50
Figure 4.7 Lead V6 Oscilloscope Output
Figure 4.8 Lead I Oscilloscope Output
Figure 4.9 Lead II Oscilloscope Output
To verify the acquired hardware results, example waveforms of each lead
were used to compare with the following outputs from the Matlab software
developed by Mr. Alan Cheng. Please see figures below.
51
Figure 4.10 Lead V1 Matlab Results
Figure 4.11 Lead V2 Matlab Results
Figure 4.12 Lead V3 Matlab Results
52
Figure 4.13 Lead V4 Matlab Results
Figure 4.14 Lead V5 Matlab Results
Figure 4.15 Lead V6 Matlab Results
53
Figure 4.16 Lead I Matlab Results
Figure 4.17 Lead II Matlab Results
The results of the electrocardiogram device based on its actual output and
computed Matlab output were acceptable. The noise on the actual results
through the oscilloscope’s display was negligible because noise was most
probably caused by the oscilloscope’s channel probe as the signal output of the
ECG device is fixed. The results from the actual outputs, even in the presence of
the noise, conformed with the expected output.
54
The expected output should include the relevant points in the ECG, such as the P
Wave, QRS complex, ST Segment, T wave, U Wave and RR Interval, which can
be seen in the diagram below by Yanowitz (2006).
Figure 4.18 Sample ECG waves and intervals
Analog to Digital Conversion and Data Transfer Testing
The last part of the hardware testing was the acquisition of the signal
from the analog circuit by the microcontroller and converting it to a digital signal
and transferring it to the PC host. The verification of the results of the
microcontroller’s analog to digital conversion was done through the IAR
Embedded Workbench’s watch window tool in debugger mode (figure 4.19).
Lastly since that the data sent is still preliminary the test of the data transfer
using USB CDC API to the PC host was completed, in the HyperTerminal software
of Windows XP. The HyperTerminal could interface the COM ports allowing for
display of data transfer in ASCII characters (figure 4.20).
55
Procedure:
1. Connect the PS410 ECG Simulator device to the ECG device.
2. Connect the USB data cable to the ECG device and PC.
3. Connect the MSP430 USB–Debug Interface (MSP-FETU430IF) to the
device’s JTAG connector.
4. Turn on the ECG device.
5. Open IAR Embedded Workbench. Load Workspace/project.
6. Perform compile and debug into IAR embedded workbench.
7. Open a watch window and view the results.
Figure 4.19 ADC test results
Procedure:
1. Connect the PS410 ECG Simulator device to the ECG device.
56
2. Connect the USB data cable to the ECG device and PC.
3. Turn on the ECG device.
4. Open HyperTerminal.
5. Connect using the appropriate COM port assigned to USB CDC API.
6. Start call and view the display of characters.
Figure 4.20 USB CDC API test results in HyperTerminal
SOFTWARE TESTING
The software testing part of the project covers three parts: (1) the
verification of the electrocardiogram waveform transferred through USB interface
to the Visual Basic program, (2) the GUI testing of the Treadmill Auto-Feedback
Control Interface, and, (3) the analysis of the GUI’s auto-feedback control.
57
GUI ECG Waveform Testing
This testing part of the Treadmill Auto-Feedback Control Interface mainly
covered verifying if the displayed waveform in the graphical user interface was
identical with the results acquired through the hardware testing and expected
output of an electrocardiogram waveform. The same procedure was done just
like with the viewing of results in the HyperTerminal but this time in the
developed graphical user interface.
Procedure:
1. Connect the PS410 ECG Simulator device to the ECG device.
2. Connect the USB data cable to the ECG device and PC.
3. Turn on the ECG device.
4. Open Visual Basic Program and load the project.
5. Connect using the appropriate COM port assigned to USB CDC API.
6. Verify the results of the waveform inside the picture box.
The first phases of the testing were unsuccessful due to the waveform displaying
in an inverted manner. This was due to the microcontroller outputting negative
values. These values were transposed to come up with the right values which led
to the correct waveform.
The second part involved testing the software’s GUI testing, performed via
trial and error procedure. This was for the sake of ensuring that no bugs existed
58
and that the debugging performed on one part of the graphical user interface
would not affect the whole project.
The serial port test was conducted to make sure that the serial port
connected to the host computer was working. This was needed as the ECG signal
is needed for the smooth execution of the program. In the absence of the serial
port or incompatibility of the serial port format with the program, the program
was not expected to function.
Test Case
Serial Port
Test
Condition
Serial Port
Exists
Serial Port
Test
Serial Port Does
Not Exist
Serial Port
Test
Serial Port Not
Supported
Expected output
Normal Program
Execution
No ECG signal for
Program Execution
Actual Output
Normal Program
Execution
No ECG signal for
Program Execution
No ECG signal for
Program Execution
No ECG signal for
Program Execution
Judgment
Passed
Passed
Passed
Table 4.1 Test Case Analysis Table for Serial Port
The next set of test cases concerned user inputs. These consisted of data
input validations like type (digits for age, for example) and allowed inputs (only
one out of pre-defined choices, for example).
59
Test
Case
User
Input
Condition
Expected output
Actual Output
Judgment
Valid Height
Input
Enable Weight Text Box
Enable Weight Text Box
Passed
User
Input
Invalid Height
Input
Disable Weight Text Box and
Program Error
Disable Weight Text Box and
Error
Passed
User
Input
Valid Weight
Input
Enable Age Text Box
Enable Age Text Box
Passed
User
Input
Invalid Weight
Input
Disable Age Text Box and
Program Error
Disable Age Text Box and
Error
Passed
User
Input
Valid Age Input
Compute and Display
Maximum Heart Rate, Enable
Gender Radio Buttons and
Target Zone Combo Box
Compute and Display
Maximum Heart Rate, Enable
Gender Radio Buttons and
Target Zone Combo Box
Passed
User
Input
Invalid Age
Input
Disable Gender Radio Buttons
and Program Error
Disable Gender Radio Buttons
and Program Error
Passed
Choose Computation for Male
Choose Computation for Male
Passed
Choose Computation for
Female
Choose Computation for
Female
Passed
Choose Computation for
Healthy Heart, Display Target
Maximum and Minimum
Heart Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
Choose Computation for
Healthy Heart, Display Target
Maximum and Minimum
Heart Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
Passed
User
Input
User
Input
User
Input
Male Radio
Button
Checked
Female Radio
Button
Checked
Healthy Heart
Target Zone
Radio Button
Checked
Table 4.2a Test Case Analysis Table for User Input Test
Another set of tests was conducted to make sure that the GUI design
responds to the events. Certain GUI elements were disabled whenever their
preconditions were not fulfilled. Also, computations are dependent on the
selections made by the user.
60
Test
Case
Condition
User
Input
Aerobic Target
Zone Radio
Button
Checked
User
Input
Temperate
Target Zone
Radio Button
Checked
User
Input
Anaerobic
Threshold
Target Zone
Radio Button
Checked
User
Input
Red Line
Target Zone
Radio Button
Checked
User
Input
No Target Zone
Radio Button
Checked
Expected output
Actual Output
Choose Computation for
Aerobic , Display Target
Maximum and Minimum
Heart Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
Choose Computation for
Temperate, Display Target
Maximum and Minimum
Heart Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
Choose Computation for
Anaerobic Threshold, Display
Target Maximum and
Minimum Heart Rate, Work
Out Status, Calories Burn per
Mile, and Auto-Feedback
Values
Choose Computation for
Red Line, Display Target
Maximum and Minimum
Heart Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
No Computation, Display
Target Maximum and
Minimum Heart Rate, Work
Out Status, Calories Burn per
Mile, and Auto-Feedback
Values
Choose Computation for
Aerobic , Display Target
Maximum and Minimum Heart
Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
Choose Computation for
Temperate, Display Target
Maximum and Minimum Heart
Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
Choose Computation for
Anaerobic Threshold, Display
Target Maximum and
Minimum Heart Rate, Work
Out Status, Calories Burn per
Mile, and Auto-Feedback
Values
Choose Computation for Red
Line, Display Target
Maximum and Minimum Heart
Rate, Work Out Status,
Calories Burn per Mile, and
Auto-Feedback Values
No Computation , Display
Target Maximum and
Minimum Heart Rate, Work
Out Status, Calories Burn per
Mile, and Auto-Feedback
Values
Judgment
Passed
Passed
Passed
Passed
Passed
Table 4.2b Test Case Analysis Table for User Input Test
The third part consists of the validation of the auto feedback process of
the software. This was to justify the correctness of the program in computing for
various values to come up with a decision, like inclining the treadmill or
prompting the users that they have reached the maximum heart rate for their
desired target zones.
61
Test Case
Conditional Test
(Actual Heart Rate
greater than or
equal to Target
Maximum Heart
Rate)
Conditional Test
(Actual Heart Rate
greater than or
equal to Target
Maximum Heart
Rate)
Condition
Expected output
Actual Output
Judgment
Move to Next
Target Zone
Change target zone
computational Values
and reset AutoFeedback values
Change target zone
computational Values
and reset AutoFeedback values
Passed
Stay on
current
Target Zone
Check Actual and
Maximum Heart Rate
Check Actual and
Maximum Heart Rate
Passed
Table 4.3 Test Case Analysis Table for Conditional Test
Lastly, a conditional test was done to check how user decision would
affect the program behavior. A difference in the computations and GUI display
was expected.
Test Case
Condition
AutoFeedback
Test
Maximum Heart Rate
greater than or equal to
Actual Heart Rate
AutoFeedback
Test
Maximum Heart Rate less
than Actual Heart Rate
AutoFeedback
Test
Actual Heart Rate less
than Target Minimum
Heart Rate
AutoFeedback
Test
Actual Heart Rate greater
than or equal to Target
Maximum Heart Rate
Target Maximum Heart
Rate greater than Actual
Heart Rate and Actual
Heart Rate greater than
Target Minimum Heart
Rate
AutoFeedback
Test
AutoFeedback
Test
Actual Heart Rate Change
Value
Expected output
Display Warning,
Maximum Heart Rate
Box turns Color Red
and Terminates
Program
Maximum Heart Rate
Box turns Color
Green
Increase Inclination
Percentage and Work
Out Status equal
“Bad”
Message Box Display
and Work Out Status
equal “Bad”
Actual Output
Display Warning,
Maximum Heart Rate
Box turns Color Red
and Terminates
Program
Maximum Heart Rate
Box turns Color
Green
Increase Inclination
Percentage and Work
Out Status equal
“Bad”
Message Box Display
and Work Out Status
equal “Bad”
Judgment
Work Out Status
equals “Good”
Work Out Status
equals “Good”
Passed
Compute and Change
Display Computed
Information
Compute and Change
Display Computed
Information
Passed
Passed
Passed
Passed
Passed
62
Table 4.4 Test Case Analysis Table for Auto-Feedback Test
63
Lastly, the auto-feedback control of the GUI was checked.
Procedure:
1. Open Visual Basic Program and load project.
2. Connect using the appropriate COM port assigned to USB CDC API.
3. Input the following:
a. Height
b. Weight
c. Age
d. Gender
e. Target zone
4. Click the “Connect Button.”
5. The following were displayed dynamically:
a. GUI waveform
b. Actual heart rate
c. Work-out status
d. metabolic rate
e. Pace per mile / Time
f. Inclination
64
Figure 4.21 GUI interface test screen
65
Number
1
2
3
4
5
6
7
8
Parameter
Height
Weight
Age
Gender
Target Heart Zone
Waveform
Actual Heart Rate
Maximum heart rate
Minimum target
9 heart rate
Maximum target
10 heart rate
11 Work-out status
Metabolic rate
(male)
12 Time
Your Total Calorie
13 Burn/Mile
Your Net Calorie
14 Burn/Mile
15 Speed
Speed classification
16 Pace per mile/Time
17 Inclination
Formula
Input-dependent
Input-dependent
Input-dependent
Input-dependent
Input-dependent
Data transfer dependent
Data transfer dependent
220 – Age
.50 * maximum heart rate
Value
5 feet 8 inches
210 pounds
23
M
Healthy Heart
N/A
80
197
98.5
.60 * maximum heart rate
Actual Heart Rate < Minimum Heart Rate or Actual Heart Rate =>
Maximum Heart Rate = BAD
Minimum Heart Rate < Actual Heart Rate < Maximum Heart Rate =
GOOD
((-55.0969 + (0.6309 x Heart Rate) + (0.1988 x Weight in KG) +
(0.2017 x Age))/4.184) x 60 x Time
Program-dependent
118.2
57.87
4.7811
.53 x your weight - Walking or .75 x your weight (in lbs.) - Running
111.3
.30 x your weight - Walking or .63 x your weight (in lbs.) - Running
Input-dependent
<7MPH, Walking >=7MPH, Running
Inclination and speed dependent
If Actual Heart Rate < Minimum Heart Rate = Inclination + 1
63
5
Walking
10.03
4
Table 4.5 Sample inputs and computations table
66
CHAPTER 5
CONCLUSION AND RECOMMENDATION
In concluding the results of this project, all the objectives set forth by the
researcher during the beginning of the project were achieved in the end.
Recommendations are also stated so as to suggest possible improvements in
case the project will be further studied by other researchers.
Conclusion
The electrocardiogram signal is used as primary input in the autofeedback mechanism of the software as it would control the parameters in the
program. However, the acquisition of this signal and its transfer to the PC host is
not a straightforward process as some data manipulation would have to be
performed. The interface between the PS410 ECG simulating device and the PC
host was established using several components as discussed in the previous
chapter. The main parameters being looked at to test the effectivity of the
software are the heart rate measures and other computations dependent on the
heart rate data. As seen in the test results, the software was able to output the
expected values. Given this, it can be concluded that smooth processing of the
ECG data was accomplished since the outputs depended on the ECG data.
In terms of the hardware design, the entire hardware cost approximately P
7,000.00 only, much cheaper compared to the ECG interpretation devices being
manufactured today. Data was transferred only thru a USB cable connected to a
67
PC host. Other low-cost components were the components used in the device,
like the microcontroller and the integrated circuits.
The program was asked to input some information like age, gender, height,
weight and desired target zone, and all of these were used in computing for the
minimum and maximum heart rate, work-out status, metabolic rate/ calorie
burned with respect to time, calories burned per mile, total calories burned per
mile and net calories burned per mile. Because of data dependency, there were
some fields which would change when the value it was based on changed. The
program is flexible enough to compute for the values in real-time, allowing the
user to see his work-out information while he’s at it.
Lastly, the system was able to initiate an increase in treadmill inclination once
the target minimum heart rate is reached for the chosen target zone. This was
accomplished by employing all the gathered information from the user by
integrating this with the processed results of the ECG data.
Recommendations
There are several enhancements that can be made to the project.
To improve its outputs, its hardware design can be enhanced. In this project,
what was used was only 1 lead ECG as it can obtain the essential signals alone.
However, a larger number of lead ECGs, up to the maximum number of 12, can
be made use of so as to obtain more strong signals, and consequently lead to
determining more accurate data.
68
Another hardware component that can be boosted is the connection
between the project device and the host computer. Data was interfaced from the
device via wired connection thru the use of a USB cable. During the testing of
the interface between the ECG device and the host computer, the researcher
was able to observe that the outputs had varying noise, which was supposed to
have been caused by the cable itself. This was assumed since, as per
observation, the output was influenced by the cable’s condition. For instance,
when the cable was bent, the output was seen to be noisier compared to the
output when the cable was laid straight. Additionally, a clearer output was
observed during the first few tries, and as the testing was repeated, the output
got noisier.
To account for more flexibility in data acquisition, a wireless connection
can be utilized. With a wireless connection, data interference will be minimized.
This was proven in the later version of the ECG device designed by Mr. Alan
Cheng wherein the device has a Bluetooth component which was responsible for
sending data to the host computer. The PCB of the device used in this project
has a specific portion allotted for the Bluetooth device, therefore it’s already
wireless-ready.
Although historical data is not vital to the performance of the project, it
can help by providing previous data to the user. For instance, a user can look
back to his previous treadmill-running days and evaluate how he has been doing,
like if he has reached his target zone by having a heart rate within that zone’s
69
limits; and may reach the conclusion that since he is already doing well at a
particular target zone, perhaps he can move on to the next zone to challenge
himself to exercise more. With the availability of a database, the user would also
not be required to enter information such as age, gender, weight and height
every time he uses the system.
Finally, since the project was able to provide inclination changes visibly via
the program, it can be interfaced with a real treadmill so the inclination may be
controlled. Given there are several technologies already existing for sending
signals from this device to the treadmill, integration can be done without
difficulty. This would enhance the usability of the project as its purpose will be
served by the controlling of the exercising device it wants to be in command of,
the treadmill. Aside from the feedback from the device being sent to the
treadmill, outbound and inbound data transmissions can also be done. This can
be accomplished thru the sending of the treadmill speed to the device, so it may
dynamically calculate for the speed-dependent values. Currently, speed is being
entered manually and is constant all throughout one program run. With speed
being sent from the actual place where it is existing, the treadmill, dynamic data
is expected, hence real-time calculation of values will also happen.
70
BIBLIOGRAPHY
Alenasco A. and Garcia J. (2008), Automatic Real-Time ECG Coding Methodology
Guaranteeing Signal Interpretation Quality, IEEE Transactions on Biomedical
Engineering, Volume: 55 Issue:11
Antonella Boraso, Ph.D (2001). “Why is reduced heart rate beneficial?”.
Dialogues in Cardiovascular Medicine, Volume 6 No. 1, Pages 19 – 24.
Christian Gross (2008). Beginning VB 2008: From Novice to Professional, 1st
Edition, Apress, United States of America.
Dr. Ingrid Waldron (2008). Regulation of Human Heart Rate. Department of
Biology, University of Pennsylvania, Pennsylvania.
Fei Zhang, Ying Wei,and Yong Lian(2008), Efficient QRS detection in wearable
ECG devices for body sensor network, Proceedings of the 5th International
Workshop on Wearable and Implantable Body Sensor Networks, in conjunction
with The 5th International Summer School and Symposium on Medical Devices
and Biosensors.
F.L. Lewis (1992). Applied Optimal Control and Estimation Digital Design&
Implementation, 1st Edition, Prentice-Hall, New Jersey.
Fred Waters (2008). Heart Rate Control for Treadmill Workouts. About.com
Health's Disease and Condition
Hall, Cameron, Figueroa, Arturo, Fernhall, Bo, Kanaley,and Jill A. (2004).
"Energy Expenditure of Walking and Running". Medicine & Science in Sport &
Exercise. Volume 36 - Issue 12, Pages 2128-2134.
Hui Pan and Paul Polishuk (1998). “Definition of Universal Serial Bus”. 1394
Newsletter, Volume 2m Pages 7-9.
James M. Bryant (2011). “Simple Op Amp Measurements”, Analog Devices.
Online Symposium for Electronic Engineers.
Khalil, I.and Sufi, F. (2008). Real-Time ECG Data Transmission with Wavelet
Packet Decomposition over Wireless Network. Intelligent Sensors, Sensor
71
Networks and Information Processing, 2008. ISSNIP 2008. International
Conference, Pages 267-272.
K. Komala, M. Z. Kurian, and Ashwini S. Shivannavar. “Real time access & control
of ECG signals using lab view based web browser”. Proceedings of the 3rd
international conference on Anti-Counterfeiting, security, and identification in
communication (ASID'09). IEEE Press, Piscataway, NJ, USA, Pages 406-409.
LR Keytel, JH Goedecke, TD Noakes, H Hiiloskorpi, R Laukkanen, L van der
Merwe, and EV Lambert (2005). "Prediction of energy expenditure from heart
rate monitoring during submaximal exercise”. Journal of Sports Science , Pages
289-297.
M.S. Manikandanand S. Dandapat (2008). Wavelet threshold based TDL and TDR
algorithms for real-time ECG signal compression. Biomedical Signal Processing
and Control, Volume 3, Issue 1, Pages 44-66.
Mukhopadhyay, S.K., Mitra, M., and Mitra, S. (2011). An ECG data
compression method via R-Peak detection and ASCII Character Encoding.
Computer, Communication and Electrical Technology (ICCCET), 2011
International Conference, Pages 136-141.
So H.H., Chan K.L. (1997), Development of QRS Detection Method for Real-Time
Ambulatory Cardiac Monitor, IEEE/EMBS, Proceedings - 19th International
Conference.
Steven F. Barrett and Daniel J. Pack (2006). Microcontroller Fundamentals for
Engineers and Scientist, 1st Edition, Morgan & Claypool, United States of America.
Texas Instruments (2007). Cap-Free, NMOS, 400mA Low-Dropout Regulator
with Reverse Current Protection. Texas Instruments Incorporated.
Texas Instruments (2009). MSP430 USB Communications Device Class (CDC) API
Programmer’s Guide Version 1.0.
Texas Instruments (2009). Precision, Low Power INSTRUMENTATION AMPLIFIER.
Burr-Brown Corporation.
Texas Instruments (2010). MSP430x5xx/MSP430x6xx Family User's Guide. Texas
Instruments Incorporated.
Wagner GS and Marriott HJ (2002). Marriott's Practical Electrocardiography 10th
ed. Lippincott Williams & Wilkins.
72
Yun-Chi Yeh and, Wen-June Wang (2008). QRS complexesdetection for ECG
signal: The Difference Operation Method. Computer Methods and Programs in
Biomedicine, Volume 91, Issue 3,Pages 245-254.
73
APPENDIX A
Operations Manual
1. System Requirement
a. Intel Atom Dual Processor 1.6 GHz
b. Windows XP Operating System
c. 2GB Memory RAM
d. Microsoft Visual Basic
2. Installation Procedure
a. Install Microsoft Visual Basic software to laptop or desktop.
b. Connect the device in the USB port of the laptop or desktop.
c. Install MSP430 CDC setup information for the ECG device.
d. Open the software.
3. User’s Manual
a. Connect the ECG device to the USB port through a USB data cable
to the laptop or desktop.
b. Connect the PS410 ECG Simulator to the ECG device.
74
c. Turn on ECG device power switch.
d. Run the Visual Basic graphical user interface software.
e. Choose COM port for the MSP430 CDC API.
f. Input required user information and target zone.
g. Click connect button in the GUI.
h. Proceed with the work out.
i. Input treadmill’s speed at GUI (optional).
j. Click disconnect button and close/end the program when finished.
4. Troubleshooting Guides and Procedures
a. If the COM port does not appear, check the port status of the
laptop or desktop. Make sure that the ECG device is active and
particular port is detected.
b. If the com port is fine and the software cannot detect that specific
port, unplug the connection and close the program. It is
recommended to connect USB data cable before opening the
program.
c. If the program terminates when running the graphical user
interface restart the program, do not click the connect button twice.
d. If the display of the waveform is slow close other computer
application.
5. Error Definitions
75
a. Check Comm. Port Settings – Error in com port setting.
APPENDIX B
Pictures of Prototype
Electrocardiogram Device Top and Bottom
76
Electrocardiogram Device and PS410 ECG Simulator
77
Electrocardiogram Device, PS410 ECG Simulator, Laptop Computer, and
Oscilloscope
78
APPENDIX C
Program Listing

MSP430F5529 Program
#include "Common\device.h"
#include "Common\types.h"
#include "Common\hal_UCS.h"
#include "Common\hal_pmm.h"
#include "USB_Common\descriptors.h"
#include "USB_Common\usb.h"
#ifdef _CDC_
#include "USB_CDC_API\UsbCdc.h"
#endif
#ifdef _HID_
#include "USB_HID_API\UsbHid.h"
#endif
#include "main.h"
#include "USBCDC_constructs.h"
#include <intrinsics.h>
#include <string.h>
volatile BYTE bDataReceived_event = TRUE; // Indicates data has been received without an open rcv
operation
//volatile BYTE bDataReceiveCompleted_event = FALSE; // data receive completed event
//volatile BYTE bDataSendCompleted_event = FALSE;
// data send completed event
char outString[32];
WORD x;
WORD rounds=0;
// Dummy variable for use with abortSend()
#define MEGA_DATA_LENGTH 2046
BYTE dataBuf[MEGA_DATA_LENGTH];
int w;
#define Num_of_Results 8
volatile
volatile
volatile
volatile
volatile
volatile
volatile
volatile
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
int
int
int
int
int
int
int
int
A0results[Num_of_Results];
A1results[Num_of_Results];
A2results[Num_of_Results];
A3results[Num_of_Results];
A4results[Num_of_Results];
A5results[Num_of_Results];
A6results[Num_of_Results];
A7results[Num_of_Results];
79
unsigned short int z=100;
/*----------------------------------------------------------------------------+
| Main Routine
|
+----------------------------------------------------------------------------*/
VOID main(VOID)
{
WDTCTL = WDTPW + WDTHOLD;
// Stop watchdog timer
Init_StartUp();
USB_init();
USB_setEnabledEvents(kUSB_VbusOnEvent+kUSB_VbusOffEvent+kUSB_dataReceivedEvent+kUSB_Usb
SuspendEvent+kUSB_UsbResumeEvent+kUSB_UsbResetEvent);
//ADC #####################################################
P6SEL = 0x0F;
// Enable A/D channel inputs
TBCCR0 = 625 - 1;
// TBCLK = 4.8k Hz
TBCCTL1 = OUTMOD_2;
TBCCR1 = 300 - 1;
TBCTL = TBSSEL_2 + ID_2 + MC_1 + TBCLR;
REFCTL0 &= ~REFMSTR;
// Reset REFMSTR to hand over control to
// ADC12_A ref control registers
ADC12CTL0 = ADC12SHT1_2 + ADC12SHT0_2 + ADC12REF2_5V + ADC12REFON + ADC12ON; // Ref
= 2.5V
ADC12CTL1 = ADC12SHS_3 + ADC12SHP + ADC12DIV_2 + ADC12SSEL_3 + ADC12CONSEQ_3; // SAH
source = TB0.1,
ADC12CTL2 = ADC12TCOFF + ADC12RES_2;
// 12bit, temperature sensor off
// VR+ = VREF+ = 2.5V, VR- = AVSS
ADC12MCTL0 = ADC12SREF_1
ADC12MCTL1 = ADC12SREF_1
ADC12MCTL2 = ADC12SREF_1
ADC12MCTL3 = ADC12SREF_1
ADC12MCTL4 = ADC12SREF_1
ADC12MCTL5 = ADC12SREF_1
ADC12MCTL6 = ADC12SREF_1
ADC12MCTL7 = ADC12SREF_1
end seq. >> LPF I
ADC12IE = 0x08;
ADC12CTL0 |= ADC12ENC;
ADC12CTL0 |= ADC12SC;
+
+
+
+
+
+
+
+
ADC12INCH_0; // ref+=AVcc, channel = A0 >> LEAD V6
ADC12INCH_1; // ref+=AVcc, channel = A1 >> LEAD V5
ADC12INCH_2; // ref+=AVcc, channel = A2 >> LEAD V4
ADC12INCH_3; // ref+=AVcc, channel = A3 >> LEAD V3
ADC12INCH_4; // ref+=AVcc, channel = A4 >> LEAD V2
ADC12INCH_5; // ref+=AVcc, channel = A >> LEAD V1
ADC12INCH_6; // ref+=AVcc, channel = A6 >> LPF II
ADC12INCH_7 + ADC12EOS; // ref+=AVcc, channel = A3,
// Enable ADC12IFG.3
// Enable conversions
// Start convn - software trigger
//ADC#####################################################
// Check if we're already physically attached to USB, and if so, connect to it
// This is the same function that gets called automatically when VBUS gets attached.
if (USB_connectionInfo() & kUSB_vbusPresent)
80
USB_handleVbusOnEvent();
while(1)
{
switch(USB_connectionState())
{
case ST_USB_DISCONNECTED:
__bis_SR_register(LPM3_bits + GIE);
break;
case ST_USB_CONNECTED_NO_ENUM:
break;
case ST_ENUM_ACTIVE:
if(!bDataReceived_event)
{
// Enter LPM3 w/interrupt
// Do this until a key is pressed
if(sendData_inBackground((BYTE*)outString,strlen(outString),1,0))
// Send it; no timeout
{
USBCDC_abortSend(&x,1);
// Operation may still be open; cancel it
break;
}
}
else
{
bDataReceived_event = FALSE;
USBCDC_rejectData(1);
for(rounds=0;rounds<50;rounds++)
{
if(sendData_inBackground(dataBuf,MEGA_DATA_LENGTH,1,0))
// Send all of RAM
{
USBCDC_abortSend(&x,1);
// Operation probably still open; cancel it
break;
}
}
if(sendData_inBackground((BYTE*)outString,strlen(outString),1,0))
// Send it; no timeout
{
USBCDC_abortSend(&x,1);
break;
// Operation may still be open; cancel it
}
}
break;
case ST_ENUM_SUSPENDED:
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/interrupt
break;
case ST_ENUM_IN_PROGRESS:
break;
81
case ST_NOENUM_SUSPENDED:
__bis_SR_register(LPM3_bits + GIE);
_NOP();
break;
case ST_ERROR:
_NOP();
break;
default:;
}
}
}
//---------------------------------------------------------------------------/*----------------------------------------------------------------------------+
| System Initialization Routines
|
+----------------------------------------------------------------------------*/
VOID Init_Clock(VOID)
{
if (USB_PLL_XT == 2)
{
P5SEL |= 0x0C; // Enable the XT2 pins. Without this, the xtal pins default to being I/O's.
// Use the REFO oscillator to source the FLL and ACLK
UCSCTL3 = (UCSCTL3 & ~(SELREF_7)) | (SELREF__REFOCLK);
UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (SELA__REFOCLK);
// MCLK will be driven by the FLL (not by XT2), referenced to the REFO
Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768);
// Start the FLL, at the freq indicated by the config constant USB_MCLK_FREQ
XT2_Start();
}
else
{
P5SEL |= 0x10;
default to being I/O's.
// Start the "USB crystal"
// Enable the XT1 pins. Without this, the xtal pins
// Use the REFO oscillator to source the FLL and ACLK
UCSCTL3 = SELREF__REFOCLK;
UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (SELA__REFOCLK);
// MCLK will be driven by the FLL (not by XT2), referenced to the REFO
Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768); // set FLL (DCOCLK)
XT1_Start();
// Start the "USB crystal"
}
}
82
//---------------------------------------------------------------------------VOID Init_Ports(VOID)
{
// Drive all I/O's as output-low, making sure there's no shoot-through current. There
// should be no floating I/Os, to prevent unnecessary current draw during USB suspend.
PAOUT = 0x0000;
PASEL = 0x0000;
PADIR = 0xFFFF;
PBOUT = 0x0000;
PBSEL = 0x0000;
PBDIR = 0xFFFF;
PCOUT = 0x0000;
PCSEL = 0x0000;
PCDIR = 0xFFFF;
PDOUT = 0x0000;
PDSEL = 0x0000;
PDDIR = 0xFFFF;
PJDIR = 0xFFFF;
PJOUT = 0x0000;
}
//---------------------------------------------------------------------------VOID Init_StartUp(VOID)
{
__disable_interrupt();
// Disable global interrupts
Init_Ports();
SetVCore(3);
frequency
Init_Clock();
__enable_interrupt();
// Init ports (do first ports because clocks do change ports)
// USB core requires the VCore set to 1.8 volt, independ of CPU clock
// enable global interrupts
}
//---------------------------------------------------------------------------// To be robust, an application should handle fault events that invoke the NMI vector.
#pragma vector = UNMI_VECTOR
__interrupt VOID UNMI_ISR(VOID)
{
switch (__even_in_range(SYSUNIV, SYSUNIV_SYSBUSIV))
{
case SYSUNIV_NONE:
__no_operation();
break;
case SYSUNIV_NMIIFG:
__no_operation();
83
break;
case SYSUNIV_OFIFG:
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC fault source flags
SFRIFG1 &= ~OFIFG;
// Clear OFIFG flag
break;
case SYSUNIV_ACCVIFG:
__no_operation();
break;
case SYSUNIV_SYSBUSIV:
// In the rare event of an internal system bus error - must clear the flag and re-initialize USB.
SYSBERRIV = 0;
// Clear flag
USB_disable();
// Disable USB
if (USB_connectionInfo() & kUSB_vbusPresent)
USB_handleVbusOnEvent();
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
static unsigned int index = 0;
switch(__even_in_range(ADC12IV,34))
{
case 0: break;
// Vector
case 2: break;
// Vector
case 4: break;
// Vector
case 6: break;
// Vector
case 8: break;
// Vector
case 10: break;
// Vector
case 12:
0: No interrupt
2: ADC overflow
4: ADC timing overflow
6: ADC12IFG0
8: ADC12IFG1
10: ADC12IFG2
// Vector 12: ADC12IFG3
A0results[index] = ADC12MEM0 >> 4;
// Move A0 results, IFG is cleared >> LEAD V6
A1results[index] = ADC12MEM1 >> 4;
// Move A1 results, IFG is cleared >> LEAD V5
dataBuf[w] = - ADC12MEM1 >> 4;
w++;
if(w==2046)
w=0;
A2results[index]
A3results[index]
A4results[index]
A5results[index]
A6results[index]
A7results[index]
index++;
=
=
=
=
=
=
ADC12MEM2
ADC12MEM3
ADC12MEM4
ADC12MEM5
ADC12MEM6
ADC12MEM7
//DATA TRANSFER
>> 4;
// Move A2 results, IFG is cleared >> LEAD V4
>> 4;
// Move A3 results, IFG is cleared >> LEAD V3
>> 4;
// Move A4 results, IFG is cleared >> LEAD V2
>> 4;
// Move A5 results, IFG is cleared >> LEAD V1
>> 4;
// Move A6 results, IFG is cleared >> LPF II
>> 4;
// Move A7 results, IFG is cleared >> LPF I
// Increment results index, modulo; Set Breakpoint1 here
if (index == 8)
84
{
(index = 0);
}
case 14: break;
case 16: break;
case 18: break;
case 20: break;
case 22: break;
case 24: break;
case 26: break;
case 28: break;
case 30: break;
case 32: break;
case 34: break;
default: break;
}
// Vector 14:
// Vector 16:
// Vector 18:
// Vector 20:
// Vector 22:
// Vector 24:
// Vector 26:
// Vector 28:
// Vector 30:
// Vector 32:
// Vector 34:
ADC12IFG4
ADC12IFG5
ADC12IFG6
ADC12IFG7
ADC12IFG8
ADC12IFG9
ADC12IFG10
ADC12IFG11
ADC12IFG12
ADC12IFG13
ADC12IFG14
}

Visual Basic Program
Imports
Imports
Imports
Imports
System.IO.Ports
System.Text
System
System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Windows.Forms
Public Class Form1
Dim WithEvents RS232 As SerialPort
Dim
Dim
Dim
Dim
inData As String
bDataReady As Boolean
counter As Integer = 0
ReceiveData As String
Dim i As Integer = 0
Dim resultArray As String()
Dim temp_ahead As Integer = 0
Dim X_Start As Integer
Dim Y_Start As Integer
Dim
Dim
Dim
Dim
Dim
k As Integer = 0
g1 As Graphics
fm As Graphics
p2 As New System.Drawing.Pen(Color.Red, 1)
p1 As New System.Drawing.Pen(Color.Blue, 1)
Dim DataEnter As Boolean = False
85
Dim SaveFalg As Boolean = False
Dim bFirst As Boolean
Dim bMarker As Boolean, MarkerX, MarkerY As Integer
Dim end1, end2, end3 As String
Dim request_data_flag As Boolean = False
Dim pc_check_flag As Boolean = False
'auto-feedback
Dim tz As Double = 5
Dim age As Double = 0
Dim mhr As Double = 0
Dim ahr As Double = 0
Dim r2 As Double = 0
Dim r1 As Double = 0
Dim speed As Double
Dim distance As Integer
Dim time As Double
Dim incline As Integer
'Basal Metabolic Rate
Dim H1 As Double = 0
Dim H2 As Double = 0
Dim FH As Double = 0
Dim W As Double = 0
'Calories Burn
Dim TCB As Double = 0
Dim NCB As Double = 0
Dim calorie As Integer
Dim
Dim
Dim
Dim
msg As String
title As String
style As MsgBoxStyle
response As MsgBoxResult
Dim dd As Date
Public Serial_data_count As Integer = 0
Public Serial_data_tmp As String
Public Serial_array(100000) As String
'inData
'Array
Dim clock1 As Double
Dim clock2 As Double
Dim hours As Double = My.Computer.Clock.LocalTime.Hour
Dim minutes As Double = My.Computer.Clock.LocalTime.Minute
Dim seconds As Double = My.Computer.Clock.LocalTime.Second
'metabolic heart rate
Dim MR As Double '
Dim gender As Integer
'So and Chan
Dim a As Integer = 0
86
Dim b As Integer = 0
Dim hr_time_count As Integer = 0
Dim maf_count As Integer = 0
Public maf_array(5) As String
Dim hr_maf_results As Double
Public hr_array(5) As String
Dim setting_onset As Integer
Dim detecting_peak As Integer
Dim maxi As Double = 0
Dim slope_threshold As Double = 0
Dim onset_check As Integer = 0
Dim hr_onset As Integer = 0
Dim peak_address_ptr As Integer = 0
Dim hr_peak_addr_tmp As Integer = 0
Dim HR_peak_tmp As Integer = 0
Dim hr_slope_tmp As Double
Dim hr_slope As Integer
Dim detect_peak_counter As Integer
Public peak_address(5) As String
Dim heartrate As Double
Delegate Sub SetTextCallback(ByVal InputString As String)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
For Each sp As String In SerialPort.GetPortNames()
cmbCOM.Items.Add(sp)
Next
cmbCOM.Sorted = True
cmbCOM.SelectedIndex = 0
bFirst = True
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnStart.Click
Dim mBaudRate As Integer
Dim mParity As IO.Ports.Parity
Dim mDataBit As Integer
Dim mStopbit As IO.Ports.StopBits
Dim mPortName As String
clock1 = hours + (minutes / 60) + (seconds / 3600)
mPortName = cmbCOM.SelectedItem.ToString
mBaudRate = 9600
mParity = Parity.None
mDataBit = 8
mStopbit = StopBits.One
RS232 = New IO.Ports.SerialPort(mPortName, mBaudRate, mParity, mDataBit, mStopbit)
'RS232.Encoding = Encoding.Unicode
RS232.Encoding = Encoding.ASCII
If Not RS232.IsOpen Then
RS232.Open()
RS232.ReceivedBytesThreshold = 1
87
Else
MsgBox("!!!", MsgBoxStyle.Critical Or MsgBoxStyle.OkCancel)
End
End If
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnClose.Click
If RS232 Is Nothing OrElse Not RS232.IsOpen Then
MsgBox("!!!", MsgBoxStyle.Critical Or MsgBoxStyle.OkCancel)
Exit Sub
End If
RS232.Close()
RS232 = Nothing
End Sub
Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnEnd.Click
If Not RS232 Is Nothing Then
If RS232.IsOpen Then RS232.Close()
End If
End
End Sub
Private Sub RS232_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles RS232.DataReceived
'If e.EventType <> SerialData.Chars Then Exit Sub
'Do '
inData = RS232.ReadByte
DataEnter = True
Serial_packet_process()
soandchan()
hrmafprocess(inData)
hrslopeprocess(inData)
printX(inData)
If Serial_data_count = 89961 Then
Serial_data_count = 0
End If
'Loop While RS232.BytesToRead <> 0
'RS232.DiscardInBuffer()
End Sub
Function printX(ByVal Xvalue As Byte)
X_Start = 1
Y_Start = (PictureBox1.Height)
g1 = PictureBox1.CreateGraphics
g1.PageUnit = GraphicsUnit.Pixel
g1.PageScale = 1
g1.DrawLine(p1, 0, CInt(PictureBox1.Height), CInt(PictureBox1.Width), CInt(PictureBox1.Height))
g1.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
88
g1.ScaleTransform(1, 1)
If DataEnter = True Then
g1.DrawLine(p2, X_Start + k, Y_Start - temp_ahead, X_Start + (k + 1), Y_Start - Xvalue)
temp_ahead = Xvalue
DataEnter = False
End If
k=k+1
If k = PictureBox1.Width Then ' - TrackBar1.Value * 12
k=0
g1.Clear(Color.White)
End If
End Function
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton1.CheckedChanged
tz = 1
THR1.Text = Mhrtxt.Text * 0.5
THR2.Text = Mhrtxt.Text * 0.6
goodbad()
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton2.CheckedChanged
tz = 2
THR1.Text = Mhrtxt.Text * 0.6
THR2.Text = Mhrtxt.Text * 0.7
r1 = THR1.Text
r2 = THR2.Text
goodbad()
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton3.CheckedChanged
tz = 3
THR1.Text = Mhrtxt.Text * 0.7
THR2.Text = Mhrtxt.Text * 0.8
goodbad()
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton4.CheckedChanged
tz = 4
THR1.Text = Mhrtxt.Text * 0.8
THR2.Text = Mhrtxt.Text * 0.9
r1 = THR1.Text
r2 = THR2.Text
goodbad()
End Sub
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton5.CheckedChanged
tz = 5
THR1.Text = Mhrtxt.Text * 0.9
THR2.Text = Mhrtxt.Text * 1.0
r1 = THR1.Text
r2 = THR2.Text
goodbad()
End Sub
89
Public Sub HRtBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
HRtBox.TextChanged
ahr = HRtBox.Text
r1 = THR1.Text
r2 = THR2.Text
clock2 = My.Computer.Clock.LocalTime.Hour + (My.Computer.Clock.LocalTime.Minute / 60) +
(My.Computer.Clock.LocalTime.Second / 3600)
If ahr < mhr Then
HRtBox.BackColor = Color.Green
ElseIf ahr >= mhr Then
HRtBox.BackColor = Color.Red
Speedtxt.Text = 0
Timetxt.Text = 0
Inctxt.Text = 0
msg = "WARNING!" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Exclamation Or MsgBoxStyle.Critical
title = "MsgBox Demonstration" ' Define title.
' Display message.
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Ok Then
End
Else
' Perform some other action.
End If ' END IF RESPONSE
End If ' HEART RATE
If ahr > r2 Then
tresult.Text = "BAD"
msg = "Do you want to go to the Next Zone?" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
MsgBoxStyle.Exclamation Or MsgBoxStyle.YesNo
title = "MsgBox Demonstration" ' Define title.
' Display message.
response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then ' User chose Yes.
If RadioButton1.Checked = True Then
RadioButton2.Checked = True
ElseIf RadioButton2.Checked = True Then
RadioButton3.Checked = True
ElseIf RadioButton3.Checked = True Then
RadioButton4.Checked = True
ElseIf RadioButton4.Checked = True Then
RadioButton5.Checked = True
End If ' END IF RADIOBUTTON
Else
' Perform some other action.
End If ' END IF RESPONSE
ElseIf ahr < r1 Then
tresult.Text = "BAD"
feedback()
ElseIf r1 < ahr < r2 Then
tresult.Text = "GOOD"
End If
90
If gender = 1 Then
BMRtxt.Text = ((-55.0969 + (0.6309 * ahr) + (0.1988 * (W / 2.2)) + (0.2017 * age)) / 4.184) * 60
* (clock2 - clock1)
ElseIf gender = 2 Then
BMRtxt.Text = ((-20.4022 + (0.4472 * ahr) + (0.1263 * (W / 2.2)) + (0.074 * age)) / 4.184) * 60
* (clock2 - clock1)
End If
End Sub
Private Sub Mhrtxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Mhrtxt.TextChanged
mhr = Mhrtxt.Text
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
ahr = 80
HRtBox.Text = ahr
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ahr = 110
HRtBox.Text = ahr
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ahr = 200
HRtBox.Text = ahr
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ahr = ahr + 5
HRtBox.Text = ahr
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ahr = ahr - 5
HRtBox.Text = ahr
End Sub
Private Sub Agetxt_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Agetxt.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Enter) Then
age = Agetxt.Text
Mhrtxt.Text = 220 - age
Agetxt.Enabled = False
Tzgbox.Enabled = True
btnStart.Enabled = True
malerb.Enabled = True
femalerb.Enabled = True
'This tells the system not to process
'the key, as you've already taken care
'of it
e.Handled = True
End If
End Sub
91
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button9.Click
speed = speed + 1
If (speed > 12.0) Then
speed = 12.0
Button9.Enabled = False
End If
Speedtxt.Text = speed
timecheck()
End Sub
Private Sub Button8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button8.Click
speed = speed - 1
If (speed < 5) Then
speed = 5
Button8.Enabled = False
End If
Speedtxt.Text = speed
timecheck()
End Sub
Private Function timecheck() As Boolean
Select Case speed
'Equivalent Paces by incline
Case 5
Select Case incline
Case 0
time = 12.31
Timetxt.Text = time
Case 1
time = 11.44
Timetxt.Text = time
Case 2
time = 11.05
Timetxt.Text = time
Case 3
time = 10.32
Timetxt.Text = time
Case 4
time = 10.03
Timetxt.Text = time
Case 5
time = 9.38
Timetxt.Text = time
Case 6
time = 9.16
Timetxt.Text = time
Case 7
time = 8.56
Timetxt.Text = time
Case 8
time = 8.38
Timetxt.Text = time
Case 9
time = 8.22
Timetxt.Text = time
Case 10
time = 8.07
92
Timetxt.Text = time
End Select
Case 6
Select Case incline
Case 0
time = 10.26
Timetxt.Text =
Case 1
time = 9.52
Timetxt.Text =
Case 2
time = 9.24
Timetxt.Text =
Case 3
time = 9.0
Timetxt.Text =
Case 4
time = 8.38
Timetxt.Text =
Case 5
time = 8.19
Timetxt.Text =
Case 6
time = 8.02
Timetxt.Text =
Case 7
time = 7.46
Timetxt.Text =
Case 8
time = 7.32
Timetxt.Text =
Case 9
time = 7.19
Timetxt.Text =
Case 10
time = 7.07
Timetxt.Text =
End Select
Case 7
Select Case incline
Case 0
time = 8.56
Timetxt.Text =
Case 1
time = 8.32
Timetxt.Text =
Case 2
time = 8.1
Timetxt.Text =
Case 3
time = 7.51
Timetxt.Text =
Case 4
time = 7.34
Timetxt.Text =
Case 5
time = 7.19
Timetxt.Text =
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
93
Case 6
time = 7.05
Timetxt.Text =
Case 7
time = 6.53
Timetxt.Text =
Case 8
time = 6.41
Timetxt.Text =
Case 9
time = 6.31
Timetxt.Text =
Case 10
time = 6.21
Timetxt.Text =
End Select
Case 8
Select Case incline
Case 0
time = 7.49
Timetxt.Text =
Case 1
time = 7.3
Timetxt.Text =
Case 2
time = 7.13
Timetxt.Text =
Case 3
time = 6.58
Timetxt.Text =
Case 4
time = 6.45
Timetxt.Text =
Case 5
time = 6.32
Timetxt.Text =
Case 6
time = 6.21
Timetxt.Text =
Case 7
time = 6.11
Timetxt.Text =
Case 8
time = 6.01
Timetxt.Text =
Case 9
time = 5.52
Timetxt.Text =
Case 10
time = 5.44
Timetxt.Text =
End Select
Case 9
Select Case incline
Case 0
time = 6.57
Timetxt.Text =
Case 1
time = 6.42
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
94
Timetxt.Text =
Case 2
time = 6.28
Timetxt.Text =
Case 3
time = 6.16
Timetxt.Text =
Case 4
time = 6.05
Timetxt.Text =
Case 5
time = 5.55
Timetxt.Text =
Case 6
time = 4.45
Timetxt.Text =
Case 7
time = 5.37
Timetxt.Text =
Case 8
time = 5.29
Timetxt.Text =
Case 9
time = 5.21
Timetxt.Text =
Case 10
time = 5.14
Timetxt.Text =
End Select
Case 10
Select Case incline
Case 0
time = 6.15
Timetxt.Text =
Case 1
time = 6.03
Timetxt.Text =
Case 2
time = 5.52
Timetxt.Text =
Case 3
time = 5.42
Timetxt.Text =
Case 4
time = 5.32
Timetxt.Text =
Case 5
time = 5.24
Timetxt.Text =
Case 6
time = 5.16
Timetxt.Text =
Case 7
time = 5.08
Timetxt.Text =
Case 8
time = 5.02
Timetxt.Text =
Case 9
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
95
time = 4.55
Timetxt.Text =
Case 10
time = 4.49
Timetxt.Text =
End Select
Case 11
Select Case incline
Case 0
time = 5.41
Timetxt.Text =
Case 1
time = 5.31
Timetxt.Text =
Case 2
time = 5.22
Timetxt.Text =
Case 3
time = 5.13
Timetxt.Text =
Case 4
time = 5.05
Timetxt.Text =
Case 5
time = 4.58
Timetxt.Text =
Case 6
time = 4.51
Timetxt.Text =
Case 7
time = 4.45
Timetxt.Text =
Case 8
time = 4.39
Timetxt.Text =
Case 9
time = 4.33
Timetxt.Text =
Case 10
time = 4.28
Timetxt.Text =
End Select
Case 12
Select Case incline
Case 0
time = 5.13
Timetxt.Text =
Case 1
time = 5.04
Timetxt.Text =
Case 2
time = 4.56
Timetxt.Text =
Case 3
time = 4.49
Timetxt.Text =
Case 4
time = 4.42
Timetxt.Text =
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
time
96
Case 5
time = 4.36
Timetxt.Text =
Case 6
time = 4.3
Timetxt.Text =
Case 7
time = 4.24
Timetxt.Text =
Case 8
time = 4.19
Timetxt.Text =
Case 9
time = 4.14
Timetxt.Text =
Case 10
time = 4.1
Timetxt.Text =
End Select
Case Else
time = 0
Timetxt.Text = time
End Select
time
time
time
time
time
time
End Function
Private Function feedback() As Boolean
incline = incline + 1
If (incline > 10) Then
incline = 10
End If
timecheck()
Timetxt.Text = time
Inctxt.Text = incline
End Function
Private Function goodbad() As Boolean 'Target Zone Status
r1 = THR1.Text
r2 = THR2.Text
If ahr > r2 Then
tresult.Text = "BAD"
ElseIf ahr < r1 Then
tresult.Text = "BAD"
ElseIf r1 < ahr < r2 Then
tresult.Text = "GOOD"
End If
speed = 5
time = 12.31
incline = 0
Speedtxt.Text = speed
Timetxt.Text = time
Inctxt.Text = incline
End Function
Private Sub H1txt_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles H1txt.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Enter) Then
H1 = H1txt.Text
H1txt.Enabled = False
e.Handled = True
97
End If
End Sub
Private Sub H2txt_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles H2txt.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Enter) Then
H2 = H2txt.Text
H2txt.Enabled = False
FH = (H1 * 12) + H2
e.Handled = True
Wtxt.Enabled = True
End If
End Sub
Private Sub Wtxt_KeyPress(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles Wtxt.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Enter) Then
W = Wtxt.Text
Wtxt.Enabled = False
e.Handled = True
Agetxt.Enabled = True
End If
End Sub
Private Sub malerb_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles malerb.CheckedChanged
gender = 1
End Sub
Private Sub femalerb_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles femalerb.CheckedChanged
gender = 2
End Sub
Private Sub Speedtxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Speedtxt.TextChanged
Select Case speed
Case 5 To 6
TCBtxt.Text = 0.53 * W
NCBtxt.Text = 0.3 * W
Case 7 To 12
TCBtxt.Text = 0.75 * W
NCBtxt.Text = 0.63 * W
End Select
End Sub
Private Sub Serial_packet_process()
Serial_data_tmp = inData
Serial_array(Serial_data_count) = Chr(Serial_data_tmp)
Serial_data_count = Serial_data_count + 1
'ASCII
End Sub
Public Sub soandchan()
hr_time_count = 0
If a < 5 Then
maf_array(a) = 0
98
a=a+1
End If
hr_maf_results = 0
If b < 5 Then
hr_array(b) = 0
b=b+1
End If
setting_onset = 1
detecting_peak = 0
maxi = 0
slope_threshold = 0
onset_check = 0
hr_onset = 0
peak_address_ptr = 0
End Sub
Public Sub newmaxi()
maxi = ((HR_peak_tmp - hr_onset - maxi) / 2) + maxi
End Sub
Public Sub newslope()
slope_threshold = 0.7 * maxi
End Sub
Public Sub hrmafprocess(ByVal inData)
maf_array(0) = maf_array(1)
maf_array(1) = maf_array(2)
maf_array(2) = maf_array(3)
maf_array(3) = maf_array(4)
maf_array(4) = inData
hr_maf_results = (maf_array(0) + maf_array(1) + maf_array(2) + maf_array(3) + maf_array(4)) / 5
hr_time_count = hr_time_count + 1
hr_slope_tmp = 0
hr_slope = 0
End Sub
Public Sub hrslopeprocess(ByVal inData)
hr_array(0) = hr_array(1)
hr_array(1) = hr_array(2)
hr_array(2) = hr_array(3)
hr_array(3) = hr_array(4)
hr_array(4) = inData
hr_slope_tmp = -2 * hr_array(0) - hr_array(1) + hr_array(3) + 2 * hr_array(4)
If setting_onset = 1 Then
If hr_time_count > 5 Then
If hr_slope_tmp > hr_slope Then
hr_slope = hr_slope_tmp
End If
If hr_time_count = 11 Then
setting_onset = 0
maxi = hr_slope
99
slope_threshold = maxi * 0.9
onset_check = 0
End If
End If
ElseIf detecting_peak = 1 Then
If hr_maf_results > HR_peak_tmp Then
HR_peak_tmp = hr_maf_results
hr_peak_addr_tmp = hr_time_count
End If
detect_peak_counter = detect_peak_counter + 1
If detect_peak_counter >= 100 Then
If peak_address_ptr < 5 Then
peak_address(peak_address_ptr) = hr_peak_addr_tmp
peak_address_ptr = peak_address_ptr + 1
Else
peak_address(0) = peak_address(1)
peak_address(1) = peak_address(2)
peak_address(2) = peak_address(3)
peak_address(3) = peak_address(4)
peak_address(4) = hr_peak_addr_tmp
If peak_address(4) > peak_address(0) Then
heartrate = 115200 / peak_address(4) - peak_address(0)
heartrate = ahr
HRtBox.Text = ahr
Else
heartrate = 115200 / (65536 - peak_address(0) + peak_address(4))
heartrate = ahr
HRtBox.Text = ahr
End If
newmaxi()
newslope()
detecting_peak = 0
End If
Else
If hr_slope_tmp > slope_threshold Then
onset_check = onset_check + 1
Else
onset_check = 0
End If
If onset_check >= 6 Then
hr_onset = hr_maf_results
onset_check = 0
detecting_peak = 1
detect_peak_counter = 0
HR_peak_tmp = hr_onset
hr_peak_addr_tmp = hr_time_count
End If
End If
End If
End Sub
End Class
100
APPENDIX D
Data Sheets
101
Download