Intermediate
30 min

Navigate current monitoring with confidence using PAC1921 and PIC18LF46K42

Ultimate solution for accurate and reliable power monitoring

PAC1921 Click with EasyPIC v8

Published Sep 29, 2023

Click board™

PAC1921 Click

Dev. board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18LF46K42

Experience a new level of precision with our power monitoring technology, designed for high-side current measurement, ensuring you have the insights you need for critical analysis

A

A

Hardware Overview

How does it work?

PAC1921 Click is based on the PAC1921, a high-side power/current monitor from Microchip. The measurement is done by the SENSE+ and SENSE- pins, which are routed to the onboard terminals used for connecting the load. A shunt resistor of 10mΩ is also soldered between these two pins. The SENSE pins are very sensitive to the voltage and they can detect up to 100mV of across the shunt resistor. The OUT pin of the PAC1921 IC can be used to output an analog voltage, which corresponds to the selected measured electrical property - voltage, current or power. The full scale for the measurement can be set to 1V, 1.5V, 2V and 3V. The OUT pin of the IC is routed to the mikroBUS™ AN pin so that the host MCU can instantly read the measurement information without latency, common for the serial communication. The load should be connected in series with the PAC1921 click so that the positive end of the power supply runs through the PAC1921 click SENSE+ terminal, SENSE- terminal and finally to the positive end of the load. Negative end (GND) of the load is connected to the ground. The voltage drop across the shunt resistor is used to measure the current flow through the load and it should not exceed 6A. When the voltage drop across the shunt resistor and its resistance are known, the current can be easily calculated. The voltage across the connected power supply is measured between the SENSE+ pin and the GND. The maximum voltage level between the SENSE+ and the GND rail should not exceed 32V. During the measurement, these values are stored in the appropriate registers and are used for the power calculation. PAC1921 is able

to integrate the measurements so that the average value can be calculated. The integration can be done in two modes: Free-Run mode and Pin Controlled mode. Pin Controlled integration mode can be engaged by pulling the #READ/INT pin to a HIGH level. This pin is routed to the mikroBUS™ INT pin. The measured type in this mode is limited only to power readings. While the pin is held at a HIGH logic level or before 2048 measuring samples are made, the PAC1921 IC will perform an integration of the measured values. After the integration is over - either after 2048 samples are taken, or after the #READ/INT pin is pulled to a LOW logic level for the minimum update time at any moment, the registers are updated, and the calculated value is sent to the 10bit DAC of the OUT pin. Pulling the #READ/INT pin to a LOW logic level for a minimum update time will put the device into the Read mode, stop the integration process and send the value to the 10bit DAC of the OUT pin. While working in Free-Run integration mode, besides the power measurement, it is possible to measure current and voltage, too. The Free-Run integration time depends on the selected measuring mode, filtering, resolution, and the number of samples, which is selectable to a maximum of 2048 samples. The filtering improves the signal quality but increases the integration time for 50%. Also, when less integration time is required, 11bit ADC conversion should be used instead of the 14bit, at a cost of decreased precision. When power reading mode is selected as the measurement type, both voltage and current registers will be

updated, resulting in longer integration time. While the device stays in the integration mode, the information will be latched on the DAC of the OUT pin after each integration period. When the device enters the Read mode, the integration is interrupted, and the collected data is discarded. The device is able to enter the Read mode by setting the appropriate registers, too. While integrating the measured values, the device will place the selected measured electrical property values into the accumulator registers. At the end of the integration period, this averaged value is sent to the output 10bit DAC of the OUT pin, so that it can be read by the host MCU. It is also available in the registers, in a form of the MSB/LSB and by using conversion formulas from the PAC1921 datasheet, this value can be directly converted to the physical value of the electrical property - ampers [A], volts [V] or watts [W]. All the required setup and config registers are described in the PAC1921 datasheet, in details. This Click board™ library contains functions used to easily set up the device registers and read the measurements for the selected electrical property. The provided demo application can be used as a starting point or a reference for a custom design. PAC1921 click features the onboard SMD jumper, labeled as the PWR SEL, which can be used to set the operating voltage and the logic level for the I2C communication lines so that both 3.3V and 5V capable MCUs can communicate with the device. The communication lines are already equipped with the pull-up resistors so that the device is ready to be used out of the box.

PAC1921 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

PIC18LF46K42

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

4096

Used MCU Pins

mikroBUS™ mapper

Analog Output
RA2
AN
NC
NC
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
RB0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

PAC1921 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
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v8 Access DIPMB 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
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

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 PAC1921 Click driver.

Key functions:

  • pac1921_write_to_reg - This function writes data to the specified register address/es and saves the state of the register/s so it doesn't write the same value/s twice

  • pac1921_get_measured_data - This function gathers voltage/power data from the PAC1921 chip and, depending on the measurement mode, converts those raw values into a more suitable form

  • pac1921_set_int_pin - This function sets the digital output on the interrupt pin.

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 PAC1921 Click example
 * 
 * # Description
 * This example showcases how to measure voltage, current or power (load) data using the 
 * PAC1921 chip. Required modules are first initialized and after used to read and
 * display the measured data. 
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * This function initializes and configures the logger and Click modules. Default settings
 * are written to three control/configuration registers in the default_cfg(...) function.
 * 
 * ## Application Task  
 * This function reads and displays voltage, current or power data from the chip, depending
 * on the specified measurement mode and sample count. It does so every half a second. 
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "pac1921.h"

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

static pac1921_t pac1921;
static log_t logger;

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

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

    pac1921_cfg_setup( &cfg );
    PAC1921_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    pac1921_init( &pac1921, &cfg );
    Delay_ms ( 100 );
    pac1921_default_cfg( &pac1921 );
    Delay_ms ( 100 );
}

void application_task ( )
{
    float read_data;

    read_data = pac1921_get_measured_data( &pac1921, PAC1921_MEASUREMENT_MODE_V_BUS_FREE_RUN,
                                                     PAC1921_SAMPLE_RATE_512 );

    if ( pac1921.aux.measurement_mode_old == PAC1921_MEASUREMENT_MODE_V_POWER_FREE_RUN )
    {
        log_printf( &logger, " * Power: %.2f W * \r\n", read_data );
    }
    else
    {
        log_printf( &logger, " * Voltage: %.2f mV * \r\n", read_data );
    }

    Delay_ms ( 500 );
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

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