Skip to content

Commit f43322d

Browse files
committed
added Gain.AUTO. Updated values for 16V_5A
1 parent e179b04 commit f43322d

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

adafruit_ina219.py

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class Gain:
7171
DIV_2_80MV = 0x01 # shunt prog. gain set to /2, 80 mV range
7272
DIV_4_160MV = 0x02 # shunt prog. gain set to /4, 160 mV range
7373
DIV_8_320MV = 0x03 # shunt prog. gain set to /8, 320 mV range
74+
AUTO = -1 # shunt prog. gain set to automatic
7475

7576
class ADCResolution:
7677
"""Constants for ``bus_adc_resolution`` or ``shunt_adc_resolution``"""
@@ -501,14 +502,14 @@ def set_calibration_16V_5A(self):
501502

502503
# 4. Choose an LSB between the min and max values
503504
# (Preferrably a roundish number close to MinLSB)
504-
# CurrentLSB = 0.00016 (50uA per bit)
505+
# CurrentLSB = 0.00016 (uA per bit)
505506
self._current_lsb = 0.1524 # in milliamps
506507

507508
# 5. Compute the calibration register
508509
# Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
509-
# Cal = 26869 (0x68f5)
510+
# Cal = 13434 (0x347a)
510511

511-
self._cal_value = 26869
512+
self._cal_value = 13434
512513

513514
# 6. Calculate the power LSB
514515
# PowerLSB = 20 * CurrentLSB
@@ -517,41 +518,15 @@ def set_calibration_16V_5A(self):
517518

518519
# 7. Compute the maximum current and shunt voltage values before overflow
519520
#
520-
# Max_Current = Current_LSB * 32767
521-
# Max_Current = 1.63835A before overflow
522-
#
523-
# If Max_Current > Max_Possible_I then
524-
# Max_Current_Before_Overflow = MaxPossible_I
525-
# Else
526-
# Max_Current_Before_Overflow = Max_Current
527-
# End If
528-
#
529-
# Max_Current_Before_Overflow = MaxPossible_I
530-
# Max_Current_Before_Overflow = 0.4
531-
#
532-
# Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
533-
# Max_ShuntVoltage = 0.04V
534-
#
535-
# If Max_ShuntVoltage >= VSHUNT_MAX
536-
# Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
537-
# Else
538-
# Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
539-
# End If
540-
#
541-
# Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
542-
# Max_ShuntVoltage_Before_Overflow = 0.04V
543-
544521
# 8. Compute the Maximum Power
545-
# MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
546-
# MaximumPower = 0.4 * 16V
547-
# MaximumPower = 6.4W
522+
#
548523

549524
# Set Calibration register to 'Cal' calcutated above
550525
self._raw_calibration = self._cal_value
551526

552527
# Set Config register to take into account the settings above
553528
self.bus_voltage_range = BusVoltageRange.RANGE_16V
554-
self.gain = Gain.DIV_2_80MV
529+
self.gain = Gain.AUTO
555530
self.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S
556531
self.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S
557532
self.mode = Mode.SANDBVOLT_CONTINUOUS

examples/ina219_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
print("Shunt Voltage: {:9.6f} V".format(shunt_voltage))
4040
print("Load Voltage: {:6.3f} V".format(bus_voltage))
4141
print("Current: {:9.6f} A".format(current/1000))
42-
print("Power: {:9.6f} W".format(power))
42+
print("Power: {:9.6f} mW".format(power*1000))
4343
print("")
4444

4545
time.sleep(2)

0 commit comments

Comments
 (0)