資源簡介
使用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
- 下一篇:圖書管理系統源碼
評論
共有 條評論