Intermediate
30 min
0

Monitor your heart's activity with AD8232 and PIC18LF46K80

ECG - your window to wellness

ECG 5 Click with EasyPIC v7

Published Nov 01, 2023

Click board™

ECG 5 Click

Development board

EasyPIC v7

Compiler

NECTO Studio

MCU

PIC18LF46K80

The perfect solution for athletes and fitness enthusiasts, providing advanced monitoring and analysis of heart rate variability during exercise

A

A

Hardware Overview

How does it work?

ECG 5 Click is based on the AD8232, an integrated heart rate monitoring front-end, by Analog Devices. This IC is targeted toward wearables and battery-operated applications. The heart-rate impulses are naturally weak and in the range of just a few millivolts, even microvolts. Therefore, any external interference might obscure them. The interferences might be induced in the human body itself, or they might appear as the result of the activity of other muscles, such as skeletal muscles. Therefore, the input signal from the electrodes is processed by several filtering sections until it is amplified to a value suitable for sampling. However, the correct placement of the measurement electrodes is crucial for accurate readings. ECG 5 Click features a 3.5mm jack connector connecting three electrodes. One of the electrodes is a so-called right leg drive electrode (RLD), used to set the patient's body to the same potential as the rest of the system. In addition, it is used to reduce the noise resulting from the human body acting as an antenna (picking up

50/60Hz hum from the mains). Along with the integrated 2-pole high-pass and RFI filtering sections, the IC effectively reduces the overall system noise. Lead-off detection is very important for accurate ECG measurements. Therefore, this IC is equipped with the dedicated LOD pin, set to a HIGH logic level when any of the electrodes is missing. Lead-off circuitry is a comparator that ensures the body stays within 0.5V from the positive rail. By featuring two separate LOD pins, it is possible to determine the exact electrode that may be missing. In DC lead-off detection mode, all three electrodes must be connected. The LOD+ is routed to the mikroBUS™ INT pin, while the LOD- is routed to the mikroBUS™ PWM pin. The pins are labeled as LO+ and LO- respectively, on this Click board™. Due to the signal filtering within the AD8232 IC, the settling time for the connected electrodes may be too long. Therefore this IC features the fast restore option (FR pin is pulled to a HIGH logic level on ECG 5 click), which dynamically sets the cutoff frequency

to a higher value, speeding up the settling time, which may be in the magnitude of several seconds (for example, when the electrodes are connected). The IC can be driven to a low power consumption mode. If the SDN pin is pulled to a LOW logic level, the IC will enter the standby mode, greatly reducing the power consumption. Utilizing the LOD pins, the MCU can be programmed to enter the standby mode along with the AD8232, which is ideal for battery-powered applications. SDN pin is routed to the mikroBUS™ CS pin and is labeled as SDN. The OUT pin of the AD8232 is routed to the AN pin of the mikroBUS™. It provides the amplified and filtered signal from the electrodes, which can be used directly on the A/D peripheral of the host MCU. The AD8232 can drive both resistive and capacitive loads, so no additional buffering IC is required. In addition, ECG 5 click is equipped with a LED labeled as ECG, which can be used as a visual indicator of the output signal.

ECG 5 Click top side image
ECG 5 Click bottom side image

Features overview

Development board

EasyPIC v7 is the seventh generation of PIC development boards specially designed to develop embedded applications rapidly. It supports a wide range of 8-bit PIC microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB-B. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyPIC v7 allows you to connect accessory boards, sensors, and custom electronics more efficiently than ever. Each part of

the EasyPIC v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use various external power sources, including an external 12V power supply, 7-23V AC or 9-32V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B) connector. Communication options such as

USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from PIC10F, PIC12F, PIC16F, PIC16Enh, PIC18F, PIC18FJ, and PIC18FK families. EasyPIC v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyPIC v7 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

3648

You complete me!

Accessories

3-wire ECG/EMG cable comes with a convenient 3.5mm phone jack, and it is designed for electrocardiogram recording. This 1m cable is a practical companion for medical professionals and enthusiasts. To complement this cable, you can also use single-use adhesive ECG/EMG electrodes measuring 48x34mm, each equipped with an ECG/EMG cable stud adapter. These electrodes ensure a seamless experience when paired with our ECG/EMG cable and guarantee reliable ECG/EMG signal transmission for comprehensive cardiac monitoring. Trust in the accuracy and convenience of this setup to effortlessly record electrocardiograms and electromyograms with confidence.

ECG 5 Click accessories image

Used MCU Pins

mikroBUS™ mapper

Analog Output
RA2
AN
NC
NC
RST
Chip Enable
RE0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Lead-off detection for IN-
RC0
PWM
Lead-off detection for IN+
RB0
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

ECG 5 Click Schematic schematic

Step by step

Project assembly

EasyPIC v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v7 as your development board.

EasyPIC v7 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v7 Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for ECG 5 Click driver.

Key functions:

  • ecg5_setMode - Mode Setting function

  • ecg5_check_LOD_negative - LOD- Checking function

  • ecg5_check_lod_positive - LOD+ Checking function

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief ECG 5 Click Example.
 *
 * # Description
 * This is an example which demonstrates the use of ECG 5 Click board.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes ADC and GPIO.
 *
 * ## Application Task
 * Reads ADC value and sends results on serial plotter every 5 ms.
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "ecg5.h"

static ecg5_t ecg5;   /**< ECG 5 Click driver object. */
static log_t logger;    /**< Logger object. */
static uint32_t time;

void application_init ( void ) {
    log_cfg_t log_cfg;  /**< Logger config object. */
    ecg5_cfg_t ecg5_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    ecg5_cfg_setup( &ecg5_cfg );
    ECG5_MAP_MIKROBUS( ecg5_cfg, MIKROBUS_1 );
    if ( ADC_ERROR == ecg5_init( &ecg5, &ecg5_cfg ) ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    log_info( &logger, " Application Task " );
}

void application_task ( void ) {
    uint16_t ecg5_an = 0;
    if ( ADC_SUCCESS == ecg5_read_an_pin_value( &ecg5, &ecg5_an ) ) {
        log_printf( &logger, " %u,%lu\r\n ", ecg5_an, time );
    }
    time += 5;
    Delay_ms( 5 );
}

void main ( void ) {
    application_init( );

    for ( ; ; ) {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources