Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible error with INA226 #66

Closed
SV-Zanshin opened this issue Aug 30, 2020 · 14 comments
Closed

Possible error with INA226 #66

SV-Zanshin opened this issue Aug 30, 2020 · 14 comments
Assignees
Labels
question Further information is requested

Comments

@SV-Zanshin
Copy link
Collaborator

SV-Zanshin commented Aug 30, 2020

Taras sent in the following:

Hi there. I used your library for INA226. Found an error. In the example DisplayReadings.ino
power is not calculated correctly. I add a screen.
V = 8,843 V
A = 35.736 mA
V * A = 8.843 * 35.736 = 316mW
, and in the example it turns out 253 mW.
Could this be a library error? Maybe it's my fault?

--
INA226 ERROR

The Shunt is 0.1Ohm and the original DisplayReadings.ino settings were used.

@SV-Zanshin SV-Zanshin added the question Further information is requested label Aug 30, 2020
@SV-Zanshin SV-Zanshin self-assigned this Aug 30, 2020
@SV-Zanshin
Copy link
Collaborator Author

I am looking at the library and can't locate an error. The "getBusMicroWatts()" function will read the next computed value, so if the current changes very quickly then you might get a value that doesn't correspond to the BusmA * BusVoltage. Could this be the case for you? Is the problem reproduceable?

@Samodelkin-YouTube
Copy link

Today I tried to use the library "INA226" ,everything works well there.
A 0.1348 V 19.120 W_ina 2.5788 W=V*A 2.5774 % 100.05

When I use the "INA" library, the power is incorrect, the error is 80%

A 0.1348 V 19.118 W_ina 2.0618 W=V*A 2.5771 % 80.01

@SV-Zanshin
Copy link
Collaborator Author

Since the Amps and Volts are the same in both cases, the problem lies in the computation of the Watts. Are you initializing both libraries with the same begin() statement?

@Samodelkin-YouTube
Copy link

"INA226.begin " and "INA.begin"

@SV-Zanshin
Copy link
Collaborator Author

I meant the parameters to the begin() - are they identical, especially the values for expected maximum amps

@Samodelkin-YouTube
Copy link

all the same

@SV-Zanshin
Copy link
Collaborator Author

How comfortable are you to make some small changes to your version of the library? I would like you to change the library by adding the following after line 634 "(int64_t)readWord(INA_POWER_REGISTER, ina.address) * (int64_t)ina.power_LSB / (int64_t)1000;"

The lines are:

Serial.print("power register is "); Serial.println(readWord(INA_POWER_REGISTER, ina.address)); Serial.print("power_LSB is "); Serial.println(ina.power_LSB);

@Gallium70
Copy link

Gallium70 commented Oct 24, 2020

According to the INA226 datasheet, page 16, for INA 226, the power LSB should be 25 * Current_LSB:
image

However, it's set to 20x in INA.cpp, line 27:
image

And 20/25 is exactly 80%.

@SV-Zanshin
Copy link
Collaborator Author

Good sleuthing - I am re-installing my PC this weekend (Thank You, Mr. Gates) but once all the software is installed I'll check this out.

@Samodelkin-YouTube
Copy link

Согласно таблице данных INA226 , стр. 16, для INA 226 младший разряд мощности должен быть равен 25 * Current_LSB:
.
Why is this necessary?
P.S. Installed the library INA226 ,everything works fine.

@Gallium70
Copy link

Согласно таблице данных INA226 , стр. 16, для INA 226 младший разряд мощности должен быть равен 25 * Current_LSB:
.
Why is this necessary?
P.S. Installed the library INA226 ,everything works fine.

As the datasheet explains,

This ratio is internally programmed to ensure that the scaling of the power calculation is within an acceptable range.

Below is my theory about this. The current and bus voltage are both stored in 16-bit registers. If you directy multiply them together, you'll need a 32-bit register to store the result. To put it into a 16-bit register, scaling is necessary(of course there's a loss in precision), and the scale factor should be somewhere near 2^(32-16)=65536, intuitively.
TI chooses a scale factor of 20000, since the LSB for the bus voltage is fixed at 1.25mV/bit (equivalent to 800x scaling), then the power LSB should be 20000/800=25x current LSB.
As for why it's exactly 20000 (not some other number), maybe only TI knows.

@SV-Zanshin
Copy link
Collaborator Author

SV-Zanshin commented Oct 25, 2020 via email

@SV-Zanshin
Copy link
Collaborator Author

First test looks good :)

SV-Zanshin pushed a commit that referenced this issue Oct 26, 2020
…esults in power values that are 20% off.
@SV-Zanshin
Copy link
Collaborator Author

Fixed in Development version 1.0.13, which should be promoted to a new master version in the next couple of weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants