-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
normalize routine in setMaxCurrent not working? #11
Comments
Thanks for reporting the issue, might take a few days |
Will start investigating today. |
No setup to test. Your analysis is looks correct. |
@morrowwm |
It looks good. The current calculated by the INS226 is very close to that measured by my multimeter. |
Alternatively, what do you think of this approach to forcing current_LSB to be an integer, i.e. normalized? Starting at line 217, calculate calib, forcing no fractional part with round(). Then recalculate current_LSB using that calib. This approach does not change the max current allowed as much.
|
why didn't I think of that!
Would make sense to me if one could do the whole math in integer units. |
Would make sense to me if one could do the whole math in integer units.
I agree, integer would align better with reality in the 16 bit registers. I haven't really figured out how to do it, though.
I think the suggested approach is close to that.
You could think of it as:1) determine the factor between one bit and current, measured in amperes. Max current is 15 bits, 0x7FFF. The factor is maxCurrent / 0x7FFF <-- you'r already doing this.2) but we want factor to be an integer, so round it3) recalculate maxCurrent using the rounded factor
On Wednesday, February 2, 2022, 11:59:36 a.m. AST, Rob Tillaart ***@***.***> wrote:
Then recalculate current_LSB using that calib.
why didn't I think of that!
Very good point as that way the internal variables stay way more consistent.
forcing current_LSB to be an integer
Would make sense to me if one could do the whole math in integer units.
Can you name some advantages?
I make a note in the future section in the readme,
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Just pushed a new version of .cpp file. I added some give it a try. |
Doing all the math in integer will need more testing and I have so HW nearby (and enough time) |
I had to remove the old normalize lines, starting at about line 235. Then I defined printdebug and also added more digits to the _maxCurrent debug: With normalize = false:
And with normalize = true:
|
Here's my test version.
I should learn how to use git more completely.
On Wednesday, February 2, 2022, 01:52:30 p.m. AST, Rob Tillaart ***@***.***> wrote:
Just pushed a new version of .cpp file.
I added some #ifdef at the start of the function for switching on/off print statements.
furthermore it includes your suggestion to calculate current_LSB back from rounded calib.
give it a try.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
So the new version works and still mayches your multimeter? |
Yes, it works well. Matches my multimeter to about 1 part in 400, both normalized and not. I'll see if I can find a setup that will hold a stable, higher current and get more than three digits to measure. |
You might need to check the datasheet if you can get much better than 1 in 400 in terms of precission. |
My multimeter is not very good. I will need to increase amperage to get any more precision.
On Wednesday, February 2, 2022, 05:50:59 p.m. AST, Rob Tillaart ***@***.***> wrote:
You might need to check the datasheet if you can get much better than 1 in 400 in terms of precission.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
The datasheet mentions several causes of small errors (see below) which in the end add up so a difference of 0.25% is not bad at all, given that most multimeters are in the 0.2% range themselves. You need a DMM with 0.02% or better to make better measurements (professional or lab equipment) |
@morrowwm |
I am setting the calibration register using
INA.setMaxCurrentShunt(5, 0.097563559322034, false);
added to setup() in your INA226_demo sketch and seeing values that match what my multimeter measures fairly closely.
I uncommented and augmented the debug print statements in setMaxCurrentShunt():
This showed:
The _current_LSB value has shifted by a factor of 10
It looks like
should be
I made that change and see:
Thank you for this library, and figuring out the calibration process.
The text was updated successfully, but these errors were encountered: