Skip to content

Rewritten calibration functions #37

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

ilario
Copy link

@ilario ilario commented Oct 16, 2024

Trying to measure small currents with a 1 Ohm (for currents up to 80 mA) or a 10 Ohm (for currents up to 4 mA) shunt resistor I created new calibration functions, following the instructions in the code comments and in the INA219 datasheet but they were all wrong.
For example, following the instructions I ended up using a calibration factor of 41, that resulted in very poor resolution.

So, I would consider that the instructions are confusing, and I rewrote them.

As you can see, the logic I propose is very different:

  1. for gain/8, use always 4096 as calibration factor (unless you are calibrating versus a reliably measured current). For other gains, 4096 is also a good choice (but also 8192 and other values would be equally as good, I just used 4096 for simplicity).
  2. choose the gain that better suits your needs
  3. consider replacing the shunt resistor when no gain is a good fit

Please check if the code works well also in other cases (I checked only the last two functions with shunt resistors of 1 and 10 Ohm and for currents far from the saturation ones).

@ilario
Copy link
Author

ilario commented Oct 16, 2024

Pylint was complaining about too many instance attributes because I used

self.calibration = 4096

instead of the previously present

self._cal_value = 4096
self._raw_calibration = self._cal_value

As I don't think I made the situation worse, I silenced the "too many instance attributes" error.
If you consider I should address this, please advise how.

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

Successfully merging this pull request may close these issues.

1 participant