Skip to content

setAveraging()

Arnd edited this page Jun 25, 2018 · 4 revisions

setAveraging(averages[,deviceNumber]);

The averaging, as detailed below, is set for INA2xx "deviceNumber"; if the parameter is not specified then all INA2xxs on the I2C bus are set to the same value.

The INA2xxx devices have two settings which effectively determine how often measurements are made and how accurate the readings are. The first of these settings is how long a period to sample the bus and shunt voltages; these can be individually set using the setBusConversion() and setShuntConversion() call respectively. The second Setting is this function, which defines how many of the measurements taken for the bus and shunt are averaged together before placing the results into the INA2xx output registers. The number of averages range from the default of 1 measurement to a maximum of 1024 measurements, but this is device dependent as the INA219 only allows a Maximum of only 128 measurements for averaging.

The quickest conversion rate is 148μs so the maximum measurement rate can be ~6756 measurements per second (for just one of either the bus voltage or the shunt voltage). Using the maximum conversion time of 8.244ms and the maximum average of 1024 the measurement goes up to one measurement every ~8.4 seconds (per measure of bus voltage or shunt voltage). Using combinations of conversion times and averages lets the programmer control exactly how long each measurement may take. Longer measurements and higher number of averages produce more accurate results, but take much longer.

While any number can be entered for the "averages" parameter, the value specified is rounded down the one of the following valid values for averaging:

Averages
1(default)
4
16
64
128
256
512
1024

Example:

INA_Class INA(); // Instantiate the class
void setup() {
  INA.begin(10,100000); // 10A max and a 0.1 Ohm shunt resistor
  INA.setAveraging(18); // rounded down to 16 
  INA.setBusConversion(); // defaults to 8.244ms maximum
  INA.setShuntConversion(); // defaults to 8.244ms maximum
  // Each measurement will now take 8.244*16 = 131.904ms, or about 3.75 per second for both
} // of setup
void loop() {
  uint16_t BusMillivolts = INA.getBusMillivolts();
  Serial.print("Bus voltage is ");
  Serial.print((float)BusMillivolts/1000,3);
  Serial.print(" Volts\n");
  delay(5000); // wait 5 seconds before next measurement        
} // of main loop