Four ranges, one step
The INA219 has four gain settings, which span ±40, ±80, ±160 and ±320 mV across the shunt: 0.4, 0.8, 1.6 and 3.2 A on this board. One count is 0.1 mA on all four. What the narrow ranges buy is a smaller zero error, and what they cost is the headroom above it.
Four ranges
The chip's gain setting, called the PGA, picks how many millivolts across the shunt count as full scale. Across 100 mΩ each one becomes a current:
| Setting | Shunt range | Current range | Zero error, maximum |
|---|---|---|---|
| /1 | ±40 mV | ±0.4 A | ±1 mA |
| /2 | ±80 mV | ±0.8 A | ±1.25 mA |
| /4 | ±160 mV | ±1.6 A | ±1.5 mA |
| /8 | ±320 mV | ±3.2 A | ±2 mA |
/8 is what the chip starts in, and what the Adafruit library's default uses.
The step does not change
It is natural to expect a narrow range to measure in smaller steps. It does not. The shunt register counts in 10 µV at every setting, which on this board is 0.1 mA whether the range is 0.4 A or 3.2 A.
What does change is the zero error: how far from zero the chip may read with no current at all. TI's maximum is 100 µV at /1 and twice that at /8, so the narrow range halves the error that matters most at small currents.
Above the range
Above full scale the reading stops. A load drawing 600 mA reads 400 mA on the narrowest setting, and the reading does not move however much more it draws. A reading sitting exactly at full scale is the only sign, which is what makes it easy to miss.
So pick the widest range the load could reach, including the moment it starts, and only narrow it for a load you know stays small.
The three calls in the library
| Call | Range | Bus range | One count of current |
|---|---|---|---|
setCalibration_32V_2A() | 3.2 A | 32 V | 0.1 mA |
setCalibration_32V_1A() | about 1.3 A | 32 V | 0.04 mA |
setCalibration_16V_400mA() | 0.4 A | 16 V | 0.05 mA |
Only the last one uses the narrow range, and it also drops the bus range to 16 V. The middle one keeps /8, so its zero error is the widest setting's.
For the narrow range on a rail above 16 V, write the config register after the library's calibration: 32 V bus range, /1, 12-bit, both measured continuously.
ina.setCalibration_32V_2A(); // 0.1 mA a count
Wire.beginTransmission(0x40);
Wire.write(0x00); // config register
Wire.write(0x21); // 32 V, gain /1
Wire.write(0x9F); // 12-bit, continuous
Wire.endTransmission(); // now +-0.4 AWhen it does not work
The reading has reached the top of the range it is set to, and above that it pins. On setCalibration_16V_400mA that is 400 mA; on setCalibration_32V_1A it is about 1.3 A, where the current register runs out. Use setCalibration_32V_2A, the default, which reaches 3.2 A.
That call changes two things. As well as the narrow current range, it sets the bus voltage range to 16 V, so a rail above that cannot be read. For the narrow current range with the 32 V bus range, write the config register yourself, as the last section shows.
It makes each count of the current register 40 µA instead of 100 µA, but the shunt voltage underneath is still measured in 10 µV steps, which is 0.1 mA here. The extra digits are arithmetic, not measurement, and the range drops to about 1.3 A.
The error in a reading, in milliamps, and when it matters.
How far off a reading is →Edit this page — content/books/ina219/four-ranges.mdx
Questions about this product
See what other owners have asked, and read their solutions.
TK119 INA219 Current and Voltage Monitor
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.