中级
30 分钟

使用MAX40080和PIC32MZ1024EFH064实现无与伦比的电流测量精度

通过电流传感解锁新的可能性

Current 6 Click with PIC32MZ clicker

已发布 6月 25, 2024

点击板

Current 6 Click

开发板

PIC32MZ clicker

编译器

NECTO Studio

微控制器单元

PIC32MZ1024EFH064

通过我们的电流感应技术,轻松管理动态负载,无缝适应电流需求的变化。

A

A

硬件概览

它是如何工作的?

Current 6 Click 基于 MAX40080,这是一款来自 Analog Devices 的高精度、快速采样率数字电流检测放大器。MAX40080 测量电流和共模电压范围从 -0.1V 到 36V,并通过 I2C 兼容的两线串行接口将数据转换为数字形式,从而允许访问转换结果。此外,通过使用 I2C 寄存器设置输入电压感应 ±50mV 或 ±10mV,可以选择两个测量范围:0A 到 1A 或 0A 到 5A。这个 Click board™ 使用标准的 I2C 2 线接口与 MCU 通信,以配置和检查设备状态。标准 I2C 命令允许读取数据和配置其他操作特性。在读取电流/电压寄存器时,任何测量的电流和电压变化将在读取完成之前被忽略。读取操作完成后,电流/电压寄存器将更新新的测量值。

MAX40080 具有独特的 I2C 从设备地址选择方法,基于单个 R4 电阻。通过选择表 1 中精确定义电阻值的电阻,可以选择 32 个不同的从设备地址,这些地址对应附加数据表中的 32 个不同电阻值。R4 电阻的默认值为 100kΩ,对应地址 0x01。此外,当 I2C 接口不活动时,它还具有唤醒电流阈值和自动关机模式,旨在最大限度地减少功耗。由于传感器操作需要 1.8V 逻辑电压电平才能正常工作,因此使用了一个小型稳压 LDO,即来自 Analog Devices 的 ADP151,从 mikroBUS™ 导轨提供 1.8V。此 LDO 使用标记为 EN 的启用引脚,并布线到 mikroBUS™ 插座的 CS 引脚,以优化功耗,用于其电源开/关目的。这也是为

什么引入 LTC4301L 电压电平转换器的原因。I2C 接口总线线路布线到电压电平转换器,允许这个 Click board™ 在 3.3V 和 5V MCU 下正常工作。它还具有一个附加的中断信号,布线到 mikroBUS™ 插座的 INT 引脚,指示发生特定的中断事件,例如过流/电压、欠压、FIFO 满/溢出、达到唤醒电流阈值等。这个 Click board™ 可以通过 VIO SEL 跳线选择 3.3V 或 5V 逻辑电压电平,从而使 3.3V 和 5V 的 MCU 都能正确使用通信线路。此外,这个 Click board™ 配备了一个包含易于使用功能的库和一个可作为进一步开发参考的示例代码。

Current 6 Click hardware overview image
Current 6 Click Current Warning image

功能概述

开发板

PIC32MZ Clicker 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位带有浮点单元的 Microchip PIC32MZ 微控制器,一个 USB 连接器,LED 指示灯,按钮,一个 mikroProg 连接器,以及一个用于与外部电子设备接口的头部。得益于其紧凑的设计和清晰易识别的丝网标记,它提供了流畅且沉浸式的工作体验,允许在任

何情况下、任何地方都能访问。PIC32MZ Clicker 开 发套件的每个部分都包含了使同一板块运行最高效的必要组件。除了可以选择 PIC32MZ Clicker 的编程方式,使用 USB HID mikroBootloader 或通过外部 mikroProg 连接器为 PIC,dsPIC 或 PIC32 编程外,Clicker 板还包括一个干净且调节过的开发套件电源供应模块。USB Micro-B 连接可以提供多达 500mA 的电流,这足以操作所有板载和附加模块。所有 

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

PIC32MZ clicker double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

1024

硅供应商

Microchip

引脚数

64

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
Enable
RG9
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RB5
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RD10
SCL
I2C Data
RD9
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Current 6 Click Schematic schematic

一步一步来

项目组装

PIC32MZ clicker front image hardware assembly

从选择您的开发板和Click板™开始。以PIC32MZ clicker作为您的开发板开始。

PIC32MZ clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Board mapper by product7 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

软件支持

库描述

该库包含 Current 6 Click 驱动程序的 API。

关键功能:

  • current6_get_alert_pin - 此功能返回警报引脚的逻辑状态

  • current6_read_data - 此功能读取输入电压和电流测量值

  • current6_get_status - 此功能读取并清除状态寄存器

开源

代码示例

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

/*!
 * @file main.c
 * @brief Current6 Click example
 *
 * # Description
 * This example demonstrates the use of Current 6 Click board by reading 
 * the input voltage and current measurements.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the Click default configuration.
 *
 * ## Application Task
 * Waits for the FIFO data interrupt and then reads the measurements of
 * the input voltage and current and displays the results on the USB UART 
 * approximately once per second.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "current6.h"

static current6_t current6;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    current6_cfg_t current6_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.
    current6_cfg_setup( &current6_cfg );
    CURRENT6_MAP_MIKROBUS( current6_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == current6_init( &current6, &current6_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( CURRENT6_ERROR == current6_default_cfg ( &current6 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    if ( current6_get_alert_pin ( &current6 ) )
    {
        uint16_t status;
        if ( CURRENT6_OK == current6_get_status ( &current6, &status ) )
        {
            if ( status & CURRENT6_FIFO_CFG_DATA_OVERFLOW_MASK )
            {
                float voltage, current;
                if ( CURRENT6_OK == current6_read_data ( &current6, &voltage, &current ) )
                {
                    log_printf( &logger, " Voltage: %.3f V\r\n Current: %.3f A\r\n\n", voltage, current );
                }
            }
        }
    }
}

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

额外支持

资源

喜欢这个项目吗?

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