@@ -476,3 +476,60 @@ def set_calibration_16V_400mA(self): # pylint: disable=invalid-name
476476 self .bus_adc_resolution = ADCResolution .ADCRES_12BIT_1S
477477 self .shunt_adc_resolution = ADCResolution .ADCRES_12BIT_1S
478478 self .mode = Mode .SANDBVOLT_CONTINUOUS
479+
480+ def set_calibration_16V_5A (self ): # pylint: disable=invalid-name
481+ """Configures to INA219 to be able to measure up to 16V and 5000mA of current. Counter
482+ overflow occurs at 8.0A.
483+
484+ .. note:: These calculations assume a 0.02 ohm shunt resistor is present"""
485+ # Calibration which uses the highest precision for
486+ # current measurement (0.1mA), at the expense of
487+ # only supporting 16V at 5000mA max.
488+
489+ # VBUS_MAX = 16V
490+ # VSHUNT_MAX = 0.16 (Assumes Gain 3, 160mV)
491+ # RSHUNT = 0.02 (Resistor value in ohms)
492+
493+ # 1. Determine max possible current
494+ # MaxPossible_I = VSHUNT_MAX / RSHUNT
495+ # MaxPossible_I = 8.0A
496+
497+ # 2. Determine max expected current
498+ # MaxExpected_I = 5.0A
499+
500+ # 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
501+ # MinimumLSB = MaxExpected_I/32767
502+ # MinimumLSB = 0.0001529 (uA per bit)
503+ # MaximumLSB = MaxExpected_I/4096
504+ # MaximumLSB = 0.0012207 (uA per bit)
505+
506+ # 4. Choose an LSB between the min and max values
507+ # (Preferrably a roundish number close to MinLSB)
508+ # CurrentLSB = 0.00016 (uA per bit)
509+ self ._current_lsb = 0.1524 # in milliamps
510+
511+ # 5. Compute the calibration register
512+ # Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
513+ # Cal = 13434 (0x347a)
514+
515+ self ._cal_value = 13434
516+
517+ # 6. Calculate the power LSB
518+ # PowerLSB = 20 * CurrentLSB
519+ # PowerLSB = 0.003 (3.048mW per bit)
520+ self ._power_lsb = 0.003048
521+
522+ # 7. Compute the maximum current and shunt voltage values before overflow
523+ #
524+ # 8. Compute the Maximum Power
525+ #
526+
527+ # Set Calibration register to 'Cal' calcutated above
528+ self ._raw_calibration = self ._cal_value
529+
530+ # Set Config register to take into account the settings above
531+ self .bus_voltage_range = BusVoltageRange .RANGE_16V
532+ self .gain = Gain .DIV_4_160MV
533+ self .bus_adc_resolution = ADCResolution .ADCRES_12BIT_1S
534+ self .shunt_adc_resolution = ADCResolution .ADCRES_12BIT_1S
535+ self .mode = Mode .SANDBVOLT_CONTINUOUS
0 commit comments