This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OpenPlotter I2C 3.x.x - INA219 settings
#6
I have edited the title of this thread to be more explicit.

In older posts I have recommended to add these settings:


Quote:set_calibration_32V_2A
       """Configures to INA219 to be able to measure up to 32V and 2A of current. Counter
       overflow occurs at 3.2A.
       .. note:: These calculations assume a 0.1 shunt ohm resistor is present
       """
set_calibration_32V_1A
       """Configures to INA219 to be able to measure up to 32V and 1A of current. Counter overflow
       occurs at 1.3A.
       .. note:: These calculations assume a 0.1 ohm shunt resistor is present"""

set_calibration_16V_400mA
       """Configures to INA219 to be able to measure up to 16V and 400mA of current. Counter
       overflow occurs at 1.6A.
       .. note:: These calculations assume a 0.1 ohm shunt resistor is present"""
    
set_calibration_16V_5A
       """Configures to INA219 to be able to measure up to 16V and 5000mA of current. Counter
       overflow occurs at 8.0A.
       .. note:: These calculations assume a 0.02 ohm shunt resistor is present"""

But after a deeper analysis of the code I can se that those pre-configured "calibration" settings seem just the most usual or expected uses of the module but there could be many more possible uses.

Those pre-configured uses are the combination of different values of these constants:

bus_voltage_range
gain
bus_adc_resolution
shunt_adc_resolution
mode

We could expose these constants and its fixed values as "sensor settings" in openplotter but we would also need to expose these private variables:

_current_lsb
_cal_value
_power_lsb

and here comes the problem because calculating these private variables is really complex for normal users. Here is an example of calculating them for "set_calibration_16V_5A"


Quote:       """Configures to INA219 to be able to measure up to 16V and 5000mA of current. Counter
       overflow occurs at 8.0A.

       .. note:: These calculations assume a 0.02 ohm shunt resistor is present"""
       # Calibration which uses the highest precision for
       # current measurement (0.1mA), at the expense of
       # only supporting 16V at 5000mA max.

       # VBUS_MAX = 16V
       # VSHUNT_MAX = 0.16          (Assumes Gain 3, 160mV)
       # RSHUNT = 0.02              (Resistor value in ohms)

       # 1. Determine max possible current
       # MaxPossible_I = VSHUNT_MAX / RSHUNT
       # MaxPossible_I = 8.0A

       # 2. Determine max expected current
       # MaxExpected_I = 5.0A

       # 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
       # MinimumLSB = MaxExpected_I/32767
       # MinimumLSB = 0.0001529              (uA per bit)
       # MaximumLSB = MaxExpected_I/4096
       # MaximumLSB = 0.0012207              (uA per bit)

       # 4. Choose an LSB between the min and max values
       #    (Preferrably a roundish number close to MinLSB)
       # CurrentLSB = 0.00016 (uA per bit)
       self._current_lsb = 0.1524  # in milliamps

       # 5. Compute the calibration register
       # Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
       # Cal = 13434 (0x347a)

       self._cal_value = 13434

       # 6. Calculate the power LSB
       # PowerLSB = 20 * CurrentLSB
       # PowerLSB = 0.003 (3.048mW per bit)
       self._power_lsb = 0.003048


We could do that but we would need a good documentation or at least values for all these variables for our own pre-configured settings.

This is the result of the html tool to calculate them in your example:

[Image: attachment.php?aid=1961]
but that result is for arduino and we should make sure those settings are the same as the python settings:

_cal_value
_current_lsb
_power_lsb

bus_voltage_range
gain
bus_adc_resolution
shunt_adc_resolution
mode

Does this all make sense to you?
Reply


Messages In This Thread
RE: I2C INA 3.1.0 Settings - by tobias.e - 2022-11-12, 08:03 PM
RE: I2C INA 3.1.0 Settings - by Sailoog - 2022-11-12, 08:23 PM
RE: I2C INA 3.1.0 Settings - by tobias.e - 2022-11-12, 09:55 PM
RE: I2C INA 3.1.0 Settings - by RichFind - 2022-11-14, 03:31 AM
RE: OpenPlotter I2C 3.x.x - INA219 settings - by Sailoog - 2022-11-14, 01:37 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)