pac1944  2.0.0.0
Main Page

PAC1944 click

PAC1944 Click is a compact add-on board that contains an energy monitoring solution. This board features the PAC1944, a multi-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 Nikolic
  • Date : dec 2020.
  • Type : I2C type

Software Support

We provide a library for the PAC1944 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 PAC1944 Click driver.

Standard key functions :

Example key functions :

Examples Description

This demo application shows an example of measuring voltage, current and power in a selected part of the circuit. Note that PAC1944 is a high side power monitor, therefore the desired channel should be connected accordingly.

The demo application is composed of two sections :

Application Init

Initialization of I2C module, log UART and additional pins. In addition, a default configuration is performed as followed:

  • Sample mode is 1024, adaptive accumulation;
  • INT pin is set as an alert;
  • SLW pin is set as slow sampling rate control;
  • All channels are on;
  • Channel 1 is set for bipolar measurements;
  • Channel 2 is set for bipolar measurements reduced by half;
  • Channel 3 and 4 are set for unipolar measurements.
void application_init ( void ) {
log_cfg_t log_cfg;
pac1944_cfg_t pac1944_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
pac1944_cfg_setup( &pac1944_cfg );
PAC1944_MAP_MIKROBUS( pac1944_cfg, MIKROBUS_1 );
err_t init_flag = pac1944_init( &pac1944, &pac1944_cfg );
if ( init_flag == I2C_MASTER_ERROR ) {
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
Delay_ms( 100 );
pac1944_default_cfg ( &pac1944 );
log_info( &logger, " Application Task " );
log_printf( &logger, "-----------------------------\r\n" );
Delay_ms( 100 );
}

Application Task

The application sends a refresh command which stores the measurement data in registers. Measurements are acquired for voltage, current and power on channel 1 of PAC1944 click board. The last 8 measurements are averaged and calculated in bipolar mode. Process is repeated every two seconds.

void application_task ( void ) {
float voltage_sens;
float current_sens;
float power_sens;
pac1944_refresh_cmd( &pac1944 );
log_printf( &logger, " Voltage : %.6f V \r\n", voltage_sens );
log_printf( &logger, " Current : %.6f A \r\n", current_sens );
log_printf( &logger, " Power : %.6f W \r\n", power_sens );
log_printf( &logger, "-----------------------------\r\n" );
Delay_ms( 2000 );
}

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

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.


pac1944_t
PAC1944 Click context object.
Definition: pac1944.h:332
PAC1944_MEAS_SEL_V_SOURCE
#define PAC1944_MEAS_SEL_V_SOURCE
PAC1944 Measurement selection.
Definition: pac1944.h:145
PAC1944_MEAS_SEL_I_SENSE
#define PAC1944_MEAS_SEL_I_SENSE
Definition: pac1944.h:146
PAC1944_CH_SEL_CH_1
#define PAC1944_CH_SEL_CH_1
PAC1944 Channel selection.
Definition: pac1944.h:161
pac1944_device_state
void pac1944_device_state(pac1944_t *ctx, uint8_t state)
PAC1944 set device state function.
pac1944_cfg_t
PAC1944 Click configuration object.
Definition: pac1944.h:357
application_task
void application_task(void)
Definition: main.c:80
pac1944_get_calc_measurement
float pac1944_get_calc_measurement(pac1944_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint8_t meas_mode)
PAC1944 get calculated measurement function.
PAC1944_MEAS_MODE_BIPOLAR_FSR
#define PAC1944_MEAS_MODE_BIPOLAR_FSR
Definition: pac1944.h:194
pac1944_setup_t
PAC1944 Configuration setup structure.
Definition: pac1944.h:375
pac1944_cfg_setup
void pac1944_cfg_setup(pac1944_cfg_t *cfg)
PAC1944 configuration object setup function.
application_init
void application_init(void)
Definition: main.c:43
PAC1944_AVG_SEL_ENABLE
#define PAC1944_AVG_SEL_ENABLE
Definition: pac1944.h:179
pac1944_setup_config
void pac1944_setup_config(pac1944_t *ctx, pac1944_setup_t cfg_data)
PAC1944 setup config function.
pac1944_init
err_t pac1944_init(pac1944_t *ctx, pac1944_cfg_t *cfg)
PAC1944 initialization function.
PAC1944_MEAS_SEL_P_SENSE
#define PAC1944_MEAS_SEL_P_SENSE
Definition: pac1944.h:147
PAC1944_DEV_ENABLE
#define PAC1944_DEV_ENABLE
Definition: pac1944.h:212
pac1944_refresh_cmd
void pac1944_refresh_cmd(pac1944_t *ctx)
PAC1944 refresh command.
pac1944_default_cfg
void pac1944_default_cfg(pac1944_t *ctx)
PAC1944 default configuration function.
PAC1944_MAP_MIKROBUS
#define PAC1944_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: pac1944.h:317