Intermediate
30 min

Monitor your heart's activity with AD8232 and PIC32MZ2048EFH100

ECG - your window to wellness

ECG 5 Click with Flip&Click PIC32MZ

Published Jul 18, 2023

Click board™

ECG 5 Click

Dev. board

Flip&Click PIC32MZ

Compiler

NECTO Studio

MCU

PIC32MZ2048EFH100

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

Flip&Click PIC32MZ is a compact development board designed as a complete solution that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC32MZ microcontroller, the PIC32MZ2048EFH100 from Microchip, four mikroBUS™ sockets for Click board™ connectivity, two USB connectors, LED indicators, buttons, debugger/programmer connectors, and two headers compatible with Arduino-UNO pinout. Thanks to innovative manufacturing technology,

it allows you to build gadgets with unique functionalities and features quickly. Each part of the Flip&Click PIC32MZ development kit contains the components necessary for the most efficient operation of the same board. In addition, there is the possibility of choosing the Flip&Click PIC32MZ programming method, using the chipKIT bootloader (Arduino-style development environment) or our USB HID bootloader using mikroC, mikroBasic, and mikroPascal for PIC32. This kit includes a clean and regulated power supply block through the USB Type-C (USB-C) connector. All communication

methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, user-configurable buttons, and LED indicators. Flip&Click PIC32MZ development kit allows you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Flip&Click PIC32MZ double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

2048

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

524288

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
RB11
AN
NC
NC
RST
Chip Enable
RA0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Lead-off detection for IN-
RC14
PWM
Lead-off detection for IN+
RD9
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

ECG 5 Click Schematic schematic

Step by step

Project assembly

Flip&Click PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Flip&Click PIC32MZ as your development board.

Flip&Click PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Flip&Click PIC32MZ MB1 Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

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

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @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

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.