资源简介
使用INA226芯片测量电流和总线电压,可测量uA级别电流,可自动计算功率,本案例使用0.1欧电阻,可更换更小电阻,以测量更大电流
代码片段和文件信息
/*
INA226.cpp - Class file for the INA226 Bi-directional Current/Power Monitor Arduino Library.
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not see .
*/
#if ARDUINO >= 100
#include “Arduino.h“
#else
#include “WProgram.h“
#endif
#include
#include “INA226.h“
bool INA226::begin(uint8_t address)
{
Wire.begin();
inaAddress = address;
return true;
}
bool INA226::configure(ina226_averages_t avg ina226_busConvTime_t busConvTime ina226_shuntConvTime_t shuntConvTime ina226_mode_t mode)
{
uint16_t config = 0;
config |= (avg << 9 | busConvTime << 6 | shuntConvTime << 3 | mode);
vBusMax = 36;
vShuntMax = 0.08192f;
writeRegister16(INA226_REG_CONFIG config);
return true;
}
bool INA226::calibrate(float rShuntValue float iMaxExpected)
{
uint16_t calibrationValue;
rShunt = rShuntValue;
float iMaxPossible minimumLSB;
iMaxPossible = vShuntMax / rShunt;
minimumLSB = iMaxExpected / 32767;
currentLSB = (uint16_t)(minimumLSB * 100000000);
currentLSB /= 100000000;
currentLSB /= 0.0001;
currentLSB = ceil(currentLSB);
currentLSB *= 0.0001;
powerLSB = currentLSB * 25;
calibrationValue = (uint16_t)((0.00512) / (currentLSB * rShunt));
writeRegister16(INA226_REG_CALIBRATION calibrationValue);
return true;
}
float INA226::getMaxPossibleCurrent(void)
{
return (vShuntMax / rShunt);
}
float INA226::getMaxCurrent(void)
{
float maxCurrent = (currentLSB * 32767);
float maxPossible = getMaxPossibleCurrent();
if (maxCurrent > maxPossible)
{
return maxPossible;
} else
{
return maxCurrent;
}
}
float INA226::getMaxShuntVoltage(void)
{
float maxVoltage = getMaxCurrent() * rShunt;
if (maxVoltage >= vShuntMax)
{
return vShuntMax;
} else
{
return maxVoltage;
}
}
float INA226::getMaxPower(void)
{
return (getMaxCurrent() * vBusMax);
}
float INA226::readBusPower(void)
{
return (readRegister16(INA226_REG_POWER) * powerLSB);
}
float INA226::readShuntCurrent(void)
{
return (readRegister16(INA226_REG_CURRENT) * currentLSB);
}
float INA226::readShuntVoltage(void)
{
float voltage;
voltage = readRegister16(INA226_REG_SHUNTVOLTAGE);
return (voltage * 0.0000025);
}
float INA226::readBusVoltage(void)
{
int16_t voltage;
voltage = readRegister16(INA226_REG_BUSVOLTAGE);
return (voltage * 0.00125);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
.CA.... 131 2014-07-20 03:35 ina226\Arduino-INA226-程序\Arduino-INA226-程序\CHANGELOG
.CA.... 6774 2014-07-20 03:35 ina226\Arduino-INA226-程序\Arduino-INA226-程序\INA226.cpp
.CA.... 4770 2014-07-20 03:35 ina226\Arduino-INA226-程序\Arduino-INA226-程序\INA226.h
.CA.... 1097473 2015-09-02 14:54 ina226\Arduino-INA226-程序\Arduino-INA226-程序\ina226.pdf
.CA.... 1493 2015-11-03 13:19 ina226\Arduino-INA226-程序\Arduino-INA226-程序\INA226_alert\INA226_alert.ino
.CA.... 1284 2015-11-03 13:19 ina226\Arduino-INA226-程序\Arduino-INA226-程序\INA226_latch\INA226_latch.ino
.CA.... 4563 2015-11-03 13:19 ina226\Arduino-INA226-程序\Arduino-INA226-程序\INA226_simple\INA226_simple.ino
.CA.... 35121 2014-07-20 03:35 ina226\Arduino-INA226-程序\Arduino-INA226-程序\LICENSE
.CA.... 265 2014-07-20 03:35 ina226\Arduino-INA226-程序\Arduino-INA226-程序\README.md
.CA.... 110953 2016-03-07 19:07 ina226\Arduino-INA226-程序\CJMCU-226原理图.pdf
.CA.... 1001977 2016-07-11 09:42 ina226\Arduino-INA226-程序.zip
.CA.... 110953 2016-03-07 19:07 ina226\CJMCU-226原理图.pdf
.CA.... 1097473 2015-09-02 14:54 ina226\ina226.pdf
.CA.... 894140 2019-03-17 17:14 ina226\INA226中文.pdf
.CA.... 24423 2016-07-01 18:06 ina226\INA226模块+stm32f429\CORE\cmsis_armcc.h
.CA.... 114498 2016-07-01 18:06 ina226\INA226模块+stm32f429\CORE\core_cm4.h
.CA.... 3620 2016-07-01 18:06 ina226\INA226模块+stm32f429\CORE\core_cmFunc.h
.CA.... 3636 2016-07-01 18:06 ina226\INA226模块+stm32f429\CORE\core_cmInstr.h
.CA.... 3662 2016-07-01 18:06 ina226\INA226模块+stm32f429\CORE\core_cmSimd.h
.CA.... 31694 2016-07-01 18:06 ina226\INA226模块+stm32f429\CORE\startup_stm32f429xx.s
.CA.... 166216 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h
.CA.... 13345 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal.h
.CA.... 36376 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_adc.h
.CA.... 18952 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_adc_ex.h
.CA.... 36361 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_can.h
.CA.... 30747 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_cec.h
.CA.... 17044 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_conf_template.h
.CA.... 20217 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_cortex.h
.CA.... 7298 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_crc.h
.CA.... 23327 2016-07-01 18:06 ina226\INA226模块+stm32f429\HALLIB\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_cryp.h
............此处省略311个文件信息
- 上一篇:OV7670串口上位机显示图像.zip
- 下一篇:图书管理系统源码
相关资源
- stm32F103GRBL系统脱机移植带屏幕控制
- stm32 寄存器版开发教程
- STM32 人脸识别 战舰开发板 测试通过
- 基于STM32F104的寻迹避障小车设计源码
- 基于STM32F4的US100超声波传感器测距
- 基于stm32的字符识别卡在内存上了
- 机智云APP控制STM32战舰V3的LED和蜂鸣器
- STM32F407信号发生器整体代码.zip
- 德飞莱STM32F103ZET6的配套程序
- stm32驱动鹰眼OV7725源码与所有的资料
- STM32L1XX最新固件库
- STM32.rar
- 基于stm32的触摸屏电子秤
- 基于STM32F429的语音识别交互系统
- STM32从入门到精通
- 基于stm32的灭火器
- 基于stm32f767的OLED显示代码
- STM32_ds18b20_oled显示
- STM32 ADC/I2C +UART编程
- HC-05蓝牙模块使用资料包STM32控制程序
- stm32c8t6主控的鼠标键盘
- 基于Cortex-M3的远程温湿度监测系统
- 基于STM32F334的buck电路开关电源的PCB版
- STM32心跳采集程序加labview实时显示系
- STM32F103C8T6+USBHID通信+USB调试助手
- STM32F103GRBL脱机代码-带屏幕控制
- STM32光栅尺采集例程
- STM32F103驱动CCS811
- stm32 搭载RFID模块实现的无人超市自助
- STM32F030& 051青风全套教程和程序例程
评论
共有 条评论