PWR Meter 3 90A Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
- Author : Stefan Filipovic
- Date : Oct 2022.
- Type : I2C type
This example demonstrates the use of PWR Meter 3 90A Click board by reading and displaying the voltage, current, and power RMS measurements.
- MikroSDK.Board
- MikroSDK.Log
- Click.PWRMeter390A
pwrmeter390a_cfg_setup
Config Object Initialization function.
void pwrmeter390a_cfg_setup ( pwrmeter390a_cfg_t *cfg );
pwrmeter390a_init
Initialization function.
err_t pwrmeter390a_init ( pwrmeter390a_t *ctx, pwrmeter390a_cfg_t *cfg );
pwrmeter390a_default_cfg
Click Default Configuration function.
err_t pwrmeter390a_default_cfg ( pwrmeter390a_t *ctx );
pwrmeter390a_get_dio0_pin
This function returns the DIO0 pin logic state.
uint8_t pwrmeter390a_get_dio0_pin ( pwrmeter390a_t *ctx );
pwrmeter390a_get_dio1_pin
This function returns the DIO1 pin logic state.
uint8_t pwrmeter390a_get_dio1_pin ( pwrmeter390a_t *ctx );
pwrmeter390a_read_average_rms
This function reads the voltage and current RMS measurements averaged from a specified number of samples.
err_t pwrmeter390a_read_average_rms ( pwrmeter390a_t *ctx, float *v_rms, float *i_rms, uint16_t num_avg );
Initializes the driver and performs the Click default configuration which sets the DC measurement and VRMS thresholds to about 28V for overvoltage and about 9.3V for undervoltage flag.
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
pwrmeter390a_cfg_t pwrmeter390a_cfg; /**< Click config object. */
/**
* 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.
pwrmeter390a_cfg_setup( &pwrmeter390a_cfg );
PWRMETER390A_MAP_MIKROBUS( pwrmeter390a_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == pwrmeter390a_init( &pwrmeter390a, &pwrmeter390a_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( PWRMETER390A_ERROR == pwrmeter390a_default_cfg ( &pwrmeter390a ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
Reads the voltage and current RMS values averaged from 500 samples, then calculates the power from it and displays the results on the USB UART. Also if an UV or OV flag is detected it will be logged accordingly.
void application_task ( void )
{
float v_rms, i_rms;
if ( PWRMETER390A_OK == pwrmeter390a_read_average_rms ( &pwrmeter390a, &v_rms, &i_rms, PWRMETER390A_DEF_AVG_SAMPLES ) )
{
if ( !pwrmeter390a_get_dio0_pin ( &pwrmeter390a ) )
{
log_printf ( &logger, " Over-voltage detected!\r\n" );
}
if ( !pwrmeter390a_get_dio1_pin ( &pwrmeter390a ) )
{
log_printf ( &logger, " Under-voltage detected!\r\n" );
}
log_printf ( &logger, " Voltage: %.2f V\r\n", v_rms );
log_printf ( &logger, " Current: %.2f A\r\n", i_rms );
log_printf ( &logger, " Power: %.2f W\r\n\n", i_rms * v_rms );
}
}
This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
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.