中级
30 分钟

使用INA228和MK64FN1M0VDC12实现最高精度的电源监控

重新定义电源洞察:通过超精确监控提升性能

Power Monitor Click with Clicker 2 for Kinetis

已发布 6月 24, 2024

点击板

Power Monitor Click

开发板

Clicker 2 for Kinetis

编译器

NECTO Studio

微控制器单元

MK64FN1M0VDC12

我们的超精密电力监控解决方案重新定义了您对电力使用情况的洞察,提供无与伦比的准确性,以优化性能、降低成本并确保系统的可靠性。

A

A

硬件概览

它是如何工作的?

Power Monitor Click基于INA228,这是一款超精密的数字电源监控器,采用德州仪器的20位Delta-Sigma ADC和I2C数字接口。它测量分流电压、总线电压和内部温度,同时计算电流、功率、能量和电荷,为精确控制系统中的准确决策提供必要的数据。它可以测量通过接在板载IN端子上的电阻分流传感元件的±163.84mV或±40.96mV的满量程差分输入,支持高达+85V的共模电压,使其适合高侧和低侧电流测量。INA228还通过VBUS端子测量总线电压,并通过集成的±1°C精度温度传感器测量温度,帮助监控环境系统温度。功率、电荷和能量的计算在后台进行,不会增加整体ADC转换时

间。此外,非常低的偏置电压和噪声使其可用于毫安到千安的传感应用,并提供宽动态范围,而不会在传感分流元件上产生显著的功耗损失。Power Monitor Click通过标准的I2C 2线接口与MCU通信,以读取数据和配置设置,支持高达400kHz的快速模式操作。INA228还允许通过两个标记为A0和A1的SMD十字形跳线选择其I2C从属地址。一个十字形跳线有四个位置可选择地址引脚,可连接到GND、VS、SCL或SDA引脚。通过将SMD跳线定位到适当的位置,INA228提供了16个不同I2C地址的选择机会。此外,INA228还包括多功能警报(中断)引脚,标记为ALR并路由到mikroBUS™插座的

INT引脚,用于在设备在触发和连续转换模式下操作时,报告多个诊断或作为ADC转换完成的指示。当监控的输出值越过其相关的超范围阈值时,诸如分流过/欠电压限制、总线过/欠电压限制或温度或功率过限等诊断会通过ALR引脚不断监控和报告。此Click板™可通过VCC SEL跳线选择3.3V或5V逻辑电压电平,从而使具有3.3V和5V能力的MCU能够正确使用通信线路。此外,该Click板™配备了一个包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

Power Monitor Click hardware overview image

功能概述

开发板

Clicker 2 for Kinetis 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 ARM Cortex-M4F 微控制器,NXP 半导体公司的 MK64FN1M0VDC12,两个 mikroBUS™ 插槽用于 Click 板™连接,一个 USB 连接器,LED 指示灯,按钮,一个 JTAG 程序员连接器以及两个 26 针头用于与外部电子设备的接口。其紧凑的设计和清晰、易识别的丝网标记让您能够迅速构建具有独特功能和特性

的小工具。Clicker 2 for Kinetis 开发套件的每个部分 都包含了使同一板块运行最高效的必要组件。除了可以选择 Clicker 2 for Kinetis 的编程方式,使用 USB HID mikroBootloader 或外部 mikroProg 连接器进行 Kinetis 编程外,Clicker 2 板还包括一个干净且调节过的开发套件电源供应模块。它提供了两种供电方式;通过 USB Micro-B 电缆,其中板载电压调节器为板上每个组件提供适当的电压水平,或使用锂聚合物 电池通过板载电池连接器供电。所有 mikroBUS™ 本

身支持的通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、重置按钮和几个用户可配置的按钮及 LED 指示灯。Clicker 2 for Kinetis 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

Clicker 2 for Kinetis dimensions image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

NXP

引脚数

121

RAM (字节)

262144

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Alert Interrupt
PB13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PD8
SCL
I2C Data
PD9
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Power Monitor Click Schematic schematic

一步一步来

项目组装

Clicker 2 for PIC32MZ front image hardware assembly

从选择您的开发板和Click板™开始。以Clicker 2 for Kinetis作为您的开发板开始。

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker 2 Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

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 Click 驱动程序的 API。

关键功能:

  • powermonitor_get_vshunt - 电力监控获取分流电压功能

  • powermonitor_get_vbus - 电力监控获取总线电压功能

  • powermonitor_get_current - 电力监控获取电流功能

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief PowerMonitor Click example
 *
 * # Description
 * This library contains API for Power Monitor Click driver.
 * The library initializes and defines the I2C bus drivers 
 * to write and read data from registers. 
 * The library also includes a function for reading 
 * Shunt and Bus voltage ( mV ), Current ( mA ), Power ( W ), Energy ( J ),   
 * as well as the Temperature in degrees Celsius.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * The initialization of I2C  module, log UART, and additional pins. 
 * After the driver init and then executes a default configuration, 
 * the app checks communication, display Manufacturer, Stores Device and Revision ID. 
 *
 * ## Application Task
 * This is an example that shows the use of a Power Monitor Click board™.
 * Measures and displays Shunt voltage ( mV ), Bus voltage ( mV ), 
 * Current ( mA ), Power ( W ), Energy ( J ) and Temperature ( degrees Celsius ). 
 * Results are being sent to the USART terminal where the user can track their changes. 
 * This task repeats every 2.5 sec.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "powermonitor.h"

static powermonitor_t powermonitor;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;                    /**< Logger config object. */
    powermonitor_cfg_t powermonitor_cfg;  /**< Click config object. */
    static uint8_t manufacturer_id[ 2 ];
    static uint16_t dieid;
    static uint8_t rev_id;
    
    powermonitor.shunt = 0.28;

    /** 
     * 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.
    powermonitor_cfg_setup( &powermonitor_cfg );
    POWERMONITOR_MAP_MIKROBUS( powermonitor_cfg, MIKROBUS_1 );
    err_t init_flag = powermonitor_init( &powermonitor, &powermonitor_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    powermonitor_default_cfg ( &powermonitor );
    log_printf( &logger, "----------------------------\r\n" );
    Delay_ms( 100 );
    
    powermonitor_get_id( &powermonitor, &manufacturer_id, &dieid, &rev_id );
    log_printf( &logger, "  Manufacturer ID  : %.2s\r\n", manufacturer_id );
    log_printf( &logger, "  Stores Device ID : 0x%.3X\r\n", dieid );
    log_printf( &logger, "  Revision ID      : 0x%.1X\r\n", rev_id );
    log_printf( &logger, "----------------------------\r\n" );
    log_info( &logger, " Application Task " );
    log_printf( &logger, "----------------------------\r\n" );
    Delay_ms( 100 );
}

void application_task ( void ) 
{
    static float vshunt, vbus, current, power, energy, temperature;
    
    powermonitor_get_vshunt( &powermonitor, &vshunt );
    log_printf( &logger, " Shunt voltage : %.2f mV\r\n", vshunt );
    Delay_ms( 100 ); 
    
    powermonitor_get_vbus( &powermonitor, &vbus );
    log_printf( &logger, " BUS voltage   : %.2f mV\r\n", vbus );
    Delay_ms( 100 );
    
    powermonitor_get_current( &powermonitor, &current );
    log_printf( &logger, " Current       : %.2f mA\r\n", current );
    Delay_ms( 100 ); 
    
    powermonitor_get_power( &powermonitor, &power );
    log_printf( &logger, " Power         : %.6f W\r\n", power );
    Delay_ms( 100 ); 
    
    powermonitor_get_energy( &powermonitor, &energy );
    log_printf( &logger, " Energy        : %.6f J\r\n", energy );
    log_printf( &logger, "- - - - - - - - - - - - - - \r\n" );
    Delay_ms( 100 ); 
    
    powermonitor_get_temperature( &powermonitor, &temperature );
    log_printf( &logger, " Temperature   : %.2f C\r\n", temperature );
    log_printf( &logger, "----------------------------\r\n" );
    Delay_ms( 2000 );
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。