Intermediate
30 min

Stay connected to your heart's rhythm with BMD101 and PIC18F86K22

Cardiovascular clarity: ECG excellence for a healthier you

ECG 4 Click with UNI-DS v8

Published Jul 01, 2023

Click board™

ECG 4 Click

Dev Board

UNI-DS v8

Compiler

NECTO Studio

MCU

PIC18F86K22

Elevate your heart's performance with our intelligent ECG solution

A

A

Hardware Overview

How does it work?

ECG 4 Click is based on the BMD101, a highly integrated specialized bio-signal sensing System-on-Chip (SoC) from NeuroSky, which produces heart-monitoring-related ICs and applications. This IC is the third generation of bio-sensors from this company. It features the complete HR and ECG system on a chip: the analog front-end (AFE) section contains a very precise and low-noise instrumentation amplifier (LNA), which allows very low bio-signals generated by the heart to be amplified enough for the 16-bit ADC to be able to sample them. These voltage impulses are naturally weak and in the range of just a few millivolts, even microvolts. Therefore, any external interferences might obscure them. These interferences might be induced in the human body itself or 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, both in the analog (HP filter at the input) and digital domain (LP filter at 100 Hz and BP filter for removing the 50/60 Hz hum from the mains). However, the correct placement of the

measurement electrodes is crucial for accurate readings. More about the electrodes and their placement can be found in the blog article, as mentioned above. ECG 4 Click allows several types of electrodes to be used. It supports both stainless-steel and silver-chloride electrode types. The electrodes are used to perform differential measurements of the voltage generated by the heart. Therefore, the heart can be monitored from a single plane only - the coronal plane. However, this is quite enough for fitness, heart rate monitoring, and similar applications. The 3.5mm electrodes connector is further protected by two TVS diodes, which prevent electrostatic discharge (ESD) through the SoC and the Click board™. The absence of the electrodes is detectable by the BMD101, which turns the sensor OFF if there is approximately 19 to 25 MΩ between the electrodes. The BMD101 SoC uses the UART interface for communication. The UART interface works at a 57600 baud rate and has 64 bytes of TX FIFO. It uses the 8-1-1 configuration (1 start bit, 8 data bits, 1 stop bit), allowing communication beyond the

host microcontroller. The UART interface could be used with any USB to UART clicks, allowing the PC or smartphone to process and display the HR and ECG data. More information about the UART interface can be found in the datasheet of the BMD101 SoC. However, provided mikroSDK library offers ready-made functions which speed up the software development process. There is a CS pin on the BMD101 SoC, which is routed to the CS pin of the mikroBUS™. This pin should be set to a HIGH logic level to activate the internal power supply. The RESET pin is routed to the mikroBUS™ RST pin. Setting it to a LOW logic level will trigger a RESET of the BMD101. This Click board™ can only be operated with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board™ comes equipped with a library containing functions and an example code that can be used as a reference for further development.

ECG 4 Click top side image
ECG 4 Click bottom side image

Features overview

Development board

UNI-DS v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports a wide range of microcontrollers, such as different STM32, Kinetis, TIVA, CEC, MSP, PIC, dsPIC, PIC32, and AVR MCUs regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer over WiFi. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, UNI-DS v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the UNI-DS v8 development board contains the components necessary for the most efficient operation of the same board. An advanced integrated CODEGRIP programmer/debugger module offers many valuable programming/debugging options, including support for JTAG, SWD, and SWO Trace (Single Wire Output)), and seamless integration with the Mikroe software environment. Besides, it also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector. Communication options such as USB-UART, USB

HOST/DEVICE, CAN (on the MCU card, if supported), and Ethernet is also included. In addition, it also has the well-established mikroBUS™ standard, a standardized socket for the MCU card (SiBRAIN standard), and two display options for the TFT board line of products and character-based LCD. UNI-DS v8 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.

UNI-DS v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

80

RAM (Bytes)

3862

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 4 Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Chip Reset
PJ4
RST
Chip Enable
PJ0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
PG1
TX
UART RX
PG2
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

ECG 4 Click Schematic schematic

Step by step

Project assembly

Fusion for PIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI-DS v8 as your development board.

Fusion for PIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
v8 SiBRAIN 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 image step 7 hardware assembly
Necto image step 8 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 4 Click driver.

Key functions:

  • ecg4_uart_isr - Function performs the uart interrupt routine, reads a data from uart rx buffer and makes a response from the BMD101 device

  • ecg4_enable_ldo_ctrl - Function powers up or down control of LDO (Low Drop Out)

  • ecg4_generic_read - Generic read 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 
 * \brief Ecg4 Click example
 * 
 * # Description
 * This example reads and processes data from ECG 4 clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver, sets the driver handler and enables the click board.
 * 
 * ## Application Task  
 * Reads the received data and parses it on the USB UART if the response buffer is ready.
 * 
 * ## Additional Function
 * - ecg4_process - The general process of collecting data the module sends.
 * - plot_data - Displays raw ECG data.
 * - log_data - Displays the real time BPM heart rate.
 * - process_response - Checks the response and displays raw ECG data or heart rate (BPM).
 * - make_response - Driver handler function which stores data in the response buffer.
 * 
 * @note
 * Use the Serial Plot application for data plotting.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "ecg4.h"
#include "string.h"

// ------------------------------------------------------------------ VARIABLES

static ecg4_t ecg4;
static log_t logger;

static uint8_t response[ 256 ];
static uint8_t row_counter;
static uint8_t row_size_cnt;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void ecg4_process ( void )
{
    int32_t rx_size;
    char rx_buff;
    
    rx_size = ecg4_generic_read( &ecg4, &rx_buff, 1 );

    if ( rx_size > 0 )
    { 
        ecg4_uart_isr( &ecg4, rx_buff );
    }
}

void plot_data ( int16_t plot_data )
{
    log_printf( &logger, "%d;\r\n", plot_data );
}

void log_data ( uint8_t code_val, uint8_t data_val )
{
    if ( code_val == ECG4_HEART_RATE_CODE_BYTE )
    {
        log_printf( &logger, "** Real-time Heart Rate : %d BPM **\r\n", ( int16_t ) data_val );
    }
}

void make_response ( uint8_t *op_code, uint8_t *row_size, uint8_t *rx_buff, uint8_t *row_cnt )
{
    uint8_t idx_cnt;
    
    if ( *row_cnt == 0 )
    {
        row_size_cnt = 0;
    }
    
    response[ row_size_cnt ] = *op_code;
    response[ row_size_cnt + 1 ] = *row_size;

    for ( idx_cnt = 0; idx_cnt < *row_size; idx_cnt++ )
    {
        response[ row_size_cnt + 2 + idx_cnt ] = rx_buff[ idx_cnt ];
    }
    
    row_size_cnt += ( *row_size + 2 );
    row_counter = *row_cnt;
}

void process_response( )
{
    uint8_t cnt;
    uint8_t idx_cnt;
    int16_t raw_data;
    
    idx_cnt = 0;
    
    for ( cnt = 0; cnt <= row_counter; cnt++ )
    {
        if ( response[ idx_cnt ] == ECG4_RAW_DATA_CODE_BYTE )
        {
            raw_data = response[ idx_cnt + 2 ];
            raw_data <<= 8;
            raw_data |= response[ idx_cnt + 3 ];
            
            plot_data( raw_data );
        }
        
        if ( response[ idx_cnt ] == ECG4_HEART_RATE_CODE_BYTE )
        {
            log_data( response[ idx_cnt ], response[ idx_cnt + 2 ] );
        }
        
        idx_cnt += ( response[ idx_cnt + 1 ] + 2 );
    }
}

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    ecg4_cfg_t cfg;

    /** 
     * 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.

    ecg4_cfg_setup( &cfg );
    ECG4_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    ecg4_init( &ecg4, &cfg );

    ecg4.driver_hdl = make_response;
    Delay_ms( 500 );

    ecg4_module_reset ( &ecg4 );
    ecg4_enable_ldo_ctrl ( &ecg4, ECG4_ENABLE_LDO_CTRL );

    Delay_ms( 1000 );
}

void application_task ( void )
{
    ecg4_process(  );
    if ( ecg4_responseReady( &ecg4 ) )
    {
        process_response( );
    }
}

void main ( void )
{
    application_init( );

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


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

Additional Support

Resources