pac1954 2.0.0.0
Main Page

PAC1954 click

‍PAC1954 Click is a compact add-on board that contains an energy monitoring solution. This board features the PAC1954, a four-channel DC power/energy monitor from Microchip Technology. It uses real-time calibration to minimize offset and gain errors with no input filters required for this device.

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Jun 2021.
  • Type : I2C type

Software Support

We provide a library for the PAC1954 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

‍This library contains API for PAC1954 Click driver.

Standard key functions :

Example key functions :

  • pac1954_refresh_cmd This function updates the readable registers for the VBUS, VSENSE, Power, accumulator outputs and accumulator count by issuing the REFRESH command. The values will be static until the next REFRESH command.
    err_t pac1954_refresh_cmd(pac1954_t *ctx)
    PAC1954 Refresh Command.
  • pac1954_get_calc_measurement This function calls the function for getting the selected measurement data and performs all the necessary calculations to get the measurement value in standard unit.
    err_t pac1954_get_calc_measurement ( pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint8_t meas_mode, float *data_out );
    err_t pac1954_get_calc_measurement(pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint8_t meas_mode, float *data_out)
    PAC1954 Get Calculated Measurement Function.
  • pac1954_generic_write This function writes a desired number of data bytes starting from the selected register by using I2C serial interface.
    err_t pac1954_generic_write ( pac1954_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
    err_t pac1954_generic_write(pac1954_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
    PAC1954 I2C writing function.

Example Description

‍This example demonstrates the use of PAC1954 click board.

The demo application is composed of two sections :

Application Init

‍Initializes the driver and performs the click default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
pac1954_cfg_t pac1954_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
pac1954_cfg_setup( &pac1954_cfg );
PAC1954_MAP_MIKROBUS( pac1954_cfg, MIKROBUS_1 );
err_t init_flag = pac1954_init( &pac1954, &pac1954_cfg );
if ( I2C_MASTER_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
pac1954_default_cfg ( &pac1954 );
log_info( &logger, " Application Task " );
}
#define PAC1954_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition pac1954.h:292
void application_init(void)
Definition main.c:28

Application Task

‍Reads the voltage, current, and power from Channel 1 and displays all values on the USB UART once per second.

void application_task ( void )
{
float vsource = 0;
float isense = 0;
float power = 0;
pac1954_refresh_cmd ( &pac1954 );
&vsource );
&isense );
0,
&power );
log_printf( &logger, " Voltage: %.3f V\r\n", vsource );
log_printf( &logger, " Current: %.3f A\r\n", isense );
log_printf( &logger, " Power: %.3f W\r\n", power );
log_printf( &logger, "---------------------------\r\n" );
Delay_ms ( 1000 );
}
#define PAC1954_MEAS_SEL_P_SENSE
Definition pac1954.h:221
#define PAC1954_MEAS_SEL_V_SOURCE
PAC1954 Measurement Data Selector.
Definition pac1954.h:219
#define PAC1954_AVG_SEL_ENABLE
Definition pac1954.h:237
#define PAC1954_MEAS_MODE_BIPOLAR_FSR
Definition pac1954.h:244
#define PAC1954_MEAS_SEL_I_SENSE
Definition pac1954.h:220
#define PAC1954_CH_SEL_CH_1
PAC1954 Channel Selector.
Definition pac1954.h:227
void application_task(void)
Definition main.c:62

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.PAC1954

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.