Intermediate
30 min

Accurately measure VCP parameters in real time using INA3221 and PIC18F2610

The future of Voltage-Current-Power monitoring

VCP Monitor 2 Click with EasyPIC v8

Published Nov 01, 2023

Click board™

VCP Monitor 2 Click

Dev Board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18F2610

Continuously monitor voltage, current, and power levels to ensure safe and efficient operation of electrical systems

A

A

Hardware Overview

How does it work?

VCP Monitor 2 Click is based on the  INA3221, a three-channel, high-side current and bus voltage monitor with alert indication function ensuring the intended application works within desired operating conditions fromTexas Instruments. It performs two measurements on up to three power supplies of interest (CH3 - CH1). The voltage developed from the load current passing through a shunt resistor creates a shunt voltage that is measured between the IN+ and IN- pins. The device also internally measures the power supply bus voltage at the IN- pin for each channel. The differential shunt voltage is measured with respect to the IN- pin, and the bus voltage is measured with respect to ground. The featured chip which is used for channel measurements, INA3221-Q1, is typically powered by a separate power supply that ranges from 2.7V to 5.5V. The monitored supply buses range from 0V to 26V. The INA3221-Q1 takes two measurements for each channel: one for shunt voltage and one for the bus voltage. Each measurement can be independently or sequentially measured, based on the Configuration mode settings. When the INA3221-Q1 is in the normal operating mode the device continuously converts a shunt-voltage reading followed by a bus-voltage reading. This procedure converts one channel, and then continues to the shunt voltage reading of the next enabled channel, followed by the bus-voltage reading for that channel, and so on, until all enabled channels have been measured. The programmed Configuration register mode setting applies to all channels. Any channels that are not enabled are

bypassed in the measurement sequence, regardless of mode setting. The INA3221-Q1 has two operating modes, continuous and single-shot, that determine the internal ADC operation after these conversions complete. When the INA3221-Q1 is set to continuous mode, the device continues to cycle through all enabled channels until a new configuration setting is programmed. The Configuration register MODE control bits also enable modes to be selected that convert only the shunt or bus voltage. This feature further allows the device to fit specific application requirements. In single-shot (triggered) mode, setting any single-shot convert mode to the Configuration register triggers a single-shot conversion. This action produces a single set of measurements for all enabled channels. To trigger another single-shot conversion, write to the Configuration register a second time, even if the mode does not change. When a single-shot conversion is initiated, all enabled channels are measured one time and then the device enters a power-down state. The INA3221-Q1 registers can be read at any time, even while in power-down. In addition to the two operating modes, the INA3221-Q1 also has a separate selectable power-down mode that reduces the quiescent current and turns off current into the INA3221-Q1 inputs. Power-down mode reduces the impact of the supply drain when the device is not used. Full recovery from power-down mode requires 40 µs. The INA3221-Q1 registers can be written to and read from while the device is in power-down mode. The device remains in power-down mode until one of the

active MODE settings are written to the Configuration register. VCP Monitor 2 Click also provides programmable thresholds that make sure the intended application operates within the desired operating conditions. Multiple monitoring functions are available using four alert pins: Critical, Warning, PV (power valid), and TC (timing control). The status of these alert pins are accessible over PCA9538A, a low-voltage 8-bit GPIO expander with interrupt and reset. The open-drain interrupt (INT) output is activated when any of the alert pins state has changed. This signal is used to inform the microcontroller that the bus voltage is not within the desired operating conditions. The PCA9538A uses the I2C communication protocol to read the current states of the alert monitoring pins with the changeable slave address to avoid bus conflict in advanced systems. For the visual representation of any deviation from programmed thresholds, alert monitoring pins are connected to 4 LEDs located on Click board™. The VCP Monitor 2 Click supports the I2C communication protocol. Since there are two slave devices on the Click board™, the solderable SMD jumpers are conveniently placed for easy I2C slave address reconfiguration. The INA3221-Q1 has one cross-shaped jumper selection for one address pin with four possible addresses with connections to GND, VCC, SDA or SCL. The other one, PCA9538A, has two jumpers for address pins A1 and A0 with the possibility of four different slave addresses, making this Click board™ flexible for implementation in other systems with various peripherals sharing the same bus.

VCP Monitor 2 Click hardware overview image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. 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, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board 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 DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC 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.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

28

RAM (Bytes)

3968

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
RA0
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RB1
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
Power Supply
5V
5V
Ground
GND
GND
2

Take a closer look

Click board™ Schematic

VCP Monitor 2 Click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

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

EasyPIC v8 front image hardware assembly
LTE IoT 5 Click front image hardware assembly
MCU DIP 28 hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
EasyPIC v8 28pin-DIP Access - 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
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

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

Software Support

Library Description

This library contains API for VCP Monitor 2 Click driver.

Key functions:

  • vcpmonitor2_get_manifacture_id - Get Manufacture ID

  • vcpmonitor2_get_die_id - Get DIE ID

  • vcpmonitor2_get_bus_voltage - Get BUS voltage in mV.

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 
 * \brief Vcpmonitor2 Click example
 * 
 * # Description
 * VCP Monitor 2 Click is a three-channel, high-side current and bus voltage monitor with alert indication 
 * function ensuring the intended application works within desired operating conditions.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initiaizes the driver, and checks the communication by reading the manufacture device ID.
 * After that, performs the device default configuration.
 * 
 * ## Application Task  
 * Displays the voltage, current, and power detected from channel 1 on the USB UART every 2 seconds.
 * It also displays the status of alert indicators.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "vcpmonitor2.h"

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

static vcpmonitor2_t vcpmonitor2;
static log_t logger;

static uint16_t check_id;

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

void display_alert_status ( )
{
    uint8_t status;
    
    status = vcpmonitor2_get_alert_status( &vcpmonitor2 );

    if ( ( status & VCPMONITOR2_ALERT_PVALID ) != 0 )
    {
        log_printf( &logger, ">> Alert status: [ PVALID ]\r\n" );
    }
    if ( ( status & VCPMONITOR2_ALERT_WRNG ) != 0 )
    {
        log_printf( &logger, ">> Alert status: [ WRNG ]\r\n" );
    }
    if ( ( status & VCPMONITOR2_ALERT_CRTCL ) != 0 )
    {
        log_printf( &logger, ">> Alert status: [ CRTCL ]\r\n" );
    }
    if ( ( status & VCPMONITOR2_ALERT_TCTRL ) != 0 )
    {
        log_printf( &logger, ">> Alert status: [ TCTRL ]\r\n" );
    }
}

void display_channel_data ( uint8_t channel )
{
    float shunt_volt;
    float bus_volt;
    float current;
    float power;
    
    shunt_volt = vcpmonitor2_get_shunt_voltage( &vcpmonitor2, channel );
    log_printf( &logger, ">> Shunt voltage: %.2f mV\r\n", shunt_volt );

    bus_volt = vcpmonitor2_get_bus_voltage( &vcpmonitor2, channel );
    log_printf( &logger, ">> BUS voltage: %.2f mV\r\n", bus_volt );

    current = vcpmonitor2_get_current( &vcpmonitor2, channel );
    log_printf( &logger, ">> Current: %.2f mV\r\n", current );

    power = vcpmonitor2_get_power( &vcpmonitor2, channel );
    log_printf( &logger, ">> Power: %.2f mV\r\n", power );
}

void application_init ( void )
{
    log_cfg_t log_cfg;
    vcpmonitor2_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.

    vcpmonitor2_cfg_setup( &cfg );
    VCPMONITOR2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    vcpmonitor2_init( &vcpmonitor2, &cfg );

    check_id = vcpmonitor2_get_manifacture_id( &vcpmonitor2 );
    if ( check_id == VCPMONITOR2_DEF_MANUFACTURE_ID )
    {
        log_printf( &logger, ">> Manufacture ID: 0x%.4X\r\n", check_id );
    }
    else
    {
        log_error( &logger, " WRONG ID READ! " );
        log_printf( &logger, "Please restart your system.\r\n" );
        for ( ; ; );
    }

    vcpmonitor2_default_cfg( &vcpmonitor2 );
}

void application_task ( void )
{
    log_printf( &logger, ">> CHANNEL 1 <<\r\n" );
    display_channel_data( VCPMONITOR2_CHANNEL_1 );

    display_alert_status( );
    log_printf( &logger, "--------------------------\r\n" );
    
    Delay_ms( 2000 );
}

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.