Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Adafruit_INA219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Adafruit_INA219.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down