-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Bug]: ina3221 inverts current over certain values (maybe signed int overflow?) #5933
Comments
Yes, you don't get any values at all if you haven't changed the address. You can see from the images here in getting values, and that they suddenly reverse ( particularly channel 2, the solar input) This does seem very typical of a twos compliment overflow. Where large values cause the first bit of the word to become a 1 which is then interpreted as a negative value. |
From my limited observations, once it falls back below a threshold it reverts back to reporting correctly. That seems slightly different to what we see in your graph. |
I sent the dev a note about this back in Nov. The fix should be to use an int32_t in getshuntvolt |
Had a quick look in the code and there is indeed a uint16 in there at the moment. |
I also had a look, before seeing your comment. It's absolutely in need of an int32_t as the multiplication by 40 overflows the int16. Going to try this on my local and see if it works |
I've only just managed to try my change (been unwell), and for the first time I'm seeing higher values. I've got about 40W of 12v solar which even in cloudy rainy Britain should generate more than 260mA, and it looks like it's working ok as the channel which monitors the power usage of the node is showing the same sort of value as before. I've only just spotted that the code for the inna3221 code is from a different repo. |
I've now managed to confirm the figure using a multimeter to monitor the current in line with one of the channels. It is correctly reporting current up to an amp now. I'll get the PR opened today. |
Thank you for staying on top of this, I've been meaning to check how I did it back in Nov, but... life. Will be nice not to have to worry about one more library during builds. |
has anyone been able to check if the INA3221 still works in .19, .20 or .21? |
I'm running a custom built .20, |
I flashed .21 on my NRF nodes and I noticed that Battery % from either INA3221 and 219 is broken. Also, idk if it related, but the INA219 values are no longer passed by ch3 curr/voltage. It stops broadcasting that packet, no problem with the INA3221... |
Sounds like a different issue to this one, but worth comparing the source from an earlier version to .20 |
I went back to the .18 code base and its working fine. |
Category
Other
Hardware
Rak4631
Firmware Version
2.4.* to at least 2.5.15
Description
I have an ina3221 setup with input 1 showing power being used, input 2 showing solar being provided, and input 3 showing the actual current flowing in out of the battery.
The first two should always be positive, the third should be positive when drawing current from the battery and negative when it's being charged.
With low current this is always the case, when one of them goes over about 250mA it inverts that value.
I suspect this is a mismatch in int lengths between the library that's taking the values and where it's being stored as it's typical of a 2s compliment overflow (although strangely would seem to be 9 bits)
Relevant log output
The text was updated successfully, but these errors were encountered: