You are here: Home Blog MediFormatica's BLOG Tiny ECG Primer

Mediformatica - The Medical Informatics Portal

Mediformatica - The Medical Informatics Portal

Latest Blog Articles

Tiny ECG Primer

E-mail Print PDF
ECG PrimerThis project is for detecting human ECG (Electrocardiogram, or EKG). A tiny amplifier is embedded (<1mA). The on-chip Timer, ADC and DMA (double buffering) are used for getting ECG data. An IIR filter and hardware LCD scrolling are used for ECG rendering. User can simply touch the Primer by 2 hands, his/her ECG trace is scrolling alive on the LCD screen. The instant heart rate is displayed with beep sound and LED flashing. The device also delivers and displays the ECG on a PC through the USB cable.

The ECG Primer is a STM32 Primer with two copper foils placed on each side of the front circle. These two metal foils are the ECG electrodes. User can place his/her both thumbs on the copper foil to start the operation. The ECG trace is scrolling on the LCD display. The heart rate calculated and display on the top of the LCD display while the LED and beep sound indicating the pulse detected.

The ECG Primer consists of an extern ECG amplifier circuit for signal conditioning, the STM32 on-chip mixed signal processing peripherals for the data acquisition resources and the software handler for rending the ECG data and delivering ECG data to the USB port.

ECG Primer 

ECG Data Acquisition
The ECG signal is digitized by ADC1 (channel 2, AIN2). The sampling rate is 480/sec. ADC1 is set to the single conversion mode with the external event triggering the conversion. The conversion trigger source is the Timer1 (TIM1) channel 1. The prescaler of TIM1 is set to 24 while the modular register (Auto-reload register TIM1_ARR) is set to 6250. The system clock frequency is 72MHz and the TIM1 channel output is 72MHz / 24 / 6250 = 480 Hz. DMA channel 1 is setup for transfer the ADC sampled data from the ADC regular data register (ADC_DR) to a memory buffer. The memory buffer size is 240 bytes to hold 120 16-bit data entries, which is size for a period of ¼ second. The DMA Half-Transfer-Interrupt (HTIE), Transfer-Complete-Interrupt (TCIE) and destination memory address auto-increment mode are enabled. The DMA channel 1 destination address is increased each time a sampled data is transferred to the memory buffer until it reaches to the end of the buffer. Then the DMA is automatically wraps the destination address back to the beginning of the memory buffer to form a circular buffer scheme. The double buffering (or so called Ping-Pong buffering) is made by the dual interruptions. When the memory buffer is filled with half of the buffer size data, the Half-Transfer-Interrupt flag (HTIF) is set and signal an interruption. The interrupt service routine (ISR) is activated and a global pointer (for ECG data rendering) is set to point the beginning of the memory buffer. The data in first half of the memory buffer (60 data entries), therefore, is being processed by the ECG data rendering procedure (in the Application_Handler function) while the DMA continue transferring the ADC sampled data to the second half of the memory buffer. When the memory buffer is full, the Transfer- Complete-Interrupt flag (TCIF) is set and there ISR is activated again. At this time, the global pointer is pointing to middle of the memory buffer. So the ECG data rendering procedure processes the data in second half of the memory buffer while the DMA continues transferring the DAC sampled data to first half of the memory buffer. In this way, the data acquisition and data rendering is decoupled without pending each other. The chunk of the buffered data (representing the period of 1/8 second) is served at 8 Hz.


USB Data Transfer
Besides drawing the ECG trace on the LCD display screen, the device also sends the ECG data to a PC through the USB port (the USB port behind the pushbutton). The USB data transfer is using the Human Interface Device (HID) class. The code implementation references the PrimerMouse project posted on the website. The HID report descriptor is rewritten. Instead of the predefined mouse and pointer device, the report descriptor usage page and the usage are vendor defined classes. The input report size set to 16 for the16-bit ECG data and the report count is set to 60 for sending the entire block of the ECG data at once. Other descriptors are also modified accordingly. When the block of ECG data is ready, besides the trace rendering the Application_Handler function also copies the ECG data to the 512-byte USB dedicated SRAM memory for the input report at Endpoint 1. Because the data block is ready every 128 ms (in 8 Hz), the interrupt (polling) interval is set to 64 ms for guaranteeing there is no missing for the input report. When the device senses the report request, if the data is ready the device sends the data to the host PC.
PC USB Handler and ECG Display Software
The PC USB handler and ECG display program is written in Windows .NET environment using the C# language. Figure 6 is screenshot of the PC host GUI. Since the PC software development is not in the scope of the contest, detail description is omitted. However, the PC software executable is provided in the uploaded zip file (require .NET framework 2.0 or later installed).
ECG Primer 

You can get more information here

Last Updated ( Tuesday, 24 June 2008 21:49 )  

Google Translate


DrugFormatica provides a simple drug database providing information about FDA approved medications.
ProcFormatica provides a simple medical procedures database including information about the latest ICD-10-PCS codes.
PsychFormatica provides a simple medical procedures database including information about the latest DSM IV codes.

Healthcare IT in Egypt

In this section you'll find a list of companies and organizations working in the healthcare IT sector in Egypt.

Read more here...


Who's Online

We have 44 guests online


Members : 1
Content : 543
Web Links : 68
Content View Hits : 3127664




Medical Informatics

Medical informatics has to do with all aspects of understanding and promoting the effective organization, analysis, management, and use of information in health care.


Hospital Information Systems

A Hospital Management Information Systems (HMIS) is a comprehensive, integrated information system designed to manage the administrative, financial and clinical aspects of a hospital.



Mediformatica's videos section is rapidly becoming one of the largest health informatics video libraries linking to over 250 videos to this date...


Mediformatica's Blog

Mediformatica's Blog is frequently updated with the latest and most exciting news and reviews related to the subject of Medical Informatics.