Académique Documents
Professionnel Documents
Culture Documents
( )
)()
where this calculation will be inserted in the programming code.
Figure 3.5: ECG waveform (PQRST peak)
3.3.3 Graphic LCD Connection
Graphic LCD was used to display the results of the heartbeat calculation.
The connection of the GLCD and the microcontroller should be defined in the
programming as the use of GLCD need to be initiated so that the PIC library can
understand the data and send the desired output to the screen for display. PORTD
18
of the PIC microcontroller that had been programmed to be the digital output of
the ECG circuit is then connected to the GLCD pin.
3.4 Alarm System
The alarm system used a buzzer that will beep each time abnormal heart rate is
detected. Micro C programming has a built in sound system that will make it easier
for the user to adjust how the sound will be. In this project the buzzer was set to beep
for about 10 seconds.
CHAPTER 4
RESULTS & DISCUSSION
4.1 Introduction
This chapter covered the results of the project and discussion regarding the
results obtained.
4.2 ECG Circuit
The ECG circuit had been built according to the circuit design and successfully
produces ECG waveform as needed when tested with DNI Nevada ECG simulator
and Tektronix Oscilloscope. This ECG circuit consists of three stages;
i. Differential Amplifier
ii. Low Pass Filter
iii. High Pass Filter
20
The differential amplifier as in Figure 4.1 will take the difference in electrical
signal in Right Arm (RA) and Left Arm (LA). The use of differential amplifier is
simpler and easier to obtain the desired output than instrumentation amplifier.
However, instrumentation amplifier is more advisable to be used for biomedical
equipment. As for this project, the focus is not in the ECG circuit implementation but
the heartbeat detection and data recording. Thus, differential amplifier was used as
the ECG waveform output is more stable rather than the output when using
instrumentation amplifier which required more detail implementation which is time
consuming. When taking the signal from the body, higher gain should be considered
because the electrical signal from the body is very small. The gain use for the
differential amplifier is 1000 where this is the normal gain used for ECG circuit in
most ECG applications based on the datasheet of instrumentation amplifier AD620.
Figure 4.1: Differential amplifier
The follow up stage is low pass filter with unity gain. The corner frequency
below 60Hz was chosen to effectively remove the noise coming from the power line
interference and the frequency value is acceptable for not giving too much distortion
effects on the P and T points in the ECG waveform. High pass filter is used in the
last stage with corner frequency of 0.03Hz in order to remove the noise resulting from
the electrode movements and respiration. As this project use ECG simulator which is
not involving human respiration, the high pass filter will not be of much help for the
circuit but certainly affected the results if the human body is used in place of the
Gain =
21
simulator. Figure 4.2 shows the whole circuit of ECG together with PIC 18F4550
and the graphic LCD.
Figure 4.2: ECG circuit with PIC microcontroller and the graphic LCD
4.3 Waveform Display
There should be a difference between the ECG waveform displayed for heart
rate less than 60bpm and more than 100bpm. For heart rate less than 60 bpm, most
heart failure associate with it is said to be bradycardia. The waveform should be as
shown in Figure 4.3. From the figure, the R peaks are quite apart from each other
compared to normal ECG. In the case of heart rate more than 100 bpm or also known
as tachycardia, the waveform will be similar to Figure 4.4 where the R peaks are
more frequent than normal ECG waveform. Figure 4.5 shows the ECG output when
22
ventricular fibrillation occur. These figures were taken from the experiment using the
ECG simulator together with ECG circuit built. The output results were true when
compared with the output results of ECG module using the same scaling.
Figure 4.3: 30 bpm ECG waveform
Figure 4.4: 120 bpm ECG waveform
23
Figure 4.5: Ventricular Fibrillation
4.4 Heart Rate Reading
Heart rate reading will be displayed on the graphic LCD in beats per minute
(bpm). Normal resting heart rate for a person is 60 bpm to 100 bpm. When the heart
rate count is below 60 bpm, it is assumed to be abnormal heart rate. The same goes
for a heart rate count higher than 100 bpm. When, these abnormal heart rate counting
occur, the graphic LCD should display the ECG waveform at that time. This can be
done as the ADC inside the PIC microcontroller will change the analog signal of the
ECG output to digital signal and transferred to the input of the LCD. In this project,
the output of the ECG circuit (pin 6 of OP97 in high pass filter) is connected to the
pin RA0 of PORTA of the PIC. From datasheet of PIC 18F4550, PORTA is one of
the port that can be used to convert analog signal to digital signal. The code in the
programming will define the RA0 pin as analog signal which will be converted into
digital and take PORTD of the PIC to be the output.
24
The LCD which can read the digital signal should display it in the form of a
wave. The reason for taking PORTD of the PIC as the output is because SK40C is
used in this project where the circuit embedded had already made the connection
between PORTD of PIC and the PORTD of the LCD.
The formula used for the heartbeat calculation is
() (
( )
)(). The R to R peak interval of the ECG waveform
is defined in the microcontroller coding as the digital value of most significant figure
in the binary number of the output in PORTD of the PIC.
However, this project is not successful in displaying the waveform of the ECG
on the LCD screen just like when using the oscilloscope. The accuracy of the
waveform peak seems to be far away then the real waveform as the LCD scaling is
rather too small compared to the oscilloscope.
4.5 Alarm System
For the alarm system, a buzzer will produce a beeping sound. The alarm starts
beeping as the abnormal heart rate is detected so that the user can be alerted when he
or she need to record the ECG waveform.
4.6 Waveform Recording
The data of the ECG waveform then should be recorded. For this purpose, SD
card was used as it simply record what it is supposed to in any form that we want.
The SD card was connected to the digital output of the PIC which is the same input
pins of the GLCD. The programming for saving the data into the SD memory card
25
was written in the coding of PIC microcontroller. But, when the full circuit was
tested in order to check whether the data can be successfully recorded or not, the
memory card seems to reject the data transfer as there is no data saved when checked
on the computer. This is possibly caused by the improper connection of the SD card
with the PIC PORT.
CHAPTER 5
CONCLUSION
5.1 Introduction
This chapter will cover on the conclusion of the whole project whether the
objective of this project had been achieved or not. Some recommendation for the
future work is also included in this chapter.
5.2 Conclusion
An ECG circuit had been successfully built where it show the real time ECG
waveform of the user. From the ECG waveform, the heartbeat of the user was
calculated and shown on the LCD display. The process of saving ECG waveform
data using the SD memory card is the correct way in handling digital data but it was
not successful. The interface between the output memory of the LCD and the
memory card may not be correct. The soldering of the ECG circuit does not affect
27
much in the process of saving data. This is because the soldered ECG circuit had
been tested separately with the ECG simulator and the results of the ECG waveform
were satisfying when compared with the KL-75001 ECG module provided by the
Medical Laboratory. Thus, the connection between the SD card and the PIC 18F4550
was suspected as the cause of the problem in saving the ECG data. In order to
overcome this problem, it is recommended to use better interface for the SD card.
5.3 Recommendation
For a better future related work, there are some recommendations that can be
made to improve the project. First, the display of ECG waveform on the LCD display
should have a scale so that the clinician can used the data saved as one of the main
reference when diagnosing the patients health.
Besides, the memory size of the SD memory card should be sufficient for
recording the ECG waveform more than once. 8 GigaBytes of memory card that was
used in this project is recommended for future use, but the alert system for informing
the user if the data is already full should be made.
28
APPENDIX A
//PIC coding for heartbeat calculation, analog to digital converter,
//and saving data in SD card
//input built-in SK40C
#define SW1 PORTB.F0
#define SW2 PORTB.F1
//output built-in SK40C
//LED
#define LED1 PORTB.F6
#define LED2 PORTB.F7
// glcd pinout settings
char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at RB0_bit;
sbit GLCD_CS2 at RB1_bit;
sbit GLCD_RS at RB2_bit;
sbit GLCD_RW at RB3_bit;
sbit GLCD_EN at RB4_bit;
sbit GLCD_RST at RB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction at TRISB2_bit;
sbit GLCD_RW_Direction at TRISB3_bit;
29
sbit GLCD_EN_Direction at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
// SD Memory card module connections
sbit Mmc_Chip_Select at LATC0_bit; // for writing to output pin always use latch
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
//define characters used in the programming
unsigned int temp_res;
char i = 1;
unsigned int RtoRinterval;
char j = 60;
char txt1[] = "";
char stringData[512] = "";
unsigned long k, size, m = 0;
char Buffer[512] = "";
char CSD[16] = "";
char CID[16] = "";
void init(void)
{
ADCON0 = 0;
ADCON1 = 0x0f; // ADC - set portB ANx pins to digital i/o
CMCON = 0x07; // Comparators "off"
CCP1CON = 0;
CCP2CON = 0;
SSPCON1 = 0;
}
30
// Write string with soft uart
void writeString(char stringData[])
{
// Get string length
m = strlen(stringData);
for(k = 0; k<m; k++)
{
Soft_UART_Write(stringData[k]);
}
Soft_UART_Write(0x0D);
Soft_UART_Write(0x0A);
}
void main(){ //18F4550
init();
Glcd_Init(); // Initialize GLCD
Glcd_Fill(0x00); // Clear GLCD
// Initialize UART1 module
UART1_Init(19200);
TRISB.B7 = 1;
31
TRISB.B6 = 0;
TRISC.B0 = 0;
TRISB.B0 = 1;
TRISB.B1 = 0;
TRISC.B7 = 0;
Soft_UART_Init(&PORTB, 6, 7, 19200, 0);
Delay_ms(10);
// Initialize SPI1 module
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64,
_SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
writeString("SPI started, low speed mode");
m = Mmc_Init();
if(m == 0)
{
writeString("Mmc_Init terminated successfully (0)");
}
else
{
writeString("Mmc_Init() terminated unsuccessfully (not 0)");
}
// reinitialize spi at higher speed
32
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4,
_SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
writeString("SPI re-initialized into high speed mode. ");
m = Mmc_Read_Cid(CID);
if(m == 0)
{
writeString("Mmc_Read_Cid terminated successfully (0):");
writeString(CID);
}
else
{
writeString("Mmc_Read_Cid terminated unsuccessfully (not 0)");
}
m = Mmc_Read_Csd(CSD);
if(m == 0)
{
writeString("Mmc_Read_Csd terminated successfully (0):");
writeString(CSD);
}
else
{
writeString("Mmc_Read_Csd terminated unsuccessfully (not 0)");
}
33
writeString("Read sector address 5859375 to prove that it toggled upon toggling of
_MCLR:");
Mmc_Read_Sector(5859375, Buffer);
writeString(Buffer);
writeString("Dumping boot sector and first file structure sector (0, 1)");
Mmc_Read_Sector(0, Buffer);
writeString(Buffer);
Mmc_Read_Sector(1, Buffer);
writeString(Buffer);
Delay_ms(100); // Make a break in hex stream
writeString("End of dumping file information sector.");
writeString("Writing message to sector...(toggle _MCLR to see message change)");
writeString("");
Mmc_Read_Sector(5859375, Buffer);
Mmc_Write_Sector(5859375, "The End!");
34
if(Buffer[0] == 71)
{
Mmc_Write_Sector(5859375, "Start!");
}
TRISA = 0xFF; // PORTA is input
TRISD = 0; // PORTD is output
TRISC=0; // PORTC is output
do
{
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
PORTD = temp_res; // Send 8 bits to PORTD
PORTC = temp_res >> 7; // Send 1 most significant bits to RC1
RtoRinterval = temp_res>> 7;
i = i * temp_res /j; // (1 * R-R interval)/60 = BPM;
FloatToStr(i, txt1); // char --> string array
Glcd_Fill(0);// Clear screen
Glcd_Write_Text("Your heart beat is:", 0, 0,3);
Delay_ms(2);
Glcd_Write_Text(txt1, 10, 2, 1);
}
while(1) ;
}
35
APPENDIX B
PIC 18F4550 pin I/O description
REFERENCES
36
37
38
39
40
APPENDIX C
Graphic LCD pin description
41
REFERENCES
1. Joseph J.C and John M.B (2001). Electrocardiographs. Stephen Helba (Ed).
Introduction to Biomedical Equipment Technology (4
th
Edition). (pg 197-198). Upper
Saddle River, New Jersey: Prentice Hall.
2. Neil Townsend Michaelmas (2001). C3B Medical Electronics - ECG
Instrumentation. [Online]. Available:
http://www.robots.ox.ac.uk/~neil/teaching/lectures/med_elec/
3. Colin Tidy (11
th
October 2012). Electrocardiogram (ECG). [Online]. Available:
http://www.patient.co.uk/health/electrocardiogram-ecg
4. Soumyan Ranjan Mishra & K.Goutham (2009-2010). Realtime Classification of
ECG Waveforms for Diagnosis of Diseases. (pg 5). National Institute of Technology
Rourkela.
5. Nur Sabrina Binti Risman (2011-2012). Design an Alarm System Using
Electrocardiography (ECG). (pg 12). Universiti Teknologi Malaysia.
6. American Heart Association. Heart and Stoke Encyclopedia. [Online]. Available:
http://www.heart.org/HEARTORG/Encyclopedia/Heart-
Encyclopedia_UCM_445084_Encyclopedia.jsp
7. Yeong Che Fai & Eileen Su Lee Ming. PIC Microcontroller Hands-on.
8. Microchip Technology Inc (2001). PIC 18F4550 Datasheet.
9. Sadik Kara, Semra Kemaloglu & Samil Kirbas (2006). Low Cost Compact ECG
With Graphic LCD and Phonocardiogram System Design (Research). Erciyes
University.
10. Tinsharp. G12864E Graphic LCD Datasheet.
11. Steve Collins & Jullian Silva (1998). Flash Memory (Flash RAM) (pg1-10).