Intermediate
30 min

Accurately measure VCP parameters in real time using INA3221 and PIC18F57Q43

The future of Voltage-Current-Power monitoring

VCP Monitor 2 Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

VCP Monitor 2 Click

Dev Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

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

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PA7
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
PA6
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB2
SCL
I2C Data
PB1
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

VCP Monitor 2 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX 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 image step 5 hardware assembly
Necto image step 6 hardware assembly
PIC18F57Q43 Curiosity 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 via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

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

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

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