Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

setAveraging()

Arnd edited this page Sep 24, 2017 · 5 revisions

setAveraging(averages[,deviceNumber]);

The averaging, as detailed below, is set for INA226 "deviceNumber"; if the parameter is not specified then all INA226s discovered are set to the same value.

The INA226 has two settings which effectively determine how often 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.

This function controls the second setting, namely how many of the measurements taken for the bus and shunt are averaged together before placing the results into the INA226 output registers. The number of averages range from the default of 1 measurement to a maximum of 1024 measurements.

The quickest conversion rate is 140μs so the maximum measurement rate can be ~7142 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 will take. Longer measurements and higher number of averages produces more accurate results.

The following are valid values for averaging:

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

This function accepts an integer number and will round it downwards to the next possible averaging value.


Example:

INA226_Class INA226(); // Instantiate the class
void setup() {
  INA226.begin(50,100000); // 5V bus with maximum current of 500mA
                           // A 0.1 Ohm shunt resistor generates 50mV max
  INA226.setAveraging(18); // rounded down to 16 
  INA226.setBusConversion(); // defaults to 8.244ms maximum
  INA226.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 = INA226.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