HOW TO INTERFACE THE ECG FRONT END WITH A PIC12F1822 AND A PC
Updated: Sep 26, 2020
This is Part 2 of the series demonstrating how to interface the ECG Front End in a practical way. In Part 1 it was shown how to interface with a 128x32 graphic display. This time it will be shown how to read the signal and send it serially to a PC over USB and display the data on screen. You can download the VB.Net source code, PIC firmware, and schematic at the end of this article.
A quick disclaimer:
The ECG Front End is for educational purposes and should NOT be used for diagnostic or life saving operations of any sort. Suitability for a given application is the responsibility of the user. Always consult a qualified medical professional for any health related concerns.
To begin, a brief overview of the hardware. As in Part 1, it has three main sections with the first two common to both examples; The ECG Front End, a PIC12F1288 microcontroller, and an FTDI USB to UART converter.
The firmware for the PIC is quite a bit simpler for this demonstration since none of the routines needed to draw all the graphics are needed. Program flow is very straight forward in this case:
Initialize peripherals and set baud rate to 19,200
Start Main Loop
Read an 8 bit value from RA4 with oversampling
Send the value to the PC
Check for pulse detection and turn on the LED if detected
Wait 1/60 second
Loop and do again
The subroutines consist of a READADC method that has the capability of oversampling. Default is 8x but can be any power of 2 from 1 to 128. This will help reduce the noise floor for a cleaner signal but can blunt the signal when oversampling is set to the higher values.
The CHECKPULSE method compares the measured value to the threshold value and triggers the LED to turn on or off.
Finally there is the DELAY60 routine to wait 1/60 second for the next sample to be taken.
On the PC side the software is written using VB.Net and simply takes an 8 bit incoming data stream from a COM port and displays it graphically on screen.
The main areas here are the Horizontal Speed which changes how fast the program draws from left to right. In other words, how many beats you will see in the display area. The Digital Gain takes each sample, subtracts 128, multiplies it by the digital gain value and adds 128. This has the effect of boosting the signal but also the noise. The Offset value is added to the data to shift it up or down in the display. Since there is slight differences between each ECG Front End center output due to Op Amp variations, this can center any offset. Finally there is a Threshold value not shown in the image which is used to determine a heart beat and calculate heart rate. Default is 75%, so any data value after digital gain has been applied of 191 or greater (255 * 0.75) will trigger a beat detection.
Hopefully this short article and the previous one will give you a jumping off point for your own project. The full VB.Net source code, firmware, and schematics can be downloaded below. If there is more you would like to see or explained, be sure to let us know. And subscribe to be notified so you won't miss any future posts!