a
Revision 3:e0ddd1dfa2cc, committed 2021-07-31
- Comitter:
- MPPT51
- Date:
- Sat Jul 31 06:25:47 2021 +0000
- Parent:
- 2:8950b0f31d73
- Commit message:
- ina226 commit
Changed in this revision
INA226.cpp | Show annotated file Show diff for this revision Revisions of this file |
INA226.hpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/INA226.cpp Sat Nov 24 18:37:00 2012 +0000 +++ b/INA226.cpp Sat Jul 31 06:25:47 2021 +0000 @@ -67,13 +67,13 @@ int INA226::getCurrent(double *I_) { unsigned short val; - if(rawRead(0x04,&val) == 0){ + if(rawRead(0x04,&val) == 0){ //INA226は0x04 INA260は0x01 char *s_p = reinterpret_cast<char *>(&val); short d_s; char *d_p = reinterpret_cast<char *>(&d_s); *(d_p + 0) = *(s_p + 0); *(d_p + 1) = *(s_p + 1); - *I_ = static_cast<double>(d_s) /* * 1.25 */; + *I_ = static_cast<double>(d_s) /* 1.25*/; //INA260では1.25をかける(電流caliblationしないから) return 0; } return 1; @@ -81,5 +81,11 @@ int INA226::setCurrentCalibration(unsigned short val) { - return rawWrite(0x05,val); + return rawWrite(0x05,val); //datasheet(p.21)より0x05はCalibrationResisterへの書き込みを指定している } +int INA226::setConfigResister(unsigned short config) +{ + return rawWrite(0x00,config); //0x00でINA226のConfigResisterに指定している(datasheet p.21) + //config(INA226.hで設定)は変換時間と平均回数などの指定をしているデータ + //どちらも大きいほどノイズの影響を受けづらいがデータ取得時間が長くなる。実装システムに合わせて調整。 +}
--- a/INA226.hpp Sat Nov 24 18:37:00 2012 +0000 +++ b/INA226.hpp Sat Jul 31 06:25:47 2021 +0000 @@ -22,8 +22,8 @@ * @param i2c_ instance of I2C. * @param addr_ I2C slave address. * @param freq_ I2C frequency. - */ - INA226(I2C &i2c_,int addr_ = 0x80,int freq_ = 100000); + */ //GNDGND(G-G):0x80, Vs+Vs+(1-1):0x8A, SDASDA(D-D):0x94, SCLSCL(C-C):0x9E, GNDVs+(G-1):0x82 + INA226(I2C &i2c_,int addr_ = 0x80,int freq_ = 100000); //0x94= ?, 0x8A=VsVs_11, 0x80=GNDGND_GG /** * Check INA226 exist. * @@ -67,8 +67,10 @@ * @param val write value; * @return 0:Read OK / !0:Read NG */ - int setCurrentCalibration(unsigned short val = 0x0A00); - + int setCurrentCalibration(unsigned short val = 0x1AAA); + //int setConfigResister(unsigned short config = 0x6600 | 0x01C0 | 0x0038 | 0x0007); //0x456F=>0b 0100 010 101 101 111(datasheet pp21-23確認) + int setConfigResister(unsigned short config = 0x456F); + private: I2C &i2c; int i2c_addr;