diff --git a/Adafruit_INA219.cpp b/Adafruit_INA219.cpp index 47f480c..5d61056 100644 --- a/Adafruit_INA219.cpp +++ b/Adafruit_INA219.cpp @@ -290,6 +290,45 @@ void Adafruit_INA219::powerSave(bool on) { } } +/*! + * @brief Set Bus ADC resolution and averaging options + * @param resolution + * resolution option enum + */ +void Adafruit_INA219::setBusADCResolution(uint16_t resolution) { + // See the INA219_CONFIG_BADCRES enums for the various options + // The default set by setCalibration functions is NA219_CONFIG_BADCRES_12BIT + + Adafruit_BusIO_Register config_reg = + Adafruit_BusIO_Register(i2c_dev, INA219_REG_CONFIG, 2, MSBFIRST); + + uint32_t val = config_reg.read(); + // Mask off area and set our new values + val &= ~INA219_CONFIG_BADCRES_MASK; + val |= resolution; + _success = config_reg.write(val, 2); +} + +/*! + * @brief Set Shunt ADC resolution and averaging options + * @param resolution + * resolution option enum + */ +void Adafruit_INA219::setShuntADCResolution(uint16_t resolution) { + // See the INA219_CONFIG_SADCRES enums for the various options + // The default set by setCalibration functions is + // INA219_CONFIG_SADCRES_12BIT_1S_532US + + Adafruit_BusIO_Register config_reg = + Adafruit_BusIO_Register(i2c_dev, INA219_REG_CONFIG, 2, MSBFIRST); + + uint32_t val = config_reg.read(); + // Mask off area and set our new values + val &= ~INA219_CONFIG_SADCRES_MASK; + val |= resolution; + _success = config_reg.write(val, 2); +} + /*! * @brief Configures to INA219 to be able to measure up to 32V and 1A * of current. Each unit of current corresponds to 40uA, and each diff --git a/Adafruit_INA219.h b/Adafruit_INA219.h index 6b982d5..565ef9a 100644 --- a/Adafruit_INA219.h +++ b/Adafruit_INA219.h @@ -174,6 +174,8 @@ class Adafruit_INA219 { float getCurrent_mA(); float getPower_mW(); void powerSave(bool on); + void setBusADCResolution(uint16_t resolution); + void setShuntADCResolution(uint16_t resolution); bool success(); private: