为嵌入式系统中的电源监控和管理提供有价值的信息
A
A
硬件概览
它是如何工作的?
Power Monitoring 2 Click基于两个INA219,这是一款来自德州仪器的12位I2C输出数字电源监控器,专为精确的电源监控而设计。这些IC用于监控连接负载设备的电力消耗,测量附加mikroBUS™插座上两条独立电源轨——3.3V和5V的电流和电压。这种配置允许监控这两条电源线,非常适合评估插入板载mikroBUS™插座中的任何Click板™的功耗。得益于其灵活性,INA219允许在没有特殊电源排序的情况下进行电源监控,即使电源或总线电压独立存在或缺失时也可以监控电源。INA219提供电流、电压和功率的实时数字读数。它通过感应连接到相关总线的分流电阻(R3和R4)上的电压降来实现测量,能够处理0到
26V范围内的总线电压。该设备的可编程转换时间和滤波选项确保了在各种操作条件下的精确测量。此外,INA219提供可编程的校准值,当与内部乘法器结合时,能够直接读取电流(单位为安培)并通过乘法寄存器计算功率(单位为瓦特)。如前所述,INA219通过标准的2线I2C接口与主MCU通信,支持高达1MHz时钟频率的高速模式。Power Monitoring 2 Click上的每个INA219 IC都具有可配置的I2C地址,地址通过ADDR SEL跳线设置(U2或U3分别对应每个INA219)。通过将跳线定位到0或1,用户可以选择所需的I2C地址。此外,考虑到此Click板™可以在3.3V和5V逻辑电平下运行,I2C线路上的上拉电阻所连接
的电压也可以选择。通过调整I2C PULL-UP跳线选择适当的电压水平(3.3V或5V)。该板还具有一个板载开关CS SEL,它使mikroBUS™插座的CS线与板上的ClickID功能通信。通过将开关设置为ON位置,CS线被重定向,允许ClickID功能正常工作以识别连接的Click板™。此Click板™可以在3.3V或5V逻辑电压电平下运行。这样,支持3.3V和5V逻辑电平的MCU都可以正确使用通信线路。作为附加功能,它包括两个绿色LED指示灯,分别显示3.3V或5V电源轨是否处于活动状态。此外,该Click板™还配备了包含易于使用的函数和示例代码的库,可作为进一步开发的参考。
功能概述
开发板
Flip&Click PIC32MZ 是一款紧凑型开发板,设计为一套完整的解决方案,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 PIC32MZ 微控制器,Microchip 的 PIC32MZ2048EFH100,四个 mikroBUS™ 插槽用于 Click 板™连接,两个 USB 连接器,LED 指示灯,按钮,调试器/程序员连接器,以及两个与 Arduino-UNO 引脚兼容的头部。得益于创
新的制造技术,它允许您快速构建具有独特功能和特性的小工具。Flip&Click PIC32MZ 开发套件的每个部分都包含了使同一板块运行最高效的必要组件。此外,还可以选择 Flip&Click PIC32MZ 的编程方式,使用 chipKIT 引导程序(Arduino 风格的开发环境)或我们的 USB HID 引导程序,使用 mikroC、mikroBasic 和 mikroPascal for PIC32。该套件包括一个通过 USB 类型-C(USB-C)连接器的干净且调
节过的电源供应模块。所有 mikroBUS™ 本身支持的 通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、用户可配置的按钮和 LED 指示灯。Flip&Click PIC32MZ 开发套件允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。
微控制器概述
MCU卡片 / MCU

建筑
PIC32
MCU 内存 (KB)
2048
硅供应商
Microchip
引脚数
100
RAM (字节)
524288
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
实时跟踪您的结果
应用程序输出
1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程。

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持
库描述
该库包含 Power Monitor 2 Click 驱动程序的 API。
关键功能:
powermonitor2_set_address
- 此函数设置设备的从属地址。powermonitor2_read_data
- 此函数读取分流电压、总线电压、电流和功率数据测量值。powermonitor2_read_data_avg
- 此函数从num_conv样本中读取分流电压、总线电压、电流和功率数据的平均值。
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief Power Monitor 2 Click example
*
* # Description
* This example demonstrates the use of Power Monitor 2 click by reading and displaying
* the power consumption at 3V3 and 5V of the connected click board.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and performs the click default configuration.
*
* ## Application Task
* Reads the voltage, current, and power measurements from U2 and U3 sensors averaged
* from 20 samples and displays the results on the USB UART.
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "powermonitor2.h"
static powermonitor2_t powermonitor2;
static log_t logger;
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
powermonitor2_cfg_t powermonitor2_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.
powermonitor2_cfg_setup( &powermonitor2_cfg );
POWERMONITOR2_MAP_MIKROBUS( powermonitor2_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == powermonitor2_init( &powermonitor2, &powermonitor2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( POWERMONITOR2_ERROR == powermonitor2_default_cfg ( &powermonitor2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
powermonitor2_data_t pm_3v3, pm_5v;
powermonitor2_set_address ( &powermonitor2, powermonitor2.address_3v3 );
if ( POWERMONITOR2_OK == powermonitor2_read_data_avg ( &powermonitor2, POWERMONITOR2_DEFAULT_NUM_CONV, &pm_3v3 ) )
{
log_printf( &logger, " --- 3V3 Power Monitor ---\r\n" );
log_printf( &logger, " Voltage: %.3f V\r\n", pm_3v3.bus_v );
log_printf( &logger, " Current: %.3f A\r\n", pm_3v3.current );
log_printf( &logger, " Power: %.2f W\r\n", pm_3v3.power );
log_printf( &logger, " -------------------------\r\n" );
}
powermonitor2_set_address ( &powermonitor2, powermonitor2.address_5v );
if ( POWERMONITOR2_OK == powermonitor2_read_data_avg ( &powermonitor2, POWERMONITOR2_DEFAULT_NUM_CONV, &pm_5v ) )
{
log_printf( &logger, " ---- 5V Power Monitor ---\r\n" );
log_printf( &logger, " Voltage: %.3f V\r\n", pm_5v.bus_v );
log_printf( &logger, " Current: %.3f A\r\n", pm_5v.current );
log_printf( &logger, " Power: %.2f W\r\n", pm_5v.power );
log_printf( &logger, " -------------------------\r\n" );
}
Delay_ms ( 1000 );
}
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