pwrmeter  2.0.0.0
Main Page

PWR Meter click

PWR Meter click is a power measurement Click boardâ„¢, capable of measuring voltage and current through the load, connected to either AC or DC power source. PWR Meter click uses the MCP39F511A, a very sophisticated monitoring IC from Microchip, with 16-bit processing core.

click Product page


Click library

  • Author : MikroE Team
  • Date : jun 2020.
  • Type : UART GPS/GNSS type

Software Support

We provide a library for the PwrMeter 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

This library contains API for PwrMeter Click driver.

Standard key functions :

Example key functions :

  • Function reads 16-bit data from the desired register.

    PWRMETER_RETVAL pwrmeter_read_reg_word ( pwrmeter_t *ctx, uint16_t register_addr, uint16_t *data_out );

  • Function reads 32-bit data from the desired register.

    PWRMETER_RETVAL pwrmeter_read_reg_dword ( pwrmeter_t *ctx, uint16_t register_addr, uint32_t *data_out );

  • Function reads signed 16bit or 32bit data from the desired register.

    PWRMETER_RETVAL pwrmeter_read_reg_signed ( pwrmeter_t *ctx, uint16_t register_addr, uint8_t data_mode, int32_t *data_out );

Examples Description

This click is capable of measuring voltage and current through the load, connected to either AC or DC power source. It is used to calculate all the measurement parameters, returning values of multiple power parameters directly, over the UART interface, reducing the processing load on the host MCU. These parameters include active, reactive, and apparent power, current and voltage RMS, line frequency, and power factor.

The demo application is composed of two sections :

Application Init

Initializes UART interface, puts output of regulator in active state and configures gain channel and uart baud rate.

void application_init ( void )
{
log_cfg_t log_cfg;
// Logger initialization.
LOG_MAP_USB_UART( log_cfg );
log_cfg.level = LOG_LEVEL_DEBUG;
log_cfg.baud = 115200;
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
Delay_ms( 100 );
// Click initialization.
PWRMETER_MAP_MIKROBUS( cfg, MIKROBUS_1 );
pwrmeter_init( &pwrmeter, &cfg );
Delay_ms( 500 );
Delay_ms( 100 );
log_printf( &logger, "PWR Meter is initialized\r\n" );
Delay_ms( 100 );
}

Application Task

Reads voltage, current and power measurements from data registers, then converts this values to determined units and logs all results on uart terminal each second.

void application_task ( void )
{
meas_data[ 0 ] = ( float ) voltage_rms / 100;
meas_data[ 1 ] = ( float ) current_rms / 1000;
meas_data[ 2 ] = ( float ) active_power / 100000;
meas_data[ 3 ] = ( float ) reactive_power / 100000;
meas_data[ 4 ] = ( float ) apparent_power / 100000;
meas_data[ 5 ] = ( float ) power_factor / 32767;
{
log_printf( &logger, "DC mode\r\n" );
}
else
{
log_printf( &logger, "AC mode\r\n" );
}
log_printf( &logger, "RMS voltage: " );
{
log_printf( &logger, "-" );
}
log_printf( &logger, "%.2f[ V ]\r\n", meas_data[ 0 ] );
log_printf( &logger, "RMS current: " );
{
log_printf( &logger, "-" );
}
log_printf( &logger, "%.2f[ mA ]\r\n", meas_data[ 1 ] );
log_printf( &logger, "Active power: " );
{
log_printf( &logger, "-" );
}
log_printf( &logger, "%.2f[ W ]\r\n", meas_data[ 2 ] );
log_printf( &logger, "Reactive power: " );
{
log_printf( &logger, "-" );
}
log_printf( &logger, "%.2f[ VAr ]\r\n", meas_data[ 3 ] );
log_printf( &logger, "Apparent power: " );
log_printf( &logger, "%.2f[ VA ]\r\n", meas_data[ 4 ] );
log_printf( &logger, "Power factor: %.2f\r\n", meas_data[ 5 ] );
log_printf( &logger, "-----------------------------------\r\n" );
Delay_ms( 1000 );
}

Note

Do not apply higher voltage than 60V to this board! This click is designed for lower voltage monitoring and evaluation of the MCP39F511A and its basic functionalities.

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.PwrMeter

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.


PWRMETER_PR_SIGN_MASK
#define PWRMETER_PR_SIGN_MASK
Definition: pwrmeter.h:130
response_byte
PWRMETER_RETVAL response_byte
Definition: main.c:47
voltage_rms
uint16_t voltage_rms
Definition: main.c:48
pwrmeter_init
PWRMETER_RETVAL pwrmeter_init(pwrmeter_t *ctx, pwrmeter_cfg_t *cfg)
Initialization function.
pwrmeter_enable
void pwrmeter_enable(pwrmeter_t *ctx, uint8_t state)
Enable function.
PWRMETER_16BIT_DATA
#define PWRMETER_16BIT_DATA
Definition: pwrmeter.h:120
active_power
uint32_t active_power
Definition: main.c:50
PWRMETER_ENABLE
#define PWRMETER_ENABLE
Definition: pwrmeter.h:137
PWRMETER_ACTIVE_PWR_REG
#define PWRMETER_ACTIVE_PWR_REG
Definition: pwrmeter.h:152
pwrmeter_send_command
PWRMETER_RETVAL pwrmeter_send_command(pwrmeter_t *ctx, uint8_t command_byte)
Command Send function.
check_response
void check_response()
Definition: main.c:60
PWRMETER_DCMODE_MASK
#define PWRMETER_DCMODE_MASK
Definition: pwrmeter.h:127
pwrmeter_cfg_t
Click configuration structure definition.
Definition: pwrmeter.h:286
pwrmeter_read_reg_signed
PWRMETER_RETVAL pwrmeter_read_reg_signed(pwrmeter_t *ctx, uint16_t register_addr, uint8_t data_mode, int32_t *data_out)
Signed Data Read function.
PWRMETER_DCVOLT_SIGN_MASK
#define PWRMETER_DCVOLT_SIGN_MASK
Definition: pwrmeter.h:129
application_task
void application_task(void)
Definition: main.c:134
PWRMETER_SYS_CONFIG_REG
#define PWRMETER_SYS_CONFIG_REG
Definition: pwrmeter.h:190
pwrmeter_read_reg_dword
PWRMETER_RETVAL pwrmeter_read_reg_dword(pwrmeter_t *ctx, uint16_t register_addr, uint32_t *data_out)
DWORD Read function.
PWRMETER_DCCURR_SIGN_MASK
#define PWRMETER_DCCURR_SIGN_MASK
Definition: pwrmeter.h:128
reactive_power
uint32_t reactive_power
Definition: main.c:51
PWRMETER_REACTIVE_PWR_REG
#define PWRMETER_REACTIVE_PWR_REG
Definition: pwrmeter.h:153
PWRMETER_VOLT_RMS_REG
#define PWRMETER_VOLT_RMS_REG
Definition: pwrmeter.h:147
PWRMETER_VOLT_GAIN_1
#define PWRMETER_VOLT_GAIN_1
Definition: pwrmeter.h:223
PWRMETER_UART_BR_9600
#define PWRMETER_UART_BR_9600
Definition: pwrmeter.h:233
PWRMETER_SAVE_TO_FLASH_COMM
#define PWRMETER_SAVE_TO_FLASH_COMM
Definition: pwrmeter.h:95
pwrmeter_read_reg_word
PWRMETER_RETVAL pwrmeter_read_reg_word(pwrmeter_t *ctx, uint16_t register_addr, uint16_t *data_out)
WORD Read function.
PWRMETER_PA_SIGN_MASK
#define PWRMETER_PA_SIGN_MASK
Definition: pwrmeter.h:131
PWRMETER_CURR_RMS_REG
#define PWRMETER_CURR_RMS_REG
Definition: pwrmeter.h:151
PWRMETER_MAP_MIKROBUS
#define PWRMETER_MAP_MIKROBUS(cfg, mikrobus)
Definition: pwrmeter.h:53
pwrmeter_get_status
PWRMETER_RETVAL pwrmeter_get_status(pwrmeter_t *ctx, uint8_t *status_data)
Status Get function.
pwrmeter_cfg_setup
void pwrmeter_cfg_setup(pwrmeter_cfg_t *cfg)
Config Object Initialization function.
status_byte
uint8_t status_byte
Definition: main.c:54
application_init
void application_init(void)
Definition: main.c:101
pwrmeter_write_reg_dword
PWRMETER_RETVAL pwrmeter_write_reg_dword(pwrmeter_t *ctx, uint16_t register_addr, uint32_t data_in)
DWORD Write function.
PWRMETER_APPARENT_PWR_REG
#define PWRMETER_APPARENT_PWR_REG
Definition: pwrmeter.h:154
PWRMETER_PWR_FACTOR_REG
#define PWRMETER_PWR_FACTOR_REG
Definition: pwrmeter.h:150
apparent_power
uint32_t apparent_power
Definition: main.c:52
meas_data
float meas_data[6]
Definition: main.c:56
current_rms
uint32_t current_rms
Definition: main.c:49
PWRMETER_CURR_GAIN_8
#define PWRMETER_CURR_GAIN_8
Definition: pwrmeter.h:226
power_factor
int32_t power_factor
Definition: main.c:53