diff --git a/examples/ina260_latch.py b/examples/ina260_latch.py index bab21e0..a70e21d 100644 --- a/examples/ina260_latch.py +++ b/examples/ina260_latch.py @@ -16,44 +16,42 @@ # catch exception on init, no INA260 chip found print(r_e) raise r_e - else: - # set overcurrent limit flag and threshold value - # 0x0008 x 1,25 mA = 10 mA as alert limit - ina260.alert_limit = 0x0008 - - # alert pin is asserted, can be check with gpiozero - ina260.overcurrent_limit = True - - # keep the flag high until MASK_ENABLE register will be read - ina260.alert_latch_enable = True - - ina260.mode = Mode.CONTINUOUS - - # set higher conversion time and wait its value before each read - ina260.current_conversion_time = ConversionTime.TIME_8_244_ms - for _ in enumerate(range(5)): - time.sleep(ConversionTime.get_seconds(ina260.current_conversion_time)) - print( - "Current: %.2f mA Voltage: %.2f V Power:%.2f mW" - % (ina260.current, ina260.voltage, ina260.power) - ) - - # supposing meanwhile the alert limit was exceeded, setting an higher limit - # and clear the ALERT - # 0x0100 x 1,25 mA = 320 mA as alert limit - ina260.alert_limit = 0x0100 - - # alert function flag bit should be true if alert threshold was exceeded - print("Alert function flag: {}".format(ina260.alert_function_flag)) - - # in latch mode, reading the register clears the ALERT & alert function flag - print("MASK register: {}".format(ina260.mask_enable)) - - # reset the whole chip and wait 2 sec - ina260.reset_bit = True - time.sleep(2) + + # set overcurrent limit flag and threshold value + # 0x0008 x 1,25 mA = 10 mA as alert limit + ina260.alert_limit = 0x0008 + + # alert pin is asserted, can be check with gpiozero + ina260.overcurrent_limit = True + + # keep the flag high until MASK_ENABLE register will be read + ina260.alert_latch_enable = True + + ina260.mode = Mode.CONTINUOUS + + # set higher conversion time and wait its value before each read + ina260.current_conversion_time = ConversionTime.TIME_8_244_ms + for _ in enumerate(range(5)): + time.sleep(ConversionTime.get_seconds(ina260.current_conversion_time)) print( - "MASK_REGISTER check, must be 0x0000 after reset: {}".format( - ina260.mask_enable - ) + "Current: %.2f mA Voltage: %.2f V Power:%.2f mW" + % (ina260.current, ina260.voltage, ina260.power) ) + + # supposing meanwhile the alert limit was exceeded, setting an higher limit + # and clear the ALERT + # 0x0100 x 1,25 mA = 320 mA as alert limit + ina260.alert_limit = 0x0100 + + # alert function flag bit should be true if alert threshold was exceeded + print("Alert function flag: {}".format(ina260.alert_function_flag)) + + # in latch mode, reading the register clears the ALERT & alert function flag + print("MASK register: {}".format(ina260.mask_enable)) + + # reset the whole chip and wait 2 sec + ina260.reset_bit = True + time.sleep(2) + print( + "MASK_REGISTER check, must be 0x0000 after reset: {}".format(ina260.mask_enable) + )