top of page


Updated: Sep 26, 2020

ECG Front End Demo Circuit

This is the first of a two part series on using the ECG Front End in your own applications. In this part, we will explore a standalone design utilizing an 8 pin PIC12F1822 microcontroller connected to a Newhaven 128x32 pixel graphic display.

In the Second Part, we shall show a method utilizing the same microcontroller but instead of a graphic display, data will be transmitted serially to a PC to be drawn onscreen. The goal of both of these articles is to give the user of the ECG Front End a starting point for their own design and experimentation. A downloadable ZIP file containing the sourcecode for the PIC and a PDF of the schematic can be found at the bottom of this post. Click to buy our ECG Front End for your own design.

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.


With that out of the way, let's begin with the circuit.

ECG Front End Demo Schematic with PIC12F1822 and 128x32 Graphic Display

The circuit consists of three parts: the PIC12F1822, Graphic Display, and the ECG Front End.

Four pins connect the PIC to the display with a common reset line consisting of R1 and C1.

C3 thru C10 are used for proper operation of the display, R2 controls the display backlight current (which I found a little too bright at 100 ohms. A 220 ohm might be a better size) and C2/C11 are bypass capacitors for the PIC and display.

Finally, the ECG Front End has a simple three wire interface; Power, Ground and the Output which is connected directly to RA4 with no additional filtering on the PIC. No bypass capacitor is required since it is already contained on the ECG PCB. The sensors can be single wires with some sort of electrode end. In this demo, I used two short lengths of copper pipe connected by single conductor wire to the ECG Front End. With these pipes to be held one in each hand.

Power is supplied by a battery pack of 4 AA's and a 3.3 regulator is used to drop the voltage. A double AA pack would be able to connect directly to the circuit. Something to be aware of is if using a power supply connected to mains 120/240V, it may be necessary to connect GND to earth ground to eliminate possible noise that can bury the ECG signal and render it unreadable.


The code started off simple enough but quickly grew as the features were further expanded on. You can see in the GIF the circuit in operation. The key areas are the pulse rate in the top left corner with a flash of '*' during a beat as well as a graphic representation of the ECG on the screen. The sample rate was kept to 60Hz to further reduce the 60Hz line noise since if you sample at the same point on the mains cycle, it effectively dissapears. In addition, at 60Hz the display will show slightly more than two seconds of data.


Program flow is as follows:

  • Setup peripherals

  • Initialize display

  • Start Main Loop

  • Clear the current column on the display

  • Sample and read the 8 bit analog signal from the 10 bit measurement

  • Change the data from 8 bits (0-255) to 6 bits (0-63)

  • Adjust the data center from 32 to 16 by subtracting 16 from the data in order to center the signal in the display

  • If the adjusted data value falls below 0, set it to 0

  • Check for pulse detection

  • Determine which page on the display to draw on (0-3)

  • Determine which bit on that page to draw on (0-7)

  • Draw that pixel on the display and increment the column count

  • If the column count = 128, reset the column to 0 (left side of display)

  • Draw the current pulse rate in the top left corner (page 3, columns 8-32)

  • Wait 1/60 second and loop to top for next sample

As part of the main program, a number of sub routines needed to be coded as well:

  • Low level driver to access the display

  • A binary to BCD converted was needed for the heart rate

  • A data table containing all the pixel data for ascii characters. Most ASCII characters are available from 32-127

  • Methods to set page, set column, and set line on the display

  • A Print string method to write '0' terminated strings and writing single characters on screen

  • Pulse detection by comparing the measured value to a threshold value so when the signal spikes, a pulse is registered. In addition, this method determines pulse rate by counting the time between beats and calculating beats/minute

  • Finally, a 1/60 second delay and generic long delay used at startup

You can see from this circuit that it only takes a handful of parts to create a functioning ECG Front End capable of registering the waveform and determining the pulse rate. This pretty much maxes out the capabilities of this particular PIC but by using one with a few more I/O pins and memory, a capable device could be achieved with buttons for control and external memory to record data if desired and/or a real time clock.

For the complete source code and PDF of the schematic click the file download link below.

Click the link if you are looking to buy the ECG Front End for your own design.

In Part 2, we will see the same PIC12F1822 used only this time there will be no display and 8 bit data will be transmitted directly to a PC for processing. Full source code for both the PIC and PC using will be freely available as well.

ECG Front End Demo
Download ZIP • 114KB

159 views0 comments
bottom of page