Skip to content

waitForConversion()

Arnd edited this page Dec 12, 2020 · 4 revisions

waitForConversion([deviceNumber]);

waits for conversion to complete as specified below for the device specified in "deviceNumber"; performing a wait for all devices if the "deviceNumber" parameter is omitted. This call is not required since the last measurement for bus voltage, shunt voltage, computed amps and computed watts is always available while the new value is being computed by the INA2xx in the background, either continuously or triggered by an explicit call. Using this call allows controlling the program to only retrieve new measurements. For example, if the averaging and precision is set high to that a measurement takes 5 seconds, a program reading the values more frequently than this time would merely get the previous reading's values, but a call to this routine would have the program wait until the measurement is complete.

The INA2xx sets an internal flag when the currently running conversion has completed, and this function will not return until the computation has completed. It also resets the flag so that it can be set by the next conversion.

Calling this function also clears the ALERT pin if that has been enabled with the alertOnConversion() function


Example:

INA_Class INA(); // Instantiate the class
void setup() {
  INA.begin(10,100000); // Max 10A and a 0.1 Ohm shunt resistor
  INA.setMode(INA_MODE_CONTINUOUS_BUS); // only compute bus values
  INA.setBusConversion(7);   // set bus conversion time 8.2446ms
  INA.setShuntConversion(7); // set shunt conversion time 8.2446ms
  INA.setAveraging(1024);    // set to 1024 samples
} // of setup
void loop() {
  INA.waitForConversion(); // conversion takes 1024*8.2446ms = 8.44 seconds on a INA226
  uint16_t BusMicroAmps = INA.getBusMicroAmps();
  Serial.print("Bus amperage is ");
  Serial.print((float)BusMicroAmps/1000,3);
  Serial.print(" mVolts\n");
} // of main loop