Silicon ChipBuild A USB-Controlled Electrocardiograph - February 2005 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Tsunami warning system must be built for Indian Ocean
  4. Feature: Border Surveillance In The 21st Century by Barrie Smith
  5. Project: Build A USB-Controlled Electrocardiograph by Jim Rowe
  6. Project: TwinTen Stereo Amplifier by Jim Rowe & Peter Smith
  7. Project: Inductance & Q-Factor Meter by Leonid Lerner
  8. Project: A Real Yagi Antenna For UHF CB by Stan Swan
  9. Feature: School Electronics: Putting The Picaxe To Work by Ross Tester
  10. Salvage It: Build a $2 battery charger by Julian Edgar
  11. Vintage Radio: Converting a 240VAC set to 32V DC operation by Rodney Champness
  12. Book Store
  13. Feature: Build Yourself A Windmill Generator, Pt.3 by Glenn Littleford
  14. Advertising Index
  15. Outer Back Cover

This is only a preview of the February 2005 issue of Silicon Chip.

You can view 40 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Build A USB-Controlled Electrocardiograph":
  • PIC16F84A-04(I)/P programmed for the USB Electrocardiograph [ECGSAMPL.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC16F84 firmware and accompanying software for the USB Electocardiograph [ECGSAMPL.HEX] (Free)
  • USB Electrocardiograph PCB pattern (PDF download) [07102051] (Free)
  • USB Electrocardiograph front panel artwork (PDF download) (Free)
Items relevant to "TwinTen Stereo Amplifier":
  • TwinTen Amplifier PCB [01102051] (AUD $20.00)
  • Twin Ten Stereo Amplifier PCB pattern (PDF download) [01102051] (Free)
  • Twin Ten Stereo Amplifier front & rear panel artwork (PDF download) (Free)
Items relevant to "Inductance & Q-Factor Meter":
  • AT90S2313 firmware and source code for the Inductance & Q-Factor Meter (Software, Free)
  • Inductance & Q-Factor Meter PCB pattern (PDF download) [04102051] (Free)
  • Inductance & Q-Factor Meter front panel artwork (PDF download) (Free)
Articles in this series:
  • Inductance & Q-Factor Meter (February 2005)
  • Inductance & Q-Factor Meter (February 2005)
  • Inductance & Q-Factor Meter; Pt.2 (March 2005)
  • Inductance & Q-Factor Meter; Pt.2 (March 2005)
Articles in this series:
  • Build Yourself A Windmill Generator, Pt.1 (December 2004)
  • Build Yourself A Windmill Generator, Pt.1 (December 2004)
  • Build Yourself A Windmill Generator, Pt.2 (January 2005)
  • Build Yourself A Windmill Generator, Pt.2 (January 2005)
  • Build Yourself A Windmill Generator, Pt.3 (February 2005)
  • Build Yourself A Windmill Generator, Pt.3 (February 2005)
  • Build Yourself A Windmill Generator, Pt.4 (March 2005)
  • Build Yourself A Windmill Generator, Pt.4 (March 2005)

Purchase a printed copy of this issue for $10.00.

BUILD THIS USB ELEC Here’s an easy-to-build project which will let you take your own electrocardiogram (ECG) and display it on a PC. You can read, display, save to disk and print the electrical waveform generated by your heart – or anyone else’s. It connects to your PC via a standard USB cable which also provides the low power it needs to operate. A n Electrocardiograph is a piece of medical equipment used to measure and record the voltages (ECG) produced as a result of heart muscle activity. By attaching electrodes (or ‘leads’ as they are known in the trade) to the skin of your wrists, ankle or chest, our PC-Driven ECG project can display, record or print out the same kind of ECG waveform on your personal computer. Why would you want to build one? Well, looking at the waveforms generated by your heart can be both fun and educational. You can monitor changes to your heart under various conditions, as your heart is affected by many factors such as emotions, mental and physical activity – even breathing. All of these things have a demonstrable effect on the heart’s ECG waveform. Being able to show this 14  Silicon Chip easily, safely and at low cost is an added bonus. Professional ECG machines can cost anything from $4000 up, and while this project is not intended to be used as a diagnostic device, the displayed, recorded and printed waveforms are of a quality approaching that of professional machines. Our new PC-based electrocardiogram is smarter than previous models because its operation is under the control of an inbuilt PIC microcontroller. It’s also faster and compatible with modern PCs, because it’s linked to the PC via a standard USB cable – thanks to the use of an Elexol USBMOD3 interface module. And finally it’s easier to use, because all functions are controlled using a By JIM ROWE Windows-based GUI program, written in Visual Basic. Both the PIC microcontroller’s firmware program and the Visual Basic PC program will be available on the SILICON CHIP website (www.siliconchip. com.au). The PIC program (ECGSAMPL. HEX) is in hex code form ready for PIC programming, while the VB program (ECGCONTR.ZIP) is in the form of a zipped-up installation package. We imagine that kit suppliers will have already programmed the PIC for you. You’ll also need a special USB virtual COM port driver which the PC needs to communicate with the ECG via a USB cable. This will also be available on the SILICON CHIP website, as R9052154.ZIP. Both the latter items can be installed directly on a PC running Win98SE or newer USBcompatible operating systems. Note siliconchip.com.au CTROCARDIOGRAPH PLEASE NO TE: This project has Correct interp not been designed for m edical diagn retation of E osis. CG waveform complex and s and tracing skilled proce s dure and req is a ing. The USB uires medica /ECG is pres l trainented here a educational s an instructi device only. ve and If you are c health of you o ncerned abo r heart, cons ut the ult your GP o r a heart spe cialist. that it won’t work with Win NT-based systems – not through any shortcoming in the design but the simple fact that NT doesn’t recognise the USB port. How it works The muscles of your body are controlled by electrochemical impulses. These impulses are distributed to the muscles by the nervous system. On reaching their destination, the nerve impulses cause the muscles to contract and produce much larger electrical voltages. A small proportion of these voltages is conducted out through to the surface of the skin where they can be detected using sensitive equipment like an ECG (often also called EKG). Because the heart is a large and rather complex group of muscles which contract cyclically in a preset sequence (see sidebar), it is possible to study the overall condition of the heart by measuring the amplitude, timing and waveform of the heart muscle voltage components found on the skin. This is the reason for capturing ECG waveforms, which are obtained using two or more electrodes (pads) attached to the skin via conductive saline gels or paste. siliconchip.com.au A “screen grab” using this project on a live human. We make no comment on the condition of his/her heart from this graph: perhaps a cardiologist out there might care to? February 2005  15 the ECG amplifier, we can cancel out most of the common-mode 50Hz hum before the differential ECG voltages are amplified. By the way, the connections between the electrodes and your skin play an important role in this hum cancellation, because if one connection is poor this can upset the balance of the input amplifier. Most of the remaining 50Hz signals are removed by low-pass filtering in the later stages of the amplifier. As a result the output of the amplifier provides relatively clean amplified ECG signals, with very little 50Hz hum. We then use a simple PIC-driven ADC (analog to digital converter) to sample the amplified signals to be sent to the PC for display and recording. Circuit description Let’s see how the circuit works. It is shown in Fig.1. The shielded electrode leads are brought into the Electrocardiograph via connectors CON1 and CON2 and fed through 1mF coupling capacitors and series 3.9kW resistors to the inputs of IC1. This is an Analog Devices AD623AN device, a specialised instrumentation amplifier offering precision balanced differential inputs and hence very high common-mode signal rejection, combined with high gain. A simplified version of the circuitry The complete ECG setup using our new Electrocardiograph, a laptop PC (with inside the AD623 is shown in Fig.2. USB) and home-made electrodes. You can also use commercial ECG pads. It is essentially three op amps in one: Capturing ECG waveforms is really picked up by the electrodes is virtually two matched-gain input stages feeding quite a challenge, because the voltage the same regardless of their position a balanced ‘subtractor’ output stage. components found on the surface of on the body. In other words the 50Hz The overall AD623 gain for differthe skin are quite small in amplitude: hum is a ‘common mode’ signal, while ential-mode signals is set by the single around 1mV peak to peak, depend- the tiny ECG voltages are ‘differential external resistor Rg (between pins 1 & ing on the positions of the electrodes mode’ signals. 8), which gives a gain of 1000 times and the resistance between them and By using a highly balanced differ- (60dB) using a value of 100W. the skin. ential amplifier as the input stage of Returning to the main circuit, to So to display or record ensure that IC1 can deliver these voltages we need to INVERTING maximum undistorted output INPUT feed them through a high level and also that the ADC 50kΩ 50kΩ 2 A1 gain amplifier. used for sampling the amplified To make the job that much signals can handle the largest harder, the tiny voltages we signal swing, we connect IC1’s 1 50kΩ want to measure are usureference signal input (pin 5) to 6 A3 Vout ally completely swamped Rg a low impedance source of +2.5V 50kΩ by 50Hz hum, picked up by DC (ie, half the supply voltage). 8 our bodies from the fields This is provided by the voltage surrounding the AC wiring NONOUTPUT divider formed by the two 3.0kW 50kΩ 50kΩ REF in our homes and offices, etc. INVERTING resistors and it thereby sets the A2 INPUT 5 Luckily we are only inzero-signal output level of IC1 3 AD623 INSTRUMENTATION AMP terested in the voltage difto +2.5V DC. The two 220kW ferences between the two Fig.2: a simplified look inside the heart of the input bias resistors for IC1 are electrodes being used at any project, an Analog Devices AD623 instrumentation also returned to the same +2.5V time, whereas the 50Hz hum amplifier. It’s essentially three op amps in one. point, as you can see. 16  Silicon Chip siliconchip.com.au siliconchip.com.au February 2005  17 1 µF 1 µF SC 1nF 220k 100Ω 10 µF A K D1,D2: 1N4148 3.0k +2.5V INSULATED RCA PLUGS 5 6 3.0k 100nF 10k HI LO 8.2k TO CON2 TO CON1 usb ELECTROCARDIOGRAPH A K 4 100nF ELECTRODE LEAD WIRING NOTE: SHIELDED LEADS SHOULD BE OF EQUAL LENGTH SHIELDED LEADS 7 IC1 AD623AN 220k 2 1 8 3 IMPORTANT: INSULATE ELECTRODE ENDS OF LEAD SHIELD BRAIDS 1nF 3.9k 47nF 3.9k BALANCED INPUT AMPLIFIER Fig.1: the complete ECG circuit. It uses a preassembled module from Elexol to connect to the USB port on your PC. 2005 LEDS ELECTRODE 2 ELECTRODE 1 CON2 CON1 ELECTRODE LEADS D1 A K K A 20k 10k 10k 10k 10k LADDER DAC 10k 10k 10k 20k D2 220 µF 1 µF LP FILTER 1.8k GAIN S1 100 µF 82Ω 20k IC2a 8 2 3 20k 20k 20k 20k 20k 20k 20k 20k 5 2 3 4 5 6 7 8 9 1,4 IC3 8 1 20 DIR 1 10 18 17 16 15 14 13 12 11 100nF 1.2k OE 19 IC4 74HC245 6 7 LM311 COMPARATOR 2 3 2X/4X AMPLIFIER RB2 RB3 RB4 RB5 RB6 RB7 1k 6 RB0 7 RB1 8 9 10 11 12 13 10k 6.8 µF NP 11k IC2: LM358 5 Vss 100k OSC2 OSC1 RA0 RA1 RA2 RA3 15 16 17 18 1 2 7 14 X1 4MHz 28 27 26 25 4,13 RSTI 8 PCTL 100nF 1,2,16, 29,32 GND EP RXLD TXLD RSTO USB-MOD3 INTERFACE MODULE 33pF TxD RxD RTS CTS SLEEP VIO 100 µF 'DIGITAL' +5V +VBUS 100nF 12 100nF 33pF 4 IC2b 100nF 6 5 14 Vdd 4 MCLR IC5 PIC16F84 -04 3 RA4 1 µF 2.7k LP FILTER 'ANALOG' +5V 18 10 9 15 17 K λ A CASE USB CABLE TO PC 220Ω 220Ω LED 1 LED λ 2 33k K A RFC1 1mH 18  Silicon Chip Looking straight down on the completed PC board, mounted inside the bottom of the case. Note the earth connection on the right-hand side of the box. RECEIVE COMMAND SEND DATA USB CONNECTOR 33pF 33pF RSTI EP* 5002 © 15020170 RSTO 3V3 Din RTS* o CTS* i SLEEP IC5 DTR* o DSR* i 1 DCD* i VIO* * +V RI* i PEN* o PCTL RXLED TXLED 11k 100 µF + IC1 AD623 1 LL 220 µF 100nF 74HC245 1.0 µF SIDE OF BOX 100nF 10 µF 33k 1.0 µF 47nF + 100nF + 3.9k 3.9k 1.0 µF 1.8k 1nF 1nF 20k 3.0k 3.0k 1 IC4 1 100nF 220k 100Ω 1.2k IC2 LM358 8.2k 220k 82Ω 100nF Fig.3: and here’s the matching overlay diagram to help you place the components correctly. Between this and the photo above, you should have no problems in construction. 1k 100nF 1 10k 4148 D1 D2 4148 100 µF 6.8 µF NP 100k IC3 LM311 RFC1 1mH 2.7k PIC16F84A 100nF TXENo GND 1.0 µF X1 4MHz 20k 20k 20k 20k 20k 20k 20k 20k EDAT Dout 220Ω 220Ω ECLK + ECS 100nF B+ +V ELEXOL USBMOD3 V5+ LED2 (TXD) LED1 (RXD) G 20k 10k 10k 10k 10k 10k 10k 10k 1 + 10k 20k As IC1 is being operated with such a high gain, we also need to prevent it from amplifying any stray RF signals which may be picked up by the electrode leads (or the subject’s body). This is the purpose of the 1nF bypass capacitors on each input of IC1 and also the 47nF capacitor between the two inputs. All three capacitors form a balanced low-pass filter, in conjunction with the two 3.9kW input series resistors. The rest of the Electrocardiograph’s amplifier and filter circuitry is based around IC2, an LM358 dual low-power op amp. The output from IC1 is fed to the input of IC2a via a passive RC low-pass filter formed by the series 8.2kW and 1.8kW resistors and the 1.0mF capacitor, which give a corner frequency (-3dB point) of about 17Hz and an attenuation of about -9dB at 50Hz. IC2a is used to give additional fixed amplification to the ECG signals, of either two or four times as set by switch S1, which determines the negative feedback ratio. So in the LO position of the switch the amplification in IC2a is 2, while in the HI position it gives a gain of 4. The overall ECG signal gain for the two switch positions is therefore 2000 and 4000, respectively. IC2b is used to provide additional low-pass filtering, to further reduce any remaining 50Hz hum. With the R and C values shown this filter stage has a corner frequency of about 15Hz, providing further attenuation of about -21dB at 50Hz. At the same time it has unity gain for the low frequency ECG signals. So at the output of IC2b (pin 7) we end up with relatively clean and hum-free ECG signals, amplified by either 2000 or 4000 times depending on the setting of switch S1. The rest of the circuit is involved in performing analog-to-digital conversion (ADC) of these signals, and sending them back to the PC via the USB cable and port. Both of these functions are controlled using IC5, a PIC16F84A microcontroller operating at 4MHz. Analog-to-digital conversion is done using comparator IC3 to compare the amplified ECG signals with a programmed reference voltage generated by IC5 and IC4, an octal transceiver containing eight digital buffers. IC4 drives the binary ladder network formed by the 10kW and 20kW resistors. The combination of IC4 and the ladder network forms a simple digital- CON2 CON1 S1 GAIN HI LO LEAD2 LEAD1 M3 x 9mm CSK HEAD SCREW WITH SOLDER LUG, NUT & 2 x STAR LOCKWASHERS siliconchip.com.au to-analog converter (DAC), whereby IC5 can generate any of 256 different voltage levels between 0V and 5V at the positive input (pin 2) of IC3, by providing 8-bit values on the outputs of its I/O port B (pins 6-13). The output of comparator IC3 is connected to pin 3 of IC5 which is bit 4 of the micro’s I/O port A, configured here as an input. This allows the micro to monitor the output of IC3 and perform a simple ‘successive approximation’ ADC algorithm. It generates a sequence of voltages at pin 2 of IC3 and changes the sequence according to the comparator output (which indicates whether the DAC voltage is higher or lower than the ECG voltage on pin 3). As a result, the micro can quickly ‘zero in’ on the ECG voltage during each sampling sequence, arriving at its 8-bit digital equivalent in only 48ms. When each digital sample has been taken, the micro then sends it out in serial format (38,400bps) from bit 1 of its I/O port A1 (pin 18) to pin 27 (RxD) of the USB-MOD3 interface module. This module then reformats the sample and sends it back to the PC via the USB cable and port. The micro is programmed in firmware to take a sequence of 8192 of these samples at a time, at any of three rates: 500, 1000 or 2000 per second. The rate is controlled by the Visual Basic software running in the PC, which sends a control code out to the micro when you click on the ‘Start Sampling’ button. The control code is sent out via the USB cable, is received by the USBMOD3 module and then sent to the micro via the module’s pin 28 (TxD), connected to bit 0 of the micro’s I/O port A. Two inverse-parallel connected diodes (D1 and D2) at the inputs of IC3 are used to limit the voltage swing between the comparator inputs to +/0.6V, regardless of the real difference between the amplified ECG and DAC reference voltages. This limiting prevents the comparator from being saturated and allows it to respond faster when the difference voltage changes in polarity. The USB-MOD3 module is powered from the PC via the USB cable and it provides +5V DC from its +VBUS pins (pins 4 and 13), to power the rest of the circuitry. IC3, IC4 and IC5 are powered from it directly, while IC1, IC2 and the siliconchip.com.au Your Heart & Its Electrical Activity R T P Q S ONE HEART BEAT/PUMPING CYCLE Most people are aware that your heart is basically a pump, which pushes your blood around your body via your arteries and veins. The typical human adult heart is about the size of a clenched fist, and weighs about 300 grams. It is a popular misconception that the heart is located in the left side of the chest. It’s not: the heart is located near the centre (although its apex points to the left) and is virtually surrounded above and at the sides by the lungs. In a normal adult it pumps about once per second although this can vary dramatically due to a large number of causes (age, fitness, current activity and health/disease being just four). The pumping action is triggered mainly by a nerve centre inside the heart, called the sino-atrial or ‘SA’ node. Each pumping cycle is initiated by a nerve impulse which starts at the SA node and spreads downwards through the heart via preset pathways. The heart itself is made up of millions of bundles of microscopic R muscle cells, which contract when triggered. The muscle cells are electrically polarised, like tiny electrolytic capacitors (positive outside, negative inside), and as the trigger pulse from the SA node passes through them, they depolarise briefly and contract. So with each beat of the heart, a ‘wave’ of depolarisation sweeps from the top of the heart to the bottom. Weak voltages produced by this wave appear on the outside surface of your skin, and can be picked up using electrodes strapped to your wrists, angles and the front of your chest. It’s these voltages (about 1mV peak to peak) which are captured and recorded as an electrocardiogram or ‘ECG’. The actual shape and amplitude of the ECG waveform depends upon the individual being examined and the positioning of the electrodes but the general waveform is shown above. The initial ‘P’ wave is due to the heart’s atria (upper input chambers) depolarising, while the relatively larger and narrower ‘QRS complex’ section is due to the much stronger ventricles (lower output chambers) depolarising. Finally the ‘T’ wave is due to repolarisation of the ventricles, ready for another cycle. Doctors are able to evaluate a number of heart problems by measuring the timing of these wave components, and their relative heights. They can also diagnose problems by comparing the way the wave components change with the various standard electrode and lead connections (as shown below). L V1 V2 V3 V4 CHEST CROSS-SECTION V5 V6 SINO-ATRIAL (SA) NODE HEART STANDARD CONNECTION POINTS V6 V5 V1 F V2 V3 V4 LEAD NAME ELECTRODE 1 ELECTRODE 2 LIMB LEAD 1 L R LIMB LEAD II F R LIMB LEAD III F L LEAD aVR R L+F R+F LEAD aVL L LEAD aVF F R+L PRECORDIAL (x6) V1 — V6 R+L+F February 2005  19 standard diecast aluminium box measuring 119 x 93 x 34mm. The box is used upside down, with the PC board assembly mounted component-side down inside the main part of the box via four 6mm long M3 tapped Nylon spacers, with eight 6mm long M3 machine screws (four of them with countersink heads, passing through matching holes in the box). The two RCA Here’s the bottom of the case, which has become the top... connectors used for showing the end cutouts for the electrode leads and the the ECG electrode switch. Below right is the top of the case, which has leads are accessed become the bottom, showing the end LED and USB connector cutouts... Confused? All is explained in the text! through two 12mm diameter holes in analog circuitry are fed via a low-pass one end of the box, with miniature filter formed by RF choke RFC1 and the slider switch S1 mounted in a 5 x 100mF bypass capacitor. These remove 10mm rectangular hole at the same any digital switching noise from the end, fixed in the case via two 6mm ‘analog’ 5V rail. long M2 machine screws. When it is transmitting or receiving At the other end of the case are two data via the TxD or RxD lines, the 3.5mm holes for the indicator LEDs, USB-MOD3 interface module pulls plus a 13 x 11.5mm rectangular hole down its TXLD (pin 17) or RXLD (pin for access to the USB connector. 15) pins. LED1 and LED2 indicate bus Assembling the components on the activity. PC board is quite straightforward, as Although the complete Electrocar- the only surface-mount parts used diograph is housed in a metal box to are in the Elexol USB-MOD3 module, provide shielding, the metal box is not which comes prebuilt and tested. connected directly to the signal earth It’s in the form of a 32-pin DIL as you might expect. package with machined pins on Instead, it’s connected via a parallel standard 0.6” x 0.1” spacing, which combination of a 33kW resistor and a drop straight into matching holes 100nF capacitor, to provide current on the main PC board and are then limiting in the (unlikely) event of the soldered. earth connection of your PC becoming To protect it from broken and the signal earth of your possible damage computer and the Electrocardiograph however, the modbecoming ‘live’. ule shouldn’t be Even if you are touching a good earth mounted on the and the Electrocardiograph box at the board until you’ve same time in this situation, you should fitted all of the othbe safely protected from receiving er components. The anything more than a small ‘tingle’. component overlay diagram for the PC Construction board is shown in All of the Electrocardiograph Fig.3. circuitry except slider switch S1 You can begin is mounted on a PC board which assembly by fitting measures 107 x 81mm and coded the single wire link, 07102051. which goes in the The board assembly fits inside a centre of the board 20  Silicon Chip just above the location for IC3. Then fit the PC pins: two for the connections to switch S1 and one for the wire to the metal box itself. Then fit the two board-mounting RCA connectors CON1 and CON2. You may need to enlarge the slots in the board pads with a small jeweller’s needle file, before the connector lugs will pass through them to allow the connectors to mount down against the top of the board. Then the lugs are soldered to the board copper underneath to hold them securely in place. Next, fit the 18-pin IC socket for the PIC (IC5) which should be fitted with its notch end facing to the left, where the USB-MOD3 module will ultimately be fitted. Use a socket with machined pins, for higher reliability. Fit the resistors next, taking care to fit each one to the board in its correct position as shown in the overlay diagram. Then fit the multilayer monolithic and ceramic capacitors, again using the overlay diagram as a guide. The MKT capacitors and the 6.8mF nonpolarised electrolytic capacitor and the 4MHz crystal can be installed either way around. The remaining electrolytic capacitors are polarised, so make sure that you fit these with the orientation shown in the overlay diagram. Note that the 220mF electrolytic at the lower left corner of the PC board should be a low leakage type (RBLL). The two 1N4148 diodes (D1 & D2) go in almost the exact centre of the board, with opposite polarities. Then fit IC2, IC3 and IC4, all of which solder directly into the board. Make sure you fit them the correct way around, as shown in the overlay diagram. Then fit IC1, taking even more care, as it’s siliconchip.com.au rather more expensive. The two LEDs are fitted next. Their leads are left straight, and introduced to the PC board holes with the longer anode leads towards the right (as seen in the overlay diagram) and the ‘flat’ side of the LED bodies towards the left. The leads are then soldered to the pads under the board with the LED bodies held directly above and about 15mm above the board. This allows them to be bent outwards by 90° afterwards, so the bodies will protrude out through the matching holes in the box. Finally, you can drop the USBMOD3 module into place and solder its pins to the pads underneath. You don’t have to solder all of its pins; just those where the main PC board pad is connected to a track or the earth copper. These will be sufficient to make all necessary connections and hold the module securely in place. Preparing the box There aren’t very many holes to cut in the aluminium box, but those there are should be located and cut accurately so that the PC board assembly and slider switch S1 will mount inside it without problems and the complete assembly can be connected easily to the ECG electrode leads and the USB cable. The location and size of all holes needed in the box are shown in the drilling diagram of Fig.4. Final assembly Use four countersink-head M3 screws to attach the four M3-tapped Nylon spacers to the inside of the box. Tighten these screws fairly tightly, because their heads become inaccessible when the dress front panel is attached later. Now fit the PC board assembly into the box. You’ll find it necessary to push the RCA connectors further through their box holes than their final position, to allow you to swing the USB module/LEDs end of the board down into the box. Once the board is sitting on the spacers you can slide the board back until its mounting holes are correctly aligned over the spacers. Then fit the four remaining M3 x 6mm screws, to attach the board assembly securely inside the box. Once this is done you should be able to push the two indicator LEDs out through their matching 3.5mm holes, so they’ll be visible when the box is closed. siliconchip.com.au Parts List – USB Electrocardiograph 1 PC board, code 07102051, 107 x 81mm 1 diecast aluminium box, 119 x 93 x 34mm 1 Elexol USBMOD3 USB interface module (www.elexol.com) 2 RCA sockets, PC board mounting (CON1,2) 1 1mH choke (RFC1) 1 4MHz crystal (X1) 1 miniature DPDT slider switch (S1) 1 18-pin DIL socket, with machined pins 2 6mm x M2 machine screws, round head 4 6mm x M3 tapped Nylon spacers 4 6mm x M3 machine screws, countersink head 4 6mm x M3 machine screws, round head 1 9mm x M3 machine screw, countersink head 1 M3 nut with two star lockwashers 1 solder lug 3 1mm PC pins Semiconductors 1 AD623 instrumentation op amp (IC1) 1 LM358 dual op amp (IC2) 1 LM311 comparator (IC3) 1 74HC245 octal transceiver (IC4) 1 PIC16F84A microcontroller (IC5) programmed with ECGSAMPL.hex 1 3mm green LED (LED1) 1 3mm red LED (LED2) 2 1N4148 diodes (D1,D2) Capacitors 1 220mF 50V RBLL low leakage electrolytic 2 100mF 16V PC electrolytic 1 10mF 16V PC electrolytic 1 6.8mF NP electrolytic 4 1.0mF MKT polyester 8 100nF multilayer monolithic 1 47nF multilayer monolithic 2 1nF NPO disc ceramic 2 33pF NPO disc ceramic Resistors (0.25W 1% metal film) 2 220kW 1 100kW 1 33kW 1 11kW 9 10kW 1 8.2kW 2 3.0kW 1 2.7kW 1 1.8kW 1 1kW 2 220W 1 100W 11 20kW 2 3.9kW 1 1.2kW 1 82W For making two ECG electrodes: 2 insulated RCA plugs (1 red, 1 black) 3 metres of figure-8 shielded stereo cable 2 50 x 30mm rectangles of blank PC board (see text) 4 Nylon cable ties 2 40mm lengths of 20mm wide Velcro hook strip 2 350mm lengths of 20mm wide Velcro felt strip 2 25mm lengths of 4mm diameter heatshrink sleeving The next step is to prepare the box ‘earthing’ connection. This is done by passing a 9mm x M3 countersink-head machine screw through the single hole on the side of the box, close to the terminal pin on that side of the mounted PC board. Then to the inside of the screw fit a star lockwasher, a solder lug, another star lockwasher and finally an M3 nut. The screw and nut should then be tightened up very firmly, so the solder lug becomes a good and reliable electrical connection to the box metalwork. The lug is then connected to the nearby PC pin, using a February 2005  21 6.25 16 NOTE: ALL DIMENSIONS IN MILLIMETRES B CASE OUTSIDE DIMENSIONS 92 x 119 x 35 INCLUDING LID 11.5 B 6.5 18 11.25 36.75 36.75 A 13 A A: B: C: D: 43.25 HOLE DETAILS: 3.5mm diam (CSK) 3.5mm diam 12mm diam 2.5mm diam L 43.25 34 C 10 A A A 9 17.5 8.5 19 D D C 13 12 C 10 16 Fig.4: drilling details for the diecast aluminium box. The hole and cutout positions must be accurate to accommodate the PC board. Inset below: a pair of commercial ECG pads as supplied by First Aid Plus. These are self-adhesive and really, really stick! (LID) L C short length of tinned copper wire or a resistor lead offcut. Make sure both ends are soldered properly. Then mount slider switch S1 in the end of the box, using two M2 x 6mm screws and connect the centre and leftmost switch lugs to the PC pins immediately behind them, using short 22  Silicon Chip lengths of tinned copper wire or resistor lead offcuts. Now plug your programmed PIC micro IC5 carefully into its socket up near the top of the board and then attach the box lid via the four screws provided. The final step is to apply the front panel to the bottom of the box, which then becomes the top. The artwork for the dress front panel is reproduced in this article, actual size (see Fig.5). It can be photocopied onto a sheet of A4 self-adhesive label paper and then covered with clear ‘Contact’ or siliconchip.com.au similar adhesive film, before being cut out along the outline border. Then the backing paper on the back of the label can be peeled off, allowing the dress panel to be stuck on the top of the Electrocardiograph box. The adhesive film covering will protect the panel from finger grease and dirt. If you want the colour version and don’t have access to a colour copier, the file can be downloaded from www. siliconchip.com.au and printed on a colour inkjet or similar, then applied as above. You might also want to fit four small adhesive rubber feet to the lid/base of the box, so it won’t scratch any surface it’s placed on. The electrodes: buy or make? It goes without saying that the best electrodes you can use with this device are those intended for the purpose. Unlike the adhesive electrode pads made for TENS machines, ECG pads are disposable items and are therefore relatively cheap (only a couple of dollars or so each) but like TENS pads, are fairly difficult to find and usually have high minimum order quantities (eg, 50 minimum). We’ve managed to track down one source from a first aid supplies company in Sydney, First Aid Plus, who will sell them by mail order in small quantities – six pads for $10 including postage. ECG pads are almost always removable from their leads – they usually use a press-snap type of fitting. We suggest you obtain pads with the male snap on them, as this gives you a convenient “nipple” on which to clip a small alligator connector. First Aid Plus will assume you want male snaps and supply those unless specifically asked for female. Contact First Aid Plus at PO Box 37, Harbord, NSW 2096. (Phone 02 9905 0155); website www.firstaidplus. com.au If you don’t want to buy pads, or find it inconvenient, there is an alternative “pad” or electrode which you can make yourself. It’s not as efficient nor convenient but once made, should last perhaps indefinitely. Its made from a small rectangular piece of blank PC board. The details are shown in Fig.7. Note that the shield braid wires of each lead are bent back away from the centre conductor and then insulated with a sleeve of 4mm OD heatshrink sleeving so they can’t come into contact with either the centre wire or the human subject. Then the centre wire is passed through the small hole in the electrode and soldered to the copper underneath, after which the end of the lead is firmly secured to the electrode using two small Nylon cable ties, each of which passes through one of the 3mm holes on the side. As you can see from the circuit of Fig.1, the electrode leads are made from shielded microphone cable. The two leads should be of equal length, to maintain the balance of the ECG Electrocardiograph’s input stage. The home-made electrodes are held SAFETY WARNING The circuit of this USB ECG is directly connected to the PC which controls it, via the USB cable. Although no optical isolation is fitted, the electrodes which connect to the skin of the human subject are capacitively coupled and also have significant resistance connected in series with them. This means that even if the PC’s earth connection becomes broken and its power supply also develops a direct short circuit to active 240VAC (a very unlikely chain of events), the potential current which could flow through the body between the electrodes is very small and highly unlikely to cause injury. However if you are concerned about this small safety risk, there are two steps you can take to ensure that the USB/ECG project is used with virtually complete safety: (1). Always ensure that the human subject to which the ECG electrodes are connected is insulated from earth and unable to contact any earthed (or ‘live’) metalwork. (2). If insulation of the subject can not be achieved, connect and use the USB ECG only with a laptop computer running from batteries – rather than a desktop or laptop PC running from 240V AC. As used in the ECG project in this issue . . . Elexol’s USBMOD3 USB Interface Here’s some more of our range of USB and MP3 modules: 2nd Generation USB Plug and Play Need to get data into serial development module or out of a USB port? Try this second generation, Low Cost USB Data I/O Module 24 independently programmable Input/Output pins grouped into 3 ports. Single module high-speed digital Input/Output solution. Up to 128 modules can be connected to a single PC with capabilities of further expansion. Easy to connect by 0.1” pitch headers to suit standard IDC connectors. Integrated Type-B USB connector. On-board unique serial number in EEPROM and custom programmable FLASH microcontroller. Both USB enumeration information & microcontroller can be re-programmed to suit customer needs. Module powered by the USB from the PC. USB MOD1 - 100k baud (RS232) 300k baud (RS422/RS485) USB MOD2 - USB MOD4 - USB Plug and Play USB Plug and Play Parallel USB Plug and Play Parallel 8-Bit FIFO 8-Bit FIFO Serial Development Development Module. Development Module (2nd Module. Up to 920k baud Gen). Up to 8 Million bits (RS232) and 2000k baud Up to 8 Million bit (1 Megabyte) per sec. (1Megabyte) per second. (RS422/RS485). MP3 MOD4 - VS1001 chip. Converts clocked serial data (MP3) to stereo audio out. Suitable for driving headphones. Visit our web shop <at> www.elexol.com Elexol Pty Ltd Ph: (07) 5574 3988 Fax: (07) 5574 3833 (PO Box 5972, Bundall, Qld 4217) siliconchip.com.au February 2005  23 against the subject’s skin with Velcro strips. A 40mm length of 20mm wide Velcro hook strip is attached to the top of each electrode using a small amount of epoxy adhesive (eg, Araldite). One end of a 350mm length of the matching felt strap is attached to one half of the hook strip. The strap can be run around the subject’s forearm or ankle, pulled reasonably tight and then pressed into the ‘other half’ of the hook strip to hold the electrode in place. It’s very simple but it works surprisingly well. By the way, you need to make sure that the copper side of the electrodes is kept clean and bright, so it can form a good electrical contact with the skin. Each time the electrodes are applied to a subject you also need to apply some conductive liquid or paste to both the electrode copper and the skin underneath – again to ensure a good contact. This normally applies to commercial pads too. A convenient liquid to use is sodium chloride or saline solution, which is available at low cost from most pharmacists. Just wet a small piece of cotton wool with this and use it to apply a fairly generous amount to both the RECEIVE TRIGGER SEND DATA electrode and the subject’s skin where it’s being placed. Installing the software As mentioned earlier, there are two pieces of software which need to be installed on your PC before it will be able to communicate with and control the Electrocardiograph. There’s the Electrocardiograph control program itself, written in Visual Basic 6. There’s also a special ‘USB virtual COM port driver’ which allows Windows and the control program to communicate with the Electrocardiograph via its USB-MOD3 interface module and one of the PC’s USB ports. The VCP driver has been written by the makers of the main USB interface controller chip in the Elexol USB-MOD3 module, an FT232BM device made by Scottish firm Future Technology Device International (FTDI). A copy of FTDI’s VCP driver will be available for downloading on the SILICON CHIP website (www.siliconchip. com.au). It’s also available directly from the FTDI website (www.ftdichip. com) and updated versions of it may be available there as well in the future. The actual driver file is included in the download file (R9052154.ZIP) which also contains a PDF document explaining how to install and configure it. Basically the procedure is to download the ZIP file and unpack it using Winzip or PKUnzip onto a suitable subdirectory on your PC’s hard disk. Then when you first connect the hardware box up to your PC via a USB cable, and Windows comes up with its ‘Found New Hardware Wizard’ dialog box, you direct the wizard to the subdirectory where the driver package was unpacked, and tell it to refer to the file FTDIBUS.INF. It will then install the VCP driver for you. After this is done it’s a good idea to open up the Device Manager panel to set the port settings. The method is different for different versions of Windows. As we mentioned before, Windows NT is a no-go, as is Win95 (for the same reason). Under Windows 98SE, open Control Panel (-> System Properties -> Device Manager), where you’ll find a USB Serial Port device listed under USB High Speed Serial Converter. Select this port device, and click on Properties. Then under the Port Settings tab select 38,400 bits per second, 8 data bits, None for parity, 1 stop bit and USB TO PC +5V LEAD 1 C 2005 07102051 + ELE R A C O R T C H P A R DIOG SILICON CHIP GAIN LEAD 2 LOW HIGH Fig.5, the full-size front panel, along with, along with Fig.6, the PC board pattern (also full size). If you don’t have access to a colour photocopier, download the panel from www.siliconchip.com.au and print it on a colour inkjet. 24  Silicon Chip siliconchip.com.au Taking an ECG Apart from the gain - which is set to either LOW (2000) or HIGH (4000) using slider switch S1, all other functions of the Electrocardiograph are controlled using the ECGSampler program. This is very easy to use because when you fire it up, it provides a GUI window (see screen grab) which allows you to set the configuration or to start it taking an ECG recording and then displaying, saving and printing it. There are three drop-down menus at the top, with the labels ‘File’, ‘Settings’ and ‘About’. The first menu is for saving, reloading or printing ECG records, while the second is for changing various USB port and settings: the virtual COM port, the COM port settings (bit rate, parity, stop bits etc.), the sampling rate (500, 1000 or 2000 samples/second) and also for advising the software on which position the gain switch has been set (Low/2000 or High/4000). siliconchip.com.au 5 A BLANK PC BOARD LAMINATE (COPPER SIDE DOWN) 50 B 26 Fig.7 if you want to make your own electrodes (pads) here’s how to do it from a couple of scraps of PC board. The advantage – they’re dirt cheap. The disadvantage: they get dirty (tarnished) very easily and need to be cleaned before use. 3. SOLDER CENTRE CONDUCTOR TO COPPER (UNDERNEATH) 1. REMOVE 10mm OF OUTER INSULATION & BEND SHIELD BRAID BACK 2. FIT HEAT SHRINK TO COVER BRAID 4. SECURE CABLE USING NYLON CABLE TIES B 10 Xon/Xoff for flow control. Finally click on the Advanced button, and select COM5 as the port number. This forces the VCP driver to make its USB virtual COM port COM5, so there shouldn’t be any clashes with any existing COM ports. If you’re using XP, go to Control Panel, ->System -> Hardware ->Device Manager, -> Ports (COM & LPT) where you should find the “USB Serial Port” (probably set to COM4). Click on this and then “Port Settings” and proceed as per Win98 (including the Advanced tab). Now let’s turn to the Visual Basic control program for the USB Electrocardiograph. This is available for downloading from the SILICON CHIP website as a zipped-up installation package called ECGCONTR.ZIP. Inside this package are the CAB files for the program and its various support components and an installation program Setup.exe together with its ‘instruction sheet’ SETUP.LST. Download the package and unpack it on a TEMP directory. Then doubleclick on the Setup.exe file so that it installs everything, on a suitable subdirectory of your Program Files directory. If you wish you can also create a shortcut on your Desktop, called SILICON CHIP ECG or similar. The shortcut simply needs to be linked to the installed VB program itself, called ECGSampler.exe. 15 30 ALL DIMENSIONS IN MILLIMETRES CABLE TO RCA PLUG & ECG SAMPLER HOLE A: 1mm DIA. HOLES B: 3mm DIA. The third drop-down menu displays a small dialog box showing the version number of the software itself. Once you have made sure that the software is set up correctly to suit the USB port and the Electrocardiograph, taking an ECG is then simply a matter of choosing which lead configuration you want, applying the electrodes to your subject (or yourself), and then clicking on the ‘Start Sampling’ button on the left-hand side of the GUI window. A graphical ‘progress bar’ will then appear along the bottom of the GUI beneath the main display window, to show you the progress as the ECG samples are taken. When all of the 8192 samples are received back from the Electrocardiograph, the progress bar will display again more briefly, as the ECG record is plotted in the display window. The display window is calibrated in terms of both ECG voltage and time, as shown in the screen grab. The same calibrations are reproduced when the record is printed out, along with the date and time – and when you save the record to your hard disk (or a floppy), the calibration info is saved with it as well. So once you’ve taken an ECG record, it’s easy to work out such things as the subject’s current heart rate or other aspects of the ECG waveform. Lead configurations Finally, which lead configuration should you use, just to take a basic look at your own ECG or that of someone else? We suggest you use the ‘Lead II’ limb configuration, with lead 1 connected to the subject’s left ankle and lead 2 connected to their right wrist or inside forearm. This usually gives the largest waveform amplitude, providing your electrode-skin connections are good. (See the diagram in the sidebar, “Your heart and its electrical activity.”) If you get weak waveforms with a relatively large amount of hum, this is usually a sign of poor electrode contact. So take them off, apply a bit more saline solution and try again. The exact positioning of the limb electrodes is not critical, as the limbs are really being used as convenient ‘conductors’ joined to the four ‘corners’ of the subject’s trunk. The main thing is to get the best possible contact to the skin. If you want to try some of the chest positions for the lead 1 electrode, the electrode positions are then fair­ly critical. You really need medical knowledge to know the right chest electrode positions, so it’s best to leave these to the professionals. Note that when lead 1 is being used with a chest electrode, lead 2 should be connected to electrodes in all three of the limb positions so that it provides a ‘whole body’ reference signal. So you’ll need to make up at least two more electrodes, and connect these all in parallel – by connecting them to the Electrocardiograph’s CON2 input socket via leads of the same length as the original two electrode leads. If you really want to play around with all of the lead configurations, or you’re a medico who wants to use the USB Electrocardiograph for serious diagnostic work, you might want to make up a set of nine electrodes and leads, plus a small switch box to allow you to select any of the standard lead configurations at will. SC February 2005  25