使用INA226芯片测量电流和总线电压,可测量uA级别电流,可自动计算功率,本案例使用0.1欧电阻,可更换更小电阻,以测量更大电流
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
.CA.... 131 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序CHANGELOG
.CA.... 6774 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序INA226.cpp
.CA.... 4770 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序INA226.h
.CA.... 1097473 2015-09-02 14:54 ina226Arduino-INA226-程序Arduino-INA226-程序ina226.pdf
.CA.... 1493 2015-11-03 13:19 ina226Arduino-INA226-程序Arduino-INA226-程序INA226_alertINA226_alert.ino
.CA.... 1284 2015-11-03 13:19 ina226Arduino-INA226-程序Arduino-INA226-程序INA226_latchINA226_latch.ino
.CA.... 4563 2015-11-03 13:19 ina226Arduino-INA226-程序Arduino-INA226-程序INA226_simpleINA226_simple.ino
.CA.... 35121 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序LICENSE
.CA.... 265 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序README.md
.CA.... 110953 2016-03-07 19:07 ina226Arduino-INA226-程序CJMCU-226原理图.pdf
.CA.... 1001977 2016-07-11 09:42 ina226Arduino-INA226-程序.zip
.CA.... 110953 2016-03-07 19:07 ina226CJMCU-226原理图.pdf
.CA.... 1097473 2015-09-02 14:54 ina226ina226.pdf
.CA.... 894140 2019-03-17 17:14 ina226INA226中文.pdf
.CA.... 24423 2016-07-01 18:06 ina226INA226模块+stm32f429COREcmsis_armcc.h
.CA.... 114498 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cm4.h
.CA.... 3620 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cmFunc.h
.CA.... 3636 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cmInstr.h
.CA.... 3662 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cmSimd.h
.CA.... 31694 2016-07-01 18:06 ina226INA226模块+stm32f429COREstartup_stm32f429xx.s
.CA.... 166216 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncLegacystm32_hal_legacy.h
.CA.... 13345 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal.h
.CA.... 36376 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_adc.h
.CA.... 18952 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_adc_ex.h
.CA.... 36361 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_can.h
.CA.... 30747 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_cec.h
.CA.... 17044 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_conf_template.h
.CA.... 20217 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_cortex.h
.CA.... 7298 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_crc.h
.CA.... 23327 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_cryp.h
............此处省略311个文件信息
/*
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 ina226Arduino-INA226-程序Arduino-INA226-程序CHANGELOG
.CA.... 6774 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序INA226.cpp
.CA.... 4770 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序INA226.h
.CA.... 1097473 2015-09-02 14:54 ina226Arduino-INA226-程序Arduino-INA226-程序ina226.pdf
.CA.... 1493 2015-11-03 13:19 ina226Arduino-INA226-程序Arduino-INA226-程序INA226_alertINA226_alert.ino
.CA.... 1284 2015-11-03 13:19 ina226Arduino-INA226-程序Arduino-INA226-程序INA226_latchINA226_latch.ino
.CA.... 4563 2015-11-03 13:19 ina226Arduino-INA226-程序Arduino-INA226-程序INA226_simpleINA226_simple.ino
.CA.... 35121 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序LICENSE
.CA.... 265 2014-07-20 03:35 ina226Arduino-INA226-程序Arduino-INA226-程序README.md
.CA.... 110953 2016-03-07 19:07 ina226Arduino-INA226-程序CJMCU-226原理图.pdf
.CA.... 1001977 2016-07-11 09:42 ina226Arduino-INA226-程序.zip
.CA.... 110953 2016-03-07 19:07 ina226CJMCU-226原理图.pdf
.CA.... 1097473 2015-09-02 14:54 ina226ina226.pdf
.CA.... 894140 2019-03-17 17:14 ina226INA226中文.pdf
.CA.... 24423 2016-07-01 18:06 ina226INA226模块+stm32f429COREcmsis_armcc.h
.CA.... 114498 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cm4.h
.CA.... 3620 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cmFunc.h
.CA.... 3636 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cmInstr.h
.CA.... 3662 2016-07-01 18:06 ina226INA226模块+stm32f429COREcore_cmSimd.h
.CA.... 31694 2016-07-01 18:06 ina226INA226模块+stm32f429COREstartup_stm32f429xx.s
.CA.... 166216 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncLegacystm32_hal_legacy.h
.CA.... 13345 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal.h
.CA.... 36376 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_adc.h
.CA.... 18952 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_adc_ex.h
.CA.... 36361 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_can.h
.CA.... 30747 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_cec.h
.CA.... 17044 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_conf_template.h
.CA.... 20217 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_cortex.h
.CA.... 7298 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_crc.h
.CA.... 23327 2016-07-01 18:06 ina226INA226模块+stm32f429HALLIBSTM32F4xx_HAL_DriverIncstm32f4xx_hal_cryp.h
............此处省略311个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)