Sie sind auf Seite 1von 73

REAL TIME ECG & BODY TEMPERATURE MONITORING DEVICE

MINI PROJECT REPORT


Submitted by DILEEP DINESH ELDHO JOSE LADVINE D ALMEIDA NIDHISH ROY

VIVEK K HARIDAS

In partial fulfillment for the award of degree of BACHELOR OF TECHNOLOGY IN ELECTRONICS AND BIOMEDICAL ENGINEERING

MODEL ENGINEERING COLLEGE Thrikkakara Cochin University of Science and Technology

GOVERNMENT MODEL ENGINEERING COLLEGE THRIKKAKARA KOCHI

DEPARTMENT OF ELECTRONICS AND BIOMEDICAL ENGINEERING Cochin University of Science and Technology

BONAFIDE CERTIFICATE This is to certify that the Mini Project entitled

. Submitted by is a bonafide work done by him/her under our supervision

Dr.Jessy John

Mrs.Vijayalakshmi k

Ms.Nisha Krishnan

HEAD OF THE DEPARTMENT

CO-ORDINATOR

GUIDE

ACKNOWLEDGEMENT

At this moment of accomplishment, we are presenting our work with great pride and pleasure, we would like to express our sincere gratitude to all those who helped us in the successful completion of our venture. First of all, we would like to thank our Principal Prof. Dr.TK MANI who provided us with all facilities and amenities for the development of our project. We would like to thank Dr. Jessy John, Head of Department of Electronics and Biomedical Engineering for helping us in the successful accomplishment of our project. We are exceedingly grateful to our project coordinator, Mrs. Vijayalakshmi K, Asst. Professor, Dept. of Electronics and Biomedical Engineering for her timely and valuable suggestions. We would also like to thank our project guide Ms. Nisha Krishnan, Faculty staff who gave us constant guidance and support throughout this journey of turbulence.

We also sincerely thank Mrs. Bella, Medical electronics lab-in-charge and Mrs. Geethu and Mrs.Vidhya, Lab Technicians, Department of Electronics and Biomedical for their constant support and encouragement for our project. Above all we thank God almighty for constantly motivating us with His love, and giving us courage at each stride to step forward with confidence and self belief.

ABSTRACT

Our project aims at ECG Acquisition and temperature monitoring in medical field.

An ECG is a test that records the activity of the heart over time. Each portion of the ECG waveform can hint whether the patient is in good health or else. ECG signal are usually very small(approximately1mV) and therefore prone to interferences The problem within the ECG among the existing processes for patients ECG monitoring requires a great deal of effort to collect and analyze information introducing a latency that prevents real-time analysis and use by a common person.

We propose a solution to automate this process by acquiring the ECG and temperature, analyzing the information based on PR, QRS,ST intervals and amplitude and providing different information to person based on it such as health status, measurements etc. on a LCD screen.

The device is aimed at a common person to get current heart condition and temperature .Moreover, the device is portable.

II

TABLE OF CONTENTS

SL NO

TOPIC

PAGE NO

1. 2.

INTRODUCTION LITERATURE REVIEW RELATEDTHEORIES 3.1 3.2 3.3 3.4 CARDIAC CONDUCTION PROCESS ECG WAVEFORM ECG LEADS

1 2

3.

3 4 5 6 7 8 9

3.4.1 ECG STANDARD LIMB LEADS 3.4.2 EINTHOVANS TRIANGLE 3.5 CARDIAC ARRHYTHMIAS 3.6 DURATION AND DISEASES ASSOCIATED WITH ECG 3.7 BODY TEMPERATURE 4. DESIGN OF THE WORK 4.1 BLOCK DIAGRAM OF CIRCUIT 4.2 BLOCK LEVEL TREATMENT

10 11

12 13

III

4.2.1 ECG ACQUISITION BLOCK 4.2.2 TEMPERATURE SENSING 4.3 CIRCUIT LEVEL DESCRIPTION 4.3.1 INSTRUMENTATION AMPLIFIER 4.3.2 4.3.3 4.3.4 4.3.5 4.4 5. LOW PASS FILTER HIGH PASS FILTER RL DRIVE CIRCUIT MICROCONTROLLER

13 13

14 17 18 20 20 22

FLOWCHARTS AND CIRCUITS

IMPLEMENTATION 5.1 SYSTEM REQUIREMENTS 5.2 HARDWARE REQUIREMENTS 5.3 SOFTWARE REQUIREMENTS 5.4 FULL CIRCUIT DIAGRAM 26 26 26 27 28 29 PROGRAMS 30 53 DATA SHEETS
III

6. 7.

RESULT AND CONCLUSION FUTURE WORKS APPENDIX A REFERENCES APPENDIX B

54

LIST OF FIGURES

SL NO:

TOPIC

PAGE NO

Fig 3.1 Fig 3.2

ECG Waveform ECG Waveform Showing Various Segments

Fig 3.3

Waveform Of Standard Limb Leads 7 7

Fig3.4

Standard Limb Leads Of ECG

Fig 3.5 Fig 4.1 Fig 4.2 Fig 4.3 Fig 4.4 Fig 4.5 Fig 4.6 Fig 4.7

Einthovens Triangle Full Block Diagram ECG Acquisition Block Temperature Sensing Block ECG Acquisition Block Instrumentation Amplifier Graphics LCD Circuit Temperature Sensing Circuit
III

8 12 13 13 14 15 23 25

LIST OF ABBREVATIONS
ECG- Electrocardiogram Rl-Right Leg LCD- Liquid Crystal Display GLCD- Graphical Liquid Crystal Display

III

CHAPTER 1

Introduction
An ECG (electrocardiogram) is a test that measures the electrical activity of the heart. The heart is a muscular organ that beats in rhythm to pump the blood through the body. The signals that make the heart's muscle fibers contract come from the Sino atrial node, which is the natural pacemaker of the heart. In an ECG test, the electrical impulses made while the heart is beating are recorded and usually shown on a piece of paper. This is known as an electrocardiogram, and records any problems with the heart's rhythm, and the conduction of the heart beat through the heart which may be affected by underlying heart disease.ECG signals are usually small, approximately 1mV and therefore, it is prone to corruption by various noises; power line interference, electrode contact noise, motion artifacts. Also, it is necessary to design a good filter system that can filter out the noises from the ECG signal in order to get better result. Therefore, measuring an ECG signal is not an easy task to achieve. The ECG signals are captured by the electrode sensors, and then it is amplified by the instrumentation amplifier and precision amplifier. The gain achieved by cascading the amplifiers must be equal or greater than1000 in order to achieve the desired signal output. However, the noises may still interfere with the signal. Therefore, it is necessary to design a band-pass filter (BPF) circuit where the low-pass circuit (LPF) will eliminate the high-frequency noises and the high-pass circuit (HPF) will eliminate the direct current (DC) noise components. An operational amplifier will be used to invert the common noise voltage and drive it back to the right leg of the patient which is considered the ground, in order to cancel the interference.

CHAPTER 2

Literature Review
Initial research was conducted to determine the types of vital signs of heart and arrhythmias and also body temperature that are routinely measured during a visit to a doctor. As part of the project, it is necessary to find, design and build suitable electrodes and temperature sensors. Then, the market demand for this type of device was determined and research on similar monitoring devices that are currently sold was performed. Major disadvantages with these devices are that they are not very easy to use, somewhat intrusive, and, of course, very expensive. The main problem facing on GLCD plotting and analysis ECG signal without MAT lab. To measure the electrocardiogram (ECG), this project uses three Unipolar leads, placed in Einthovens triangle configuration. Lead I, Lead II, and Lead III are used. This method works accurately for the scope of this project as it is geared towards older individuals who are less active. Next, different types of temperature sensors were compared. It was determined that the most effective way of measuring body temperature is by using a LM35. The advantages and disadvantages of the temperature sensor is provided in block level description of temperature sensing circuit.

CHAPTER 3

Related Theories
The heart is a four-chambered organ consisting of right and left halves. Two of

the chambers, the left and right atria, are entry-points into the heart, while the other two chambers, the left and right ventricles, are responsible for contractions that send the blood through the circulation. The circulation is split into the pulmonary and systemic circulation. The role of the right ventricle is to pump

deoxygenated blood to the lungs through the pulmonary trunk and pulmonary arteries. The role of the left ventricle is to pump newly oxygenated blood to the body through the aorta. 3.1 Four Steps Of Cardiac Conduction: Step 1: Pacemaker Impulse Generation: The sinoatrial (SA) node (also referred to as the pacemaker of the heart) contracts generating nerve impulses that travel throughout the heart wall. This causes both atria to contract. The SA node is located in the upper wall of the right atrium. It is composed of nodal tissue that has characteristics of both muscle and nervous tissue. Step 2: AV node Impulse Conduction: The atrioventricular (AV) node lies on the right side of the partition that divides the atria, near the bottom of the right atrium. When the impulses from the SA node reach the AV node they are delayed for about a tenth of a second. This delay allows the atria to contract and empty their contents first. Step 3: AV Bundle Impulse Conduction: The impulses are then sent down the atrioventricular bundle. This bundle of fibres branches off into two bundles and the impulses are carried down the centre of the heart to the left and right ventricles. Step 4: Purkinje fibres impulse conduction: At the base of the heart the atrioventricular bundles starts to divide further into purkinje fibers. When the impulse reaches these fibers they trigger the muscle fibers in the ventricles to contract.
3

3.2 ECG The electrocardiogram (ECG) is a diagnostic tool that measures and records the electrical activity of the heart in detail. Being able to interpretate these details allows diagnosis of a wide range of heart problems. The ECG records the electrical activity and depicts it as a series of graph-like tracings, or waves. The shapes and frequencies of these tracings reveal abnormalities in the heart's anatomy or function.

Fig 3.1 ECG waveform The EKG can provide important information about the patient's heart rhythm, a previous heart attack, increased thickness of heart muscle, signs of decreased oxygen delivery to the heart, and problems with conduction of the electrical current from one portion of the heart to another. There are no risks. No electricity is sent through the body, so there is no risk of shock. The accuracy of the ECG depends on the condition being tested. A heart problem may not always show up on the ECG. Some heart conditions never produce any specific ECG changes.

3.3 Waveforms: The ECG records the electrical activity that results when the heart muscle cells in the atria and ventricles contract. Atrial contractions show up as the P wave. Ventricular contractions show as a series known as the QRS complex. The third and last common wave in an ECG is the T wave. This is the electrical activity produced when the ventricles are recharging for the next contraction (repolarizing). Interestingly, the letters P, Q, R, S, and T are not abbreviations for any actual words but were chosen many years ago for their position in the middle of the alphabet. The electrical activity results in P, QRS, and T waves that are of different sizes and shapes. When viewed from different leads, these waves can show a wide range of abnormalities of both the electrical conduction system and the muscle tissue of the hearts 4 pumping chambers.

Fig 3.2 ECG waveform showing various segments P Wave: represents atrial depolarization -the time necessary for an electrical impulse from the sinoatrial (SA) node to spread throughout the atrial musculature. Under normal conditions, electrical activity is spontaneously generated by the SA node, the physiological pacemaker. This electrical impulse is propagated throughout the
5

right atrium, and through Bachmann's bundle to the left atrium, stimulating the myocardium of both atria to contract. The conduction of the electrical impulse throughout the left and right atria is seen on the ECG as the P wave. Location: Precedes QRS complex. Amplitude: Should not exceed 2 to 2.5 mm in height. Duration: 0.06 to 0.11 seconds.

P-R Interval: represents the time it takes an impulse to travel from the atria through the

AV node, bundle of His, and bundle branches to the Purkinje fibres. Location: Extends from the beginning of the P wave to the beginning of the QRS complex. Duration: 0.12 to 0.20 seconds.

QRS Complex: represents ventricular depolarisation. The QRS complex consists of 3

waves: the Q wave, the R wave, and the S wave. The Q wave is always located at the beginning of the QRS complex. It may or may not always be present. The R wave is always the first positive deflection. The S wave, the negative deflection, follows the R wave 2.

Amplitude: Normal values vary with age and sex Duration: No longer than 0.10 seconds
Q-T Interval: represents the time necessary for ventricular depolarization and

repolarisation. Location: Extends from the beginning of the QRS complex to the end of the T wave (includes the QRS complex, S-T segment, and the T wave)

Duration: Varies according to age, sex, and heart rate. T Wave: represents the repolarisation of the ventricles. On rare occasions, a U wave can be seen following the T wave. The U wave reflects the repolarisation of the His-Purkinje fibres. Location: Follows the S wave and the S-T segment. 3.4 ECG leads: The three types of ECG leads are :
6

Limb Leads (Bipolar) Augmented Limb Leads (Unipolar) Chest Leads (Unipolar)

Some of the ECG leads are bipolar leads(e.g., standard limb leads) that utilize a single positive and a single negative electrode between which electrical potentials are measured. Unipolar leads (augmented leads and chest leads) have a single positive recording electrode and utilize a combination of the other electrodes to serve as a composite negative electrode. Normally, when an ECG is recorded, all leads are recorded simultaneously, giving rise to what is called a 12-lead ECG.

Fig 3.3 waveform of standard limb leads 3.4.1 Electrocardiogram Standard Limb Leads (Bipolar): There are three of these leads, I, II and III.
Lead I: is between the right arm and left arm electrodes, the left arm being positive. Lead II: is between the right arm and left leg electrodes, the left leg being positive. Lead III: is between the left arm and left leg electrodes, the left leg again being positive.

Fig 3.4 standard limb leads of ECG


7

Lead I has the positive electrode on the left arm, and the negative electrode on the right arm, and therefore measures the potential difference between the two arms. In this and the other two limb leads, an electrode on the right leg serves as a reference electrode for recording purposes. Lead II configuration, the positive electrode is on the left leg and the negative electrode is on the right arm. Lead III has the positive electrode on the left leg and the negative electrode on the left arm. These three bipolar limb leads roughly form an equilateral triangle (with the heart at the centre) that is called Einthoven's triangle in honour of Willem Einthoven who developed the electrocardiogram in 1901. Whether the limb leads are attached to the end of the limb (wrists and ankles) or at the origin of the limb (shoulder or upper thigh) makes no difference in the recording because the limb can simply be viewed as a long wire conductor originating from a point on the trunk of the body. 3.4.2Einthovans Triangle

Fig 3.5 Einthoven triangle

An equilateral triangle whose vertices lie at the left and right shoulders and the pubic region and whose center corresponds to the vector sum of all electric activity occurring in the heart at any given moment, allowing for the determination of the electrical axis. Einthoven's triangle is approximated by the triangle formed by the axes of the bipolar electrocardiographic (ECG) limb leads I, II, and III. The centre of the triangle offers a reference point for the Unipolar ECG leads. 3.5 Cardiac Arrhythmias: Arrhythmia is a irregular rhythm of heart. Bradycardia: A slow rhythm, (less than 60 beats/min), is labelled Bradycardia. This may be caused by a slowed signal from the sinus node (termed sinus Bradycardia), a pause in the normal activity of the sinus node (termed sinus arrest), or by blocking of the electrical impulse on its way from the atria to the ventricles (termed AV block or heart block). Heart block comes in varying degrees and severity. It may be caused by reversible poisoning of the AV node (with drugs that impair conduction) or by irreversible damage to the node. Bradycardias may also be present in the normally functioning heart of endurance athletes or other well-conditioned persons. Tachycardia: In adults and children over 15, resting heart rate faster than 100 beats/minute is labelled tachycardia. Tachycardia may result in palpitation, however, tachycardia is not necessarily an arrhythmia. Increased heart rate is a normal response to physical exercise or emotional stress. This is mediated by the sympathetic nervous system on the sinus node, and is called sinus tachycardia. Other things that increase sympathetic nervous system activity in the heart include ingested or injected substances such as caffeine or amphetamines, and an overactive thyroid gland (hyperthyroidism). Tachycardia that is not sinus tachycardia usually results from the addition of abnormal impulses to the normal cardiac cycle. Abnormal impulses can begin by one of three mechanisms: automaticity, re-entry or triggered activity. A specialised form of reentry problem is termed fibrillation.

3.6 Duration And Diseases Associated With Ecg PR Interval (Measured from beginning of P to beginning of QRS in the frontal plane) Normal: 0.12 - 0.20s Short PR: < 0.12s Preexcitation syndromes: WPW (Wolff-Parkinson-White) Syndrome: An accessory pathway (called the "Kent" bundle) connects the right atrium to the right ventricle (see diagram below) LGL (Lown-Ganong-Levine): An AV nodal bypass track into the His bundle exists, and this permits early activation of the ventricles without a delta-wave because the ventricular activation sequence is normal. Prolonged PR: >0.20s First degree AV block (PR interval usually constant) Intra-atrial conduction delay (uncommon) Slowed conduction in AV node (most common site) Slowed conduction in His bundle (rare) Slowed conduction in bundle branch (when contra lateral bundle is blocked)

Second degree AV block (PR interval may be normal or prolonged; some P waves do not conduct) Type I (Wenckebach): Increasing PR until nonconductor P wave occurs Type II (Mobitz): Fixed PR intervals plus nonconductor P waves

AV dissociation: Some PR's may appear prolonged, but the P waves and QRS complexes are dissociated (i.e., not married, but strangers passing in the night).

QRS Duration (Duration of QRS complex in frontal plane): Normal: 0.06 - 0.10s Prolonged QRS Duration (>0.10s):
10

QRS duration 0.10 - 0.12s Incomplete right or left bundle branch block Nonspecific intraventricular conduction delay (IVCD) Some cases of left anterior or posterior fascicular block Complete RBBB or LBBB Nonspecific IVCD Ectopic rhythms originating in the ventricles (e.g., ventricular tachycardia, pacemaker rhythm)

QRS duration > 0.12s

QT Interval (Measured from beginning of QRS to end of T wave in the frontal plane) Normal: heart rate dependent Long QT Syndrome - "LQTS" (based on upper limits for heart rate; QT> 0.47 sec for males and > 0.48 sec in females.

3.8 Body Temperature


Different

parts

of

the

body

have

different

body

temperatures.

Rectal and vaginal measurements, or measurements taken directly inside the body cavity, are typically slightly higher than oral measurements, and oral measurements are somewhat higher than skin temperature. The commonly accepted average core body temperature (taken internally) is 37.5 C (99.5 F). The typical oral (under the tongue) measurement is slightly cooler, at 36.8 0.4C (98.2 0.7F), Although some people think of these numbers as representing the normal temperature, a wide range of temperatures has been found in healthy people. The normal human body temperature can fluctuate about one degree (F) throughout the day, with lower temperatures in the morning and higher temperatures in the late afternoon and evening. The accepted range of "normal" temperature is from 97F (36.1C) to 99F (37.2C).

11

CHAPTER 4

Design Of The Work


4.1 Block Diagram Of Circuit
It consists of mainly two blocks: ECG acquisition block &

temperature sensing block.


ECG ACQUISITION BLOCK

GLCD

TEMPERATURE SENSING BLOCK Fig 4.1Block diagram


12

4.2 Block Level Treatment 4.2.1 ECG Acquisition Block

Fig 4.2 ECG acquisition block This stage is used to acquire the ECG signal from the body using electrodes. It consist of an instrumentation amplifier stage used to provide an initial gain to the signal & is made using IC LM324. it is followed by a band pass filter which is used to remove 50hz power line interference & other unwanted noise from the signal. This stage is followed by a differential amplifier stage made from IC LM324 which provides the final amplification required for the signal. This signal is given to PIC & is then displayed using a graphical display. 4.2.2 Temperature Sensing Block

Fig 4.3Temperature sensing block The LM35 series are precision integrated-circuit temperature sensors, whose
output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus

has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient
13

Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of C at room temperature and C over a full -55 to +150C temperature range. Low cost is assured by trimming and calibration at the wafer level. The LM35's low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 A from its supply, it has very low self-heating, less than 0.1C in still air. The LM35 is rated to operate over a -55 to +150C temperature range, while the LM35C is rated for a -40 to +110C range (-10 with improved accuracy). The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface mount small outline package and a plastic TO-220 package. 4.3 Circuit Level Description

Fig 4.4 ECG acquisition circuit 4.3.1 Instrumentation Amplifier As suggested before, it is beneficial to be able to adjust the gain of the amplifier circuit without having to change more than one resistor value, as is necessary with the previous
design of differential amplifier. The so-

14

called instrumentation builds on the last version of differential amplifier to give us that capability:

Fig 4.5 Instrumentation amplifier This intimidating circuit is constructed from a buffered differential amplifier stage with three new resistors linking the two buffer circuits together. Consider all resistors to be of equal value except for Rgain. The negative feedback of the upper-left op-amp causes the voltage at point 1 (top of Rgain) to be equal to V1. Likewise, the voltage at point 2 (bottom of Rgain) is held to a value equal to V2. This establishes a voltage drop across Rgain equal to the voltage difference between V1 and V2. That voltage drop causes a current through Rgain, and since the feedback loops of the two input op-amps draw no current, that same amount of current through Rgain must be going through the two "R" resistors above and below it. This produces a voltage drop between points 3 and 4 equal to:

15

The regular differential amplifier on the right-hand side of the circuit then takes this voltage drop between points 3 and 4, and amplifies it by a gain of 1 (assuming again that all "R" resistors are of equal value). Though this looks like a cumbersome way to build a differential amplifier, it has the distinct advantages of possessing extremely high input impedances on the V1 and V2 inputs (because they connect straight into the noninverting inputs of their respective op-amps), and adjustable gain that can be set by a single resistor. Manipulating the above formula a bit, we have a general expression for overall voltage gain in the instrumentation amplifier: (4.2) Though it may not be obvious by looking at the schematic, we can change the differential gain of the instrumentation amplifier simply by changing the value of one resistor: Rgain. Yes, we could still change the overall gain by changing the values of some of the other resistors, but this would necessitate balanced resistor value changes for the circuit to remain symmetrical. Please note that the lowest gain possible with the above circuit is obtained with Rgain completely open (infinite resistance), and that gain value is 1.Now use instrumentation amplifier with LM324.the advantage is that working on single supply such as 5V. Design Instrumentation Amplifier Stage Total Gain= 110 Gain of first stage, A1= 11 Gain of second stage, A2= 10 Atotal= (1+2R4/R5)(-Rf/R1) Let R4= 100k therefore R5= 20k Let R1= 100k we get Rf= 1M

16

4.3.1. a Features of Lm324 LM324 is a low power quad operational amplifier, it has these features: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Internally frequency compensated for unity gain Large DC voltage gain 100 dB Wide bandwidth (unity gain) 1 MHz (temperature compensated) Wide power supply range: Single supply 3V to 32V . Very low supply current drain (700 A)-essentially independent of supply voltage Low input biasing current 45 nA (temperature compensated) Low input offset voltage 2 mV and offset current: 5 nA Input common-mode voltage range includes ground Differential input voltage range equal to the power supply voltage Large output voltage swing 0V to V+ 1.5) A low pass filter is an electronic circuit that passes low frequency signals but attenuates (reduces the amplitude of) signals with frequencies higher than

4.3.2 Lowpass Filter

the cutoff frequency. The actual amount of attenuation for each frequency varies from filter to filter. It is sometimes called a high-cut filter, or treble cut filter when used in audio applications. Normally we using second order low pass filter for eliminating noise from the ECG signal. second order Butterworth design follows the circuit design. As with low-pass filters, high-pass filters have a rated cutoff frequency, above which the output voltage increases above 70.7% of the input voltage. Just as in the case of the capacitive low-pass filter circuit, the capacitive high-pass filter's cutoff frequency can be foun the same formula. with

fcut off = 1/2 RC


Design SECOND ORDER LOW PASS FILTER\ 1) F= 1/(2RC) Let f= 25 HZ, C= 0.1 F
17

(4.3)

R=1/(2fC)= 1(2*3.14*25*0.1*10 )= 63.69k= 68k Let gain= 2 1+Rf/R1= 2 Rf/R1= 1 Let Rf= R1= 100k Therefore cut off frequency become 23.4 HZ 2) F= 1/(2RC)

-6

Let f= 25 HZ, C= 1 F R=1/(2fC)= 1(2*3.14*25*1*10 )= 6.3 k==6.8 k AMPLIFIER Rf/R1= 10 Let R1= 100k Rf= 1M 4.3.3 High Pass Filter The High Pass Filter is the exact opposite to the low pass filter. This filter has no output voltage from DC (0Hz), up to a specified cut-off frequency (c) point. This lower cut-off frequency point is 70.7% or -3dB (dB = -20log Vout/Vin) of the voltage gain allowed to pass. The frequency range "below" this cut-off point is generally known as the Stop Band while the frequency range "above" this cut-off point is generally known as the Pass Band. The cut-off frequency or -3dB point, can be found using the formula, c = 1/(2RC). The phase angle of the output signal at c is +45 . Generally, the high pass filter is less distorting than its equivalent low pass filter. Here using second order highpass filter with LM358.Because of the better operating capabilities of IC and elimination of DC drift from ECG signal due to noise, motion artifacts etc.
o -6

18

Design SECOND ORDER HIGH PASS FILTER F= 1/2 (R2R3C2C3) Let C2= C3= 47F F= .5 HZ R2= R3= R 0.5= *3.14*(R *(47*10 ) ) R= 6.761 k= 6.8k Features Of Lm358 LM358 is a low power dual operational amplifier, it has 12 features as: Available in 8-Bump micro SMD chip sized package, (See AN-1112) Internally frequency compensated for unity gain Large dc voltage gain: 100 dB Wide bandwidth (unity gain): 1 MHz (temperature compensated) Wide power supply range: Single supply: 3V to 32V or dual supplies: 1.5V to 16V Very low supply current drain (500 A)-essentially independent of supply voltage Low input offset voltage: 2 mV Input common-mode voltage range includes ground Differential input voltage range equal to the power supply voltage Large output voltage swing
2 -6 2 1/2 1/2

19

4.3.4 RL Drive Circuit A Driven Right Leg Circuit or DRL circuit is an electric circuit that is often added to biological signal amplifiers to reduce Common noise. Biological signal amplifiers such as EKG (Electrocardiogram) EEG (Electroencephalogram) or EMG circuits measure very small electrical signals emitted by the body, often as small as several micro-volts (millionths of a volt). Unfortunately, the patient's body can also act as an antenna which picks up electromagnetic interference, especially 50/60 Hz noise from electrical power lines. This interference can obscure the biological signals, making them very hard to measure. Right Leg Driver circuitry is used to eliminate interference noise by actively canceling the interference. Electrocardiography (ECG) is the science of converting the ionic depolarization of the heart to a measurable electrical signal for analysis. One of the most common challenges in the design of the analog electronics interface to the electrodes/patient is in the optimization of the right leg drive (RLD) for common mode performance and stability. 4.3.5 Microcontroller Microcontroller are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, toys and other embedded systems. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems. Mostly using microcontroller for interfacing signal to display system by PIC. 4.3.5. a Features High performance RISC CPU Only 35 single word instructions to learn All single cycle instructions except for program branches which are two cycle Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle

20

Up to 8K x 14 words of FLASH Program Memory, Up to 368 x 8 bytes of Data

Memory (RAM),Up to 256 x 8 bytes of EEPROM Data Memory Peripheral Features: Timer0: 8-bit timer/counter with 8-bit prescaler Timer1: 16-bit timer/counter with prescaler can be incremented during SLEEP via external crystal/clock. Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler Two Capture, Compare, PWM modules - Capture is 16-bit, max. resolution is 12.5 ns - Compare is 16-bit, max. resolution is 200 ns - PWM max. Resolution is 10-bit Timer Features: 8-bit timer/counter Readable and writable 8-bit software programmable prescaler Internal or external clock select Interrupt on overflow from FFh to 00h Edge select for external clock The PIC architectures have these advantages:

Small instruction set to learn RISC architecture Built in oscillator with selectable speeds Easy entry level, in circuit programming plus in circuit debugging PIC it units available from Microchip.com for less than $50 Inexpensive microcontrollers
range of interfaces including IC, SPI, USB, USART, A/D, programmable

Wide

comparators, PWM, LIN, CAN, PSP, and Ethernet

21

4.4 Flow Chart Of Graphical Display


start

Graphical lcd either writes or erases the point from the screen and thereby plotting the points

PIC acquires the analog values (ECG) and converts them into digital values.

If x COR > 63 chip 2 is selected using chip select, else chip 1 is selected.

Y COR is divided into 8 pages of 1 bytes each. Command words are produced by performing operations of b=y/8 & d=y%8.

Reading and writing is done through separate functions implemented in the program.

Writing is done by reading the present data, writing the new data is done by ORing with the previous data

Erasing is performed by providing a zero instead of one. The whole ECG is displayed real time.

22

4.5 Graphical LCD: Character based LCDs are great for presenting the user with textual information. However there are times you need a bit morefreedom when presenting data. In this application note I will presenta interface between the Dios chips and a Crystal fonts 128x64Graphic LCD.

Fig 4.6 Graphical LCD connection


23

4.6 Flow chart of temperature sensing:


start

LM35 acquires Body temperature and provides precision output volts

PIC accepts this volts in RA0/AN0 and provides ASCII out BODY TEMP=

Code pattern from PIC (1) is analyzed and given displayed as arrhythmia and heart block.

The next page wil display RISK LEVEL=

24

Fig 4.7 Temperature sensing circuit


This circuit uses LM35 to detect the body temperature. This is then displayed on

the LCD display through PIC.

25

CHAPTER 5

Implementation
5.1 System Requirements: 3 disposable surface electrodes It is battery powered

Switches are provided for changing the lcd display 5.2 Hardware Requirements: Supply is provided by 9v battery. Lead wire should be insulated. Filters are provided for removing the artefacts. Floating ground is provided to remove baseline wandering. Power supply is also regulated to 5v using 7805 so as to provide it for PIC & display system 2 PICs are used. PIC 1 contains the program for ECG display & also contains arrhythmia detection logic. ECG display program is used to plot real time ECG signal on GLCD. Arrhythmia detection logic uses timer to calculate the time period of R-R interval & QRS complex which is used to detect arrhythmia & syndrome related to variation in QRS complex respectively. LM 35 measure voltage corresponding to the body temperature which is send to PIC 2 where it converts this voltage signals to corresponding readings in degree Celsius.

5.3 Software Requirements:

26

27

CHAPTER 6

Results & Conclusion


In short, we were successfully able acquire ECG signal and display the body temperature. ECG signal was displayed using graphical LCD and body temperature was displayed using another alpha numeric LCD display. In short, our solution delivers an integrated Device that automates the process from data collecting (EKG and temperature) to Data monitoring and RESULT display. There are several practical advantages in this implementation, such as: it provides always-on, real-time data collecting; it eliminates manual collecting work and signal analysis. This project contributes to scientific and social fields. On the scientific field, the project generates new knowledge and applications for ECG monitoring. These areas are being extensively explored by the academic community and the developments from this project will address some of the outstanding questions. In addition, there is a contribution to the social field, as the proposed system helps to improve the quality of medical assistance delivery, especially in needy communities. It is difficult to gather medical staff always for patient monitoring especially coma patients discharged from a hospital. In addition, expert medical staff has restricted time and cannot monitor patients or collect additional data from patients at bedside.

28

CHAPTER 8

Future Works
As future works, we intend to validate the proposal in a real world setup to assess the benefits of cloud computing and updating the data on a web server real-time using GSM services. In addition, we propose several services enhancements of security and management with interaction of thirty-party infrastructure service provider.

29

Appendix A
Programs A) Graphical Lcd Display Program
#include<pic.h> #include "delay.h" #include "glcd.h" #define GLCD_CS1 RC5 // Chip Selection 1 #define GLCD_CS2 RC4 // Chip Selection 2 #define GLCD_DI #define GLCD_RW #define GLCD_E RD7 // Data or Instruction input RD6 // Read/Write RD5 // Enable

#define GLCD_RST RD3 // Reset #define GLCD_BUS PORTB #define GLCD_LEFT 1

#define GLCD_RIGHT 0 #define ON #define OFF 1 0

void glcd_init(char mode) { GLCD_RST=1; // Instruction input


30

GLCD_E=0; GLCD_CS1=0; GLCD_CS2=0;


GLCD_DI=0; glcd_writeByte(GLCD_LEFT, 0xC0); // Set for instruction // Specify first RAM line at the top

glcd_writeByte(GLCD_RIGHT, 0xC0); glcd_writeByte(GLCD_LEFT, 0x40); glcd_writeByte(GLCD_RIGHT, 0x40); glcd_writeByte(GLCD_LEFT, 0xB8); glcd_writeByte(GLCD_RIGHT, 0xB8); if(mode == ON) {

//

of the screen

// Set the column address to 0

// Set the page address to 0

glcd_writeByte(GLCD_LEFT, 0x3F); // Turn the display on glcd_writeByte(GLCD_RIGHT, 0x3F); } else{ glcd_writeByte(GLCD_LEFT, 0x3E); // Turn the display off glcd_writeByte(GLCD_RIGHT, 0x3E); } glcd_fillScreen(1); }
// Clear the display */

31

/***********************************************************************

*****/ void glcd_fillScreen(char color) { char i, j; // Loop through the vertical pages for(i = 0; i < 8; ++i) { GLCD_DI=0; // Set for instruction // Set horizontal address to 0

glcd_writeByte(GLCD_LEFT, 0x40); glcd_writeByte(GLCD_RIGHT, 0x40);

glcd_writeByte(GLCD_LEFT, (i | 0xb8));// Set page address glcd_writeByte(GLCD_RIGHT, (i | 0xb8));


GLCD_DI=1; // Set for data

// Loop through the horizontal sections for(j = 0; j < 64; ++j) {


glcd_writeByte(GLCD_LEFT, (0xFF*color)); // Turn pixels on or off glcd_writeByte(GLCD_RIGHT, (0xFF*color)); // Turn pixels on or off

} }

32

} /*********************************************************************** *****/ extern void glcd_pixel(char x,char y,char color) { char data=0;
char side = GLCD_LEFT; // Stores which chip to

use on the LCD x=127-x; y=63-y; if(x > 63){ x -= 64; side = GLCD_RIGHT; }
GLCD_DI=0; // Check for first or second display area

// Set for instruction

data=(0x01<<(y%8));
glcd_writeByte(side, (0x40|x)); // Set the horizontal address

glcd_writeByte(side, (0xB8|(y/8)));
GLCD_DI=1;

// Set the vertical page address

// Set for data // Need two reads to get data // at new address

glcd_readByte(side); data |= glcd_readByte(side);

33

if(color)data|=(0x01<<(y%8)); code else data&=~(0x01<<(y%8)); GLCD_DI=0; // Set for instruction

// Clear the MSB. Part of an instruction

// Set bit 6. Also part of an instruction code

glcd_writeByte(side, (0x40|x)); GLCD_DI=1; // Set for data

// Set the horizontal address

glcd_writeByte(side, data); }

// Write the pixel data

/*********************************************************************** *****/ void glcd_writeByte(char side, char data) {


if(side){

// Choose which side to write to

GLCD_CS1=1; } Else { GLCD_CS2=1; }

GLCD_BUS=0;
GLCD_RW=0;

// Set for writing


34

PORTB=data;

// Put the data on the port

NOP(); NOP(); NOP(); NOP(); NOP(); RD5=1; NOP(); NOP(); NOP(); NOP(); RD5=0;
GLCD_CS1=0; // Pulse the enable pin

// Reset the chip select lines

GLCD_CS2=0; }
/***********************************************************************

*****/ char glcd_readByte(char side) { char data; // Stores the data read from the LCD

35

TRISB=0xFF;
GLCD_RW=1; if(side){ // Set for reading

// Choose which side to write to

GLCD_CS1=1; GLCD_CS2=0; } else{ GLCD_CS1=0; GLCD_CS2=1; }

NOP(); NOP(); NOP(); NOP(); RD5=1; NOP(); NOP(); NOP(); NOP(); NOP();
// Pulse the enable pin

36

data = PORTB; RD5=0;


GLCD_CS1=0;

// Get the data from the display's output register

// Reset the chip select lines

GLCD_CS2=0; TRISB=0; return data; #include<pic.h> #include "delay.h" #include "glcd.h"


// Return the read dat}

#define GLCD_CS1 RC5 // Chip Selection 1 #define GLCD_CS2 RC4 #define GLCD_DI #define GLCD_RW #define GLCD_E #define GLCD_RST #define GLCD_BUS // Chip Selection 2

RE0 // Data or Instruction input RE1 // Read/Write RE2 // Enable RD3 // Reset PORTB

#define GLCD_LEFT

#define GLCD_RIGHT 0 #define ON 1

37

#define OFF

void glcd_init(char mode){ GLCD_RST=1; // Instruction input GLCD_E=0; GLCD_CS1=0; GLCD_CS2=0;


GLCD_DI=0; glcd_writeByte(GLCD_LEFT, 0xC0); // Set for instruction // Specify first RAM line at the top

glcd_writeByte(GLCD_RIGHT, 0xC0); glcd_writeByte(GLCD_LEFT, 0x40); glcd_writeByte(GLCD_RIGHT, 0x40); glcd_writeByte(GLCD_LEFT, 0xB8); glcd_writeByte(GLCD_RIGHT, 0xB8);

//

of the screen

// Set the column address to 0

// Set the page address to 0

if(mode == ON){

38

glcd_writeByte(GLCD_LEFT, 0x3F); // Turn the display on glcd_writeByte(GLCD_RIGHT, 0x3F); } else{ glcd_writeByte(GLCD_LEFT, 0x3E); // Turn the display off glcd_writeByte(GLCD_RIGHT, 0x3E); } glcd_fillScreen(1); }
// Clear the display */

void glcd_fillScreen(char color) { char i, j;

// Loop through the vertical pages for(i = 0; i < 8; ++i) { GLCD_DI=0; // Set for instruction // Set horizontal address to 0

glcd_writeByte(GLCD_LEFT, 0x40);

39

glcd_writeByte(GLCD_RIGHT, 0x40); glcd_writeByte(GLCD_LEFT, (i | 0xb8));// Set page address glcd_writeByte(GLCD_RIGHT, (i | 0xb8));


GLCD_DI=1; // Set for data

// Loop through the horizontal sections for(j = 0; j < 64; ++j) {


glcd_writeByte(GLCD_LEFT, (0xFF*color)); // Turn pixels on or off glcd_writeByte(GLCD_RIGHT, (0xFF*color)); // Turn pixels on or off

} } } extern void glcd_pixel(char x,char y,char color){ char data=0;


char side = GLCD_LEFT; // Stores which chip to

use on the LCD

if(x > 63){ x -= 64;

// Check for first or second display area

side = GLCD_RIGHT;

40

}
GLCD_DI=0;

// Set for instruction

data=(0x01<<(y%8));

glcd_writeByte(side, (0x40|x));

// Set the horizontal address

glcd_writeByte(side, (0xB8|(y/8)));
GLCD_DI=1;

// Set the vertical page address

// Set for data // Need two reads to get data // at new address

glcd_readByte(side); data |= glcd_readByte(side);

if(color)data|=(0x01<<(y%8)); code
else data&=~(0x01<<(y%8));

// Clear the MSB. Part of an instruction

// Set bit 6. Also part of an instruction code

GLCD_DI=0;

// Set for instruction // Set the horizontal address

glcd_writeByte(side, (0x40|x)); GLCD_DI=1; // Set for data

glcd_writeByte(side, data); }

// Write the pixel data

void glcd_block(char x,char y,char color){

41

char data=0;
char side = GLCD_LEFT; // Stores which

chip to use on the LCD if(x > 63){ x -= 64; side = GLCD_RIGHT; }
GLCD_DI=0; // Check for first or second display area

// Set for instruction

data=(0x01<<(y%8));

glcd_writeByte(side, (0x40|x)); glcd_writeByte(side, (0xB8|(y/8))); //IO1SET =GLCD_DI; // glcd_readByte(side); // data |= glcd_readByte(side);

// Set the horizontal address // Set the vertical page address // Set for data // Need two reads to get data // at new address

if(color)data=0xff;

// Clear the MSB. Part of an instruction code // Set bit 6. Also part of an instruction code

else data = 0;

//IO1CLR =GLCD_DI;

// Set for instruction // Set the horizontal address

glcd_writeByte(side, (0x40|x));

42

GLCD_DI=1;

// Set for data

glcd_writeByte(side, data); }

// Write the pixel data

void glcd_writeByte(char side, char data) {


if(side){

// Choose which side to write to

GLCD_CS1=1; } else{ GLCD_CS2=1; }

GLCD_BUS=0;
GLCD_RW=0; GLCD_BUS=data;

// Set for writing


// Put the data on the port

NOP(); NOP(); NOP();

43

NOP(); NOP(); NOP(); NOP(); NOP();


GLCD_E=1; // Pulse the enable pin

NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); GLCD_E=0;

GLCD_CS1=0; // Reset the chip select lines GLCD_CS2=0; }

44

char glcd_readByte(char side) { char data; // Stores the data read from the LCD

TRISB=0xFF;

GLCD_RW=1;

// Set for reading

if(side){

// Choose which side to write to

GLCD_CS1=1; GLCD_CS2=0; } else{


GLCD_CS1=0; GLCD_CS2=1;

NOP(); NOP(); NOP();

45

NOP(); NOP(); NOP(); NOP(); NOP();


GLCD_E=1; // Pulse the enable pin

NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); data = GLCD_BUS; // Get the data from the display's output register GLCD_E=0;

GLCD_CS1=0;

// Reset the chip select lines

GLCD_CS2=0; TRISB=0;

46

return data; }

// Return the read data

B) Temperature Sensing Program


#include<pic.h> Void command(char); void data(char); void lcd_print(char*); void delay(long); void main() {
Int c,a[8],b; TRISC0=0; TRISC1=0; TRISC5=0; //TRIS=0 MEANS OUTPUT PORT AND VICEVERSA

TRISD=0; TRISA0=1;

//B,C,D ARE PORTS //for adc input


47

TRISB0=1; TRISB4=1; TRISB5=1; TRISB6=1; TRISB2=1; int count=0; delay(25); command(0x30); delay(15); command(0x30); delay(5); command(0x30); delay(1); command(0X38); command(0x0C); command(0x06); command(0x01); command(0x01);delay(6);command(0x83);delay(2); lcd_print("SMART CARDIOLOGIST"); delay(500); command(0x01); delay(10); loop: ADCON0=0x81; ADCON1=0xC0;
//PRESET ADC CONFIG //LCD CHARACTER MAPPING

//LCD INITIALIZATION

48

while(!RB0) {if(RB2){goto credits;} command(0x01);delay(1); lcd_print("BODY TEMPERTATURE =");


GO=1; //Initialize the ADC

while(GO); b=ADRESH; b=b<<8; b=b|ADRESL; b=((b/2)-1);

for(int i=0;i<2;i++) { a[i]=b%10; b=b/10; } for(int i=1;i>=0;i--) { data(a[i]+'0'); } delay(50);

49

command(0x01);delay(50);if(RB2){goto credits;} if((RB4==0)&&(RB5==0)&&(RB6==0)){c=0;lcd_print("1st degree arrhythmia detected");} if((RB4==0)&&(RB5==0)&&(RB6==1)){c=1;lcd_print("2nd degree arrhythmia detected");} if((RB4==0)&&(RB5==1)&&(RB6==0)){c=2;lcd_print("3rd degree arrhythmia detected"); while(!RB0); if(RB2){goto credits;} Command (0x01);delay(50); If(c==0){command(0x83);lcd_print("RISK LEVEL: LOW");} If(c==1){command(0x83);lcd_print("RISK LEVEL: MEDIUM");} If(c==2){command(0x83);lcd_print("RISK LEVEL: CRITICAL");} delay(1000); Goto loop; Credits: Command (0x07);delay(3); lcd_print("developed by dileep nidhish eldho vivek and ladvine ");delay(100); Goto loop; }

50

/***********************************************************************

****/ Void command (char a) { RC0=0; RC1=0; PORTD=a; RC5=1; delay(1); RC5=0; }
/***********************************************************************

*****/ void data(char m) { RC0=1; RC1=0; PORTD=m; RC5=1; delay(1); RC5=0; }


51

/***********************************************************************

*****/ Void lcd_print(char* n) { While (*n!='\0') { Data (*n); n++; } }


/***********************************************************************

*****/ Void delay(long g) { int i,j; for(i=0;i<=g;i++)

for(j=0;j<255;j++); }

52

REFERENCE
wikipedia.org Health science Medicine Emergency medicine

wikipedia.org/wiki/Cardiac_arrhythmia wikipedia.org/wiki/Human_body_temperature firstaid.webmd.com/body-temperature\


http://203.217.146.76/projects/MAIN/BME/M2-DOCecg%20acquisition%20and%20arrythmia%20detection.pdf

http://www.ti.com/lit/ds/symlink/lm35.pdf http://www.ti.com/lit/ds/symlink/lm124-n.pdf Guyton AC: An authors philosophy of physiology textbook writing. Adv Physiol Ed 19: s1s5, 1998.

53

Appendix B

PIC16F87X Data Sheet


28/40-Pin 8-Bit CMOS FLASH

Microcontrollers

2001 Microchip Technology Inc.

DS30292C

All

rights

reserved.

Copyright

2001,

Microchip

Technology

Trademarks The Microchip name, logo, PIC, PICmicro, PICMASTER, PICSTART, PRO MATE, KEELOQ, SEEVAL, MPLAB and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. Total Endurance, ICSP, In-Circuit Serial Programming, Filter-Lab, MXDEV, microID, FlexROM, fuzzyLAB, MPASM, MPLINK, MPLIB, PICDEM, ICEPIC, Migratable Memory, FanSense, ECONOMONITOR and SelectMode are trade-marks of Microchip Technology Incorporated in the U.S.A. Serialized Quick Term Programming (SQTP) is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. 2001, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

Incorporated, USA. Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accu-racy or use of such information, or infringement of patents or other intellectual property rights arising from such use or oth-erwise. Use of Microchip s products as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. The Microchip logo and name are registered trademarks of Microchip Technology Inc. in the U.S.A. and other countries. All rights reserved. All other trademarks mentioned herein are the property of their respective companies. No licenses are conveyed, implicitly or otherwise, under any intellectual prop-erty rights.

Microchip received QS-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona in July 1999. The Companys quality system processes and procedures are QS-9000 compliant for its PICmicro 8-bit MCUs, KEELOQ code hopping devices, Serial EEPROMs and microperipheral products. In addition, Microchips quality system for the design and manufacture of development systems is ISO 9001 certified.

DS30292C - page ii

2001 Microchip Technology Inc.

PIC16F87X
28/40-Pin 8-Bit CMOS FLASH Microcontrollers
Devices Included in this Data Sheet:
PIC16F873 PIC16F874 PIC16F876 PIC16F877

Pin Diagram
PDIP
MCLR/VPP RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 VDD VSS OSC1/CLKIN OSC2/CLKOUT
RC0/T1OSO/T1CKI

Microcontroller Core Features:


High performance RISC CPU Only 35 single word instructions to learn All single cycle instructions except for program branches which are two cycle Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle Up to 8K x 14 words of FLASH Program Memory, Up to 368 x 8 bytes of Data Memory (RAM) Up to 256 x 8 bytes of EEPROM Data Memory Pinout compatible to the PIC16C73B/74B/76/77 Interrupt capability (up to 14 sources) Eight level deep hardware stack Direct, indirect and relative addressing modes Power-on Reset (POR) Power-up Timer (PWRT) and Oscillator Start-up Timer (OST) Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation Programmable code protection Power saving SLEEP mode Selectable oscillator options Low power, high speed CMOS FLASH/EEPROM technology Fully static design
In-Circuit Serial Programming (ICSP) via two

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

RB7/PGD RB6/PGC RB5 RB4 RB3/PGM RB2 RB1 RB0/INT VDD VSS RD7/PSP7 RD6/PSP6 RD5/PSP5 RD4/PSP4 RC7/RX/DT RC6/TX/CK RC5/SDO RC4/SDI/SDA RD3/PSP3 RD2/PSP2

RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RD0/PSP0 RD1/PSP1

Peripheral Features:
Timer0: 8-bit timer/counter with 8-bit prescaler Timer1: 16-bit timer/counter with prescaler, can be incremented during SLEEP via external crystal/clock Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler Two Capture, Compare, PWM modules - Capture is 16-bit, max. resolution is 12.5 ns - Compare is 16-bit, max. resolution is 200 ns - PWM max. resolution is 10-bit 10-bit multi-channel Analog-to-Digital converter Synchronous Serial Port (SSP) with SPI (Master 2 mode) and I C (Master/Slave) Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection
Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin only)

pins
Single 5V In-Circuit Serial Programming capability

In-Circuit Debugging via two pins Processor read/write access to program memory Wide operating voltage range: 2.0V to 5.5V High Sink/Source Current: 25 mA Extended

Commercial, Industrial and temperature ranges Low-power consumption: -< 0.6 mA typical @ 3V, 4 MHz - 20 A typical @ 3V, 32 kHz - <1A typical standby current

Brown-out detection circuitry for Brown-out Reset (BOR)

2001 Microchip Technology Inc.

PIC16F877/874

DS30292C-page 1

PIC16F87X
Pin Diagrams
PDIP, SOIC
MCLR/VPP RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS VSS OSC1/CLKIN OSC2/CLKOUT RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 RB7/PGD RB6/PGC RB5 RB4 RB3/PGM RB2 RB1 RB0/INT VDD VSS RC7/RX/DT RC6/TX/CK RC5/SDO RC4/SDI/SDA

PIC16F876/873

R EF

PLCC

6 5 4 3 2 1

RE P FP

+ -

RA4/T0CKI RA5/AN4/SS RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 VDD VSS OSC1/CLKIN OSC2/CLKOUT RC0/T1OSO/T1CK1 NC

41

4443

R A 3 / A N 3 / V R A 2 / A N 2 / V R A 1 / A N 1 R A 0 / A N 0 M C L R / V N C R B 7 / P G D R B 6 / P G C R B 5 R B 4 N C

1 8

RC6/TX/ CKRC5/S DORC4/ SDI/SDA RD3/PSP 3RD2/PS P2

RC2/CCP1 RC1/T1OSI/C CP2

RD0/PSP0RC3/SCK/SCL

RD0/PS P0

RC4/SDI/SDA

RD1/PSP1 RD2/PSP2 RD3/PSP

RD1/PSP1

4443424140

38373635

RC7/RX/DT RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7 VSS VDD RB0/INT RB1 RB2 RB3/PGM

1 2 3 4 5 6 7 8 9 10 11

PIC16F877 PIC16F874

1 4 16

33 32 31 30 29 28 27 26 25 24 23 2 2

NC RC0/T1OSO/T1CKI OSC2/CLKOUT OSC1/CLKIN VSS VDD RE2/AN7/CS RE1/AN6/WR RE0/AN5/RD RA5/AN4/SS RA4/T0CKI

1 2

NCNC

RB4RB5

11920

RB6/PGC RB7/PG D MCLR/ V RA0/AN0 PP RA2/AN2/ RA1/AN1 V REF -

DS30292C-page 2

RA3/AN3/ V

R E F

RC1/T1OSI/CCP 2

RC3/SCK/S CL

QFP

2001 Microchip Technology Inc.

RC6/TX/C K

NC

RC5/SDO

RC2/CC P1

N C

22 7

202 223 24

7 8 9 10 11 12 13 14 15 16 17

PIC16F877 PIC16F874

39 38 37 36 35 34 33 32 31 30 29

RB3/PGM RB2 RB1 RB0/INT VDD VSS RD7/PSP7 RD6/PSP6 RD5/PSP5 RD4/PSP4 RC7/RX/DT

PIC16F87X
Key Features PICmicro Mid-Range Reference Manual (DS33023) Operating Frequency RESETS (and Delays) FLASH Program Memory (14-bit words) Data Memory Interrupts I/O Ports Timers Capture/Compare/PWM Modules Serial Communications Parallel Communications 10-bit Analog-to-Digital Module Instruction Set (bytes) EEPROM Data Memory PIC16F873 DC - 20 MHz POR, BOR (PWRT, OST) 4K 192 128 13 Ports A,B,C 3 2 MSSP, USART 5 input channels 35 instructions PIC16F874 DC - 20 MHz POR, BOR (PWRT, OST) 4K 192 128 14 Ports A,B,C,D,E 3 2 MSSP, USART PSP 35 instructions PIC16F876 DC - 20 MHz POR, BOR (PWRT, OST) 8K 368 256 13 Ports A,B,C 3 2 MSSP, USART 35 instructions PIC16F877 DC - 20 MHz POR, BOR (PWRT, OST) 8K 368 256 14 Ports A,B,C,D,E 3 2 MSSP, USART PSP 8 input channels 35 instructions

8 input channels 5 input channels

2001 Microchip Technology Inc.

DS30292C-page 3

PIC16F87X
Table of Contents
1.0 Device Overview .................................................................................................................................................. 5 2.0 Memory Organization ......................................................................................................................................... 11 3.0 I/O Ports............................................................................................................................................................. 29 4.0 Data EEPROM and FLASH Program Memory.................................................................................................... 41 5.0 Timer0 Module ................................................................................................................................................... 47 6.0 Timer1 Module ................................................................................................................................................... 51 7.0 Timer2 Module ................................................................................................................................................... 55 8.0 Capture/Compare/PWM Modules ....................................................................................................................... 57 9.0 Master Synchronous Serial Port (MSSP) Module................................................................................................ 65 10.0 Addressable Universal Synchronous Asynchronous Receiver Transmitter (USART) ......................................... 95 11.0 Analog-to-Digital Converter (A/D) Module ......................................................................................................... 111 12.0 Special Features of the CPU............................................................................................................................. 119 13.0 Instruction Set Summary................................................................................................................................... 135 14.0 Development Support ....................................................................................................................................... 143 15.0 Electrical Characteristics................................................................................................................................... 149 16.0 DC and AC Characteristics Graphs and Tables................................................................................................. 177 17.0 Packaging Information ...................................................................................................................................... 189 Appendix A: Revision History..................................................................................................................................... 197 Appendix B: Device Differences ................................................................................................................................ 197 Appendix C: Conversion Considerations.................................................................................................................... 198 Index ......................................................................................................................................................................... 199 On-Line Support ........................................................................................................................................................ 207 Reader Response ..................................................................................................................................................... 208 PIC16F87X Product Identification System ................................................................................................................. 209

TO OUR VALUED CUSTOMERS


It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and enhanced as new volumes and updates are introduced. If you have any questions or comments regarding this publication, please contact the Marketing Communications Department via E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150. We welcome your feedback.

Most Current Data Sheet


To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at: http://www.microchip.com You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page. The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).

Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision of silicon and revision of document to which it applies. To determine if an errata sheet exists for a particular device, please check with one of the following: http://www.microchip.com/ Microchips Worldwide Web site; http://www.microchip.com Your local Microchip sales office (see last page) The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277 When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include literature number) you are using.

Customer Notification System


Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.

DS30292C-page 4

2001 Microchip Technology Inc.

PIC16F87X
FIGURE 1-2:
Device PIC16F874 PIC16F877

PIC16F874 AND PIC16F877 BLOCK DIAGRAM


Program FLASH 4K 8K Data Memory 192 Bytes 368 Bytes
13 FLASH Program Memory 8 Level Stack (13-bit) Program Counter

Data EEPROM 128 Bytes 256 Bytes


Data Bus 8 PORTA RA0/AN0 RAM File Registers PORTB RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD PORTC
RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI

RA5/AN4/SS

Program Bus

14 RAM Addr Instruction reg Direct Addr 7

(1)

9 Addr MUX Indirect Addr

FSR reg 8 3 STATUS reg

Power-up Timer Instruction Decode & Control Timing Generation OSC1/CLKIN OSC2/CLKOUT Oscillator Start-up Timer Power-on Reset Watchdog Timer Brown-out Reset In-Circuit Debugger Low-Voltage Programming 8

MUX

ALU

RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT

W reg

PORTD RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7 PORTE

Parallel Slave Port

MCLR

VDD, VSS

RE0/AN5/RD RE1/AN6/WR RE2/AN7/CS

Timer0

Timer1

Timer 2

10-bit A/D

Data EEPROM

CCP1,2

Synchronous Serial Port

USART

Note 1: Higher order bits are from the STATUS register.

DS30292C-page 6

2001 Microchip Technology Inc.

PIC16F87X
TABLE 1-2:
Pin Name OSC1/CLKIN OSC2/CLKOUT

PIC16F874 AND PIC16F877 PINOUT DESCRIPTION


DIP Pin# 13 14 PLCC Pin# 14 15 QFP Pin# 30 31 I/O/P Type I O Buffer Type ST/CMOS Description

(4)

Oscillator crystal input/external clock source input. Oscillator crystal output. Connects to crystal or resonator in crystal oscillator mode. In RC mode, OSC2 pin outputs CLKOUT which has 1/4 the frequency of OSC1, and denotes the instruction cycle rate. Master Clear (Reset) input or programming voltage input. This pin is an active low RESET to the device. PORTA is a bi-directional I/O port. RA0 can also be analog input0. RA1 can also be analog input1. RA2 can also be analog input2 or negative analog reference voltage. RA3 can also be analog input3 or positive analog reference voltage. RA4 can also be the clock input to the Timer0 timer/ counter. Output is open drain type. RA5 can also be analog input4 or the slave select for the synchronous serial port. PORTB is a bi-directional I/O port. PORTB can be software programmed for internal weak pull-up on all inputs.

MCLR/VPP

18

I/P

ST

RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/SS/AN4

2 3 4 5 6 7

3 4 5 6 7 8

19 20 21 22 23 24

I/O I/O I/O I/O I/O I/O

TTL TTL TTL TTL ST TTL

RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD Legend: I = input

33 34 35 36 37 38 39 40

36 37 38 39 41 42 43 44

8 9 10 11 14 15 16 17

I/O I/O I/O I/O I/O I/O I/O I/O

TTL/ST TTL TTL TTL TTL TTL TTL/ST TTL/ST

(1)

RB0 can also be the external interrupt pin.

RB3 can also be the low voltage programming input. Interrupt-on-change pin. Interrupt-on-change pin.

(2) (2)

Interrupt-on-change pin or In-Circuit Debugger pin. Serial programming clock. Interrupt-on-change pin or In-Circuit Debugger pin. Serial programming data. P = power ST = Schmitt Trigger input

O = output = Not used

I/O = input/output TTL = TTL input

Note 1: This buffer is a Schmitt Trigger input when configured as an external interrupt. 2: This buffer is a Schmitt Trigger input when used in Serial Programming mode. 3: This buffer is a Schmitt Trigger input when configured as general purpose I/O and a TTL input when used in the Parallel Slave Port mode (for interfacing to a microprocessor bus). 4: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

DS30292C-page 8

2001 Microchip Technology Inc.

PIC16F87X
TABLE 1-2:
Pin Name

PIC16F874 AND PIC16F877 PINOUT DESCRIPTION (CONTINUED)


DIP Pin# PLCC Pin# QFP Pin# I/O/P Type Buffer Type Description PORTC is a bi-directional I/O port.

RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT

15 16 17 18 23 24 25 26

16 18 19 20 25 26 27 29

32 35 36 37 42 43 44 1

I/O I/O I/O I/O I/O I/O I/O I/O

ST ST ST ST ST ST ST ST

RC0 can also be the Timer1 oscillator output or a Timer1 clock input. RC1 can also be the Timer1 oscillator input or Capture2 input/Compare2 output/PWM2 output. RC2 can also be the Capture1 input/Compare1 output/PWM1 output. RC3 can also be the synchronous serial clock input/ output for both SPI and I C modes. RC4 can also be the SPI Data In (SPI mode) or data I/O (I C mode). RC5 can also be the SPI Data Out (SPI mode). RC6 can also be the USART Asynchronous Transmit or Synchronous Clock. RC7 can also be the USART Asynchronous Receive or Synchronous Data. PORTD is a bi-directional I/O port or parallel slave port when interfacing to a microprocessor bus.

RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7 RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 VSS VDD NC Legend: I = input

19 20 21 22 27 28 29 30 8 9 10 12,31 11,32

21 22 23 24 30 31 32 33 9 10 11 13,34 12,35 1,17,28, 40

38 39 40 41 2 3 4 5 25 26 27 6,29 7,28 12,13, 33,34

I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O P P

ST/TTL ST/TTL ST/TTL ST/TTL ST/TTL ST/TTL ST/TTL ST/TTL ST/TTL ST/TTL ST/TTL

(3) (3) (3) (3) (3) (3) (3) (3)


PORTE is a bi-directional I/O port.

(3) (3) (3)

RE0 can also be read control for the parallel slave port, or analog input5. RE1 can also be write control for the parallel slave port, or analog input6. RE2 can also be select control for the parallel slave port, or analog input7. Ground reference for logic and I/O pins. Positive supply for logic and I/O pins. These pins are not internally connected. These pins should be left unconnected. P = power ST = Schmitt Trigger input

O = output = Not used

I/O = input/output TTL = TTL input

Note 1: This buffer is a Schmitt Trigger input when configured as an external interrupt. 2: This buffer is a Schmitt Trigger input when used in Serial Programming mode. 3: This buffer is a Schmitt Trigger input when configured as general purpose I/O and a TTL input when used in the Parallel Slave Port mode (for interfacing to a microprocessor bus). 4: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

2001 Microchip Technology Inc.

DS30292C-page 9

2.0

MEMORY ORGANIZATION

2.1

Program Memory Organization

There are three memory blocks in each of the PIC16F87X MCUs. The Program Memory and Data Memory have separate buses so that concurrent access can occur and is detailed in this section. The EEPROM data memory block is detailed in Section 4.0. Additional information on device memory may be found in the PICmicro Mid-Range Reference Manual, (DS33023).

The PIC16F87X devices have a 13-bit program counter capable of addressing an 8K x 14 program memory space. The PIC16F877/876 devices have 8K x 14 words of FLASH program memory, and the PIC16F873/874 devices have 4K x 14. Accessing a location above the physically implemented address will cause a wraparound. The RESET vector is at 0000h and the interrupt vector is at 0004h.

FIGURE 2-1:

PIC16F877/876 PROGRAM MEMORY MAP AND STACK


PC<12:0>

FIGURE 2-2:

PIC16F874/873 PROGRAM MEMORY MAP AND STACK


PC<12:0>

CALL, RETURN RETFIE, RETLW

13

CALL, RETURN RETFIE, RETLW

13

Stack Level 1 Stack Level 2

Stack Level 1 Stack Level 2

Stack Level 8

Stack Level 8

RESET Vector

0000h

RESET Vector

0000h

Interrupt Vector Page 0

0004h 0005h

Interrupt Vector Page 0

0004h 0005h

07FFh 0800h On-Chip Program Memory Page 1 0FFFh 1000h Page 2 17FFh 1800h Page 3 1FFFh

On-Chip

Program Memory

07FFh 0800h Page 1 0FFFh 1000h

1FFFh

2001 Microchip Technology Inc.

DS30292C-page 11

PIC16F87X
2.2.2 SPECIAL FUNCTION REGISTERS
The Special Function Registers are registers used by the CPU and peripheral modules for controlling the desired operation of the device. These registers are implemented as static RAM. A list of these registers is given in Table 2-1. The Special Function Registers can be classified into two sets: core (CPU) and peripheral. Those registers associated with the core functions are described in detail in this section. Those related to the operation of the peripheral features are described in detail in the peripheral features section.

TABLE 2-1:
Address Bank 0 00h 01h 02h 03h 05h 06h 07h 08h 09h
(4) (4) (3) (3) (3) (3)

SPECIAL FUNCTION REGISTER SUMMARY


Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on: POR, BOR 0000 xxxx 0000 PD Z DC C 0001 xxxx --0x xxxx xxxx xxxx RE2 T0IF CCP1IF RE1 INTF TMR2IF RE0 RBIF TMR1IF CCP2IF ------0 0000 0000 -r-0 xxxx xxxx TMR1CS T2CKPS1 SSPM1 TMR1ON --00 0000 TOUTPS2 TOUTPS1 SSPEN CKP TOUTPS0 SSPM3 TMR2ON SSPM2 T2CKPS0 -000 xxxx SSPM0 0000 xxxx xxxx CCP1M3 ADDEN CCP1M2 FERR CCP1M1 OERR CCP1M0 RX9D --00 0000 0000 0000 xxxx xxxx CCP2M3 CHS0 CCP2M2 GO/DONE CCP2M1 CCP2M0 ADON --00 xxxx CHS1 0000 RP0 TO 0000 xxxx 0000 1xxx xxxx 0000 xxxx xxxx xxxx -xxx 0000 000x 0000 0--0 xxxx xxxx 0000 0000 0000 xxxx 0000 xxxx xxxx 0000 000x 0000 0000 xxxx xxxx 0000 xxxx 00-0 Details on page: 27 47 26 18 27 29 31 33 35 36 26 20 22 24 52 52 51 55 55 70, 73 67 57 57 58 96 99 101 57 57 58 116 111

Name

INDF TMR0 PCL STATUS FSR PORTA PORTB PORTC PORTD PORTE PCLATH INTCON PIR1 PIR2 TMR1L TMR1H T1CON TMR2 T2CON SSPBUF SSPCON CCPR1L CCPR1H CCP1CON RCSTA TXREG RCREG CCPR2L CCPR2H CCP2CON ADRESH ADCON0

Addressing this location uses contents of FSR to address data memory (not a physical register) Timer0 Module Register Program Counter (PC) Least Significant Byte IRP RP1 Indirect Data Memory Address Pointer PORTA Data Latch when written: PORTA pins when read PORTB Data Latch when written: PORTB pins when read PORTC Data Latch when written: PORTC pins when read PORTD Data Latch when written: PORTD pins when read GIE PSPIF
(3)

04h(3)

PEIE ADIF (5)

T0IE RCIF

INTE TXIF EEIF

RBIE SSPIF BCLIF

0Ah(1,3)
0Bh 0Ch 0Dh 0Eh 0Fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1Ah 1Bh 1Ch 1Dh 1Eh 1Fh
Legend:

Write Buffer for the upper 5 bits of the Program Counter

Holding register for the Least Significant Byte of the 16-bit TMR1 Register Holding register for the Most Significant Byte of the 16-bit TMR1 Register WCOL TOUTPS3 SSPOV T1CKPS1 T1CKPS0 T1OSCEN T1SYNC Timer2 Module Register Synchronous Serial Port Receive Buffer/Transmit Register Capture/Compare/PWM Register1 (LSB) Capture/Compare/PWM Register1 (MSB) SPEN RX9 CCP1X SREN CCP1Y CREN

USART Transmit Data Register USART Receive Data Register Capture/Compare/PWM Register2 (LSB) Capture/Compare/PWM Register2 (MSB) ADCS1 ADCS0 CCP2X CHS2 CCP2Y A/D Result Register High Byte

x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0', r = reserved.

Shaded locations are unimplemented, read as 0. Note 1: The upper byte of the program counter is not directly accessible. PCLATH is a holding register for the PC<12:8> whose contents are transferred to the upper byte of the program counter. 2: Bits PSPIE and PSPIF are reserved on PIC16F873/876 devices; always maintain these bits clear. 3: These registers can be addressed from any bank. 4: PORTD, PORTE, TRISD, and TRISE are not physically implemented on PIC16F873/876 devices; read as 0. 5: PIR2<6> and PIE2<6> are reserved on these devices; always maintain these bits clear.

2001 Microchip Technology Inc.

DS30292C-page 15

Das könnte Ihnen auch gefallen