-
-
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
Shunt calibration register 15 Bit instead of 16? #47
Comments
Thanks for this issue. Need to investigate this asap probably coming week. |
Bug confirmed! |
Did you patch the library to support the INA236 (80/20 mV) ? It might easy to implement a derived class. |
@josef929 If you have time, can you confirm the develop branch works for you? |
Yes, I implemented the selectable range. I rewrote the code for the INA 236 (changed the names and checked the registers), but most of the code is basically the same. I can sent you the code for the INA 236 class if you want. |
Yes I can do that. |
Please do, so I can make it available for the larger audience if you agree |
documents-export-2024-5-27.zip |
Quick look shows a few differences, two functions a number of constants. |
@josef929 // auto scale calibration if needed.
uint32_t calib = round(0.00512 / (_current_LSB * shunt*pow(4,adcrange)));
while (calib > 32768) <<<<<<<< should be > 32767
{
_current_LSB *= 2;
calib >>= 1;
}
_writeRegister(INA236_CALIBRATION, calib); |
@josef929 So green light for a separate repository? |
Yes, thats fine with me. |
OK, I will set up a new repo, add your name - credits where credits are due. |
I tested the 0.6.0 version. The returned current values were all as expected, especially for small maximal currents, where the 15 Bit shunt calibration register limits the resolution. I checked both true and false option for the normalization of the calibration. |
Thanks for testing! Created a develop branch + PR - https://github.com/RobTillaart/INA236 |
found another minor point, can you confirm that it makes sense? When calling setADCRange(..), the value of _voltage_LSB must change as the next reading will be done with a different voltageLSB. |
Yes and No. |
Exactly, And yes, if that setting is not optimal or even out of range (setting 20 mV while actual voltage is higher) is the risk of the user. |
BTW, your decision to set the best range in setMaxCurrentShunt is 100% right (imho). |
Understood. In such scenarios, the value of the shunt register also needs to be updated (either by a factor of 4 or 1/4, depending on the previous Range ). |
The build doesn't cooperate 100%, it fails on I2C somehow. |
@josef929 (still investigating the build CI which works for the 226 and fails for the 236 although they are nearly identical) |
@josef929 |
Hi Rob Tillaart,
I am a physicist at the Universität Heidelberg. In our experiment, we are using the INA 236 chip. It is similar to the INA 226 but has two selectable ranges (~ 80 mV/20 mV). By implementing the range selection in your code, I encountered a possible mistake in the code.
In the function "setMaxCurrentShunt," during normalisation, the minimal current_lsb is calculated (lines 244-247). This value is based on the shunt_register size and some internal factors. You assumed the register to be 16 Bits, but according to the datasheet, only 15 Bits are writable.
In Line 294, at the auto scale calibration, the shunt calibration value is compared to 16 bits rather than 15 Bits.
This has only consequences if the optimal current_lsb is larger than 15Bit.
Thank you for the effort you put into this project.
Best regards
Josef
The text was updated successfully, but these errors were encountered: