The INA219 datasheet provides an example calibration workflow, but doesn’t really explain how some of the equations and constant values are derived. This article tries to fill in some of the gaps that weren’t obvious to me when I first read the datasheet.

Overview

“The INA219 is a high-side current shunt and power monitor with an I2C interface. The INA219 monitors both shunt drop and supply voltage, with programmable conversion times and filtering. A programmable calibration value, combined with an internal multiplier, enables direct readouts in amperes. An additional multiplying register calculates power in watts. The I2C interface features 16 programmable addresses.”

The INA219 calculates the current flowing through the “Current Shunt” sense resistor by first measuring the voltage across the resistor, and then applying Ohm’s law,

Bus voltage is measured directly on the load side of the shunt resistor ($V_{IN-}$).

Power is then calculated by multiplying these two sampled values,

Shunt and Bus Voltage Measurements

When measuring the shunt voltage, the internal ADC converts the analog voltage into a digital value which is stored in binary representation in the Shunt Voltage Register. The INA219 uses a 12-bit ADC, meaning it can resolve the analog voltage into $2^{12}$ (4096) discrete digital values. The ADC can measure voltages in the range of ±40mV (± for bidirectional current measurement). In order to extend this range, the INA219 has a PGA in front of the ADC that can be configured to divide the input voltage by a factor of 1, 2, 4, or 8. This gives the INA219 an effective range of ±40mV, ±80mV, ±160mV, or ±320mV respectively.

The Shunt Voltage Register is a signed 16-bit register, so you may be wondering how the 12-bit ADC can generate 16 bits of information? It turns out that the INA219 can be configured to average 2-128 samples to generate an average shunt voltage measurement. This averaging operation can provide additional resolution in the lowest 1, 2, or 3 bits when the shunt voltage range is set for ±80mV, ±160mV, or ±320mV respectively.

Similarly, the ADC converts the analog bus voltage ($V_{IN-}$) into a digital value and stores the result in the Bus Voltage Register. The full-scale BRNG can be selected between 16V and 32V (default), and there are 13 bits in the Bus Voltage Register that can be used for storing the bus voltage value. When using the 32V BRNG setting, the bus voltage is divided by 2 in the PGA before being sampled by the ADC. In this mode, the lowest bit may provide additional resolution if averaging is enabled.

The LSB step size specified in the data sheet can be verified as follows,

The raw values in the voltage registers can be converted to real voltage values by multiplying by the LSB step size,

This is generally applicable to all measurement registers in the INA219. The real world quantities that are represented by the register values can be obtained by simply multiplying the register value by the LSB step size,

Calibrating the INA219

Since the device cannot detect the value of $R_{shunt}$, the Calibration Register is used to inform the power measurement engine about the shunt resistance value. However, instead of specifying the value of $R_{shunt}$ directly, for the same $R_{shunt}$ value, the Calibration Register can be programmed differently depending on the type of result that is desired in the Current and Power Registers. From the datasheet,

“The Calibration Register can also be selected to provide values in the Current and Power Registers that either provide direct decimal equivalents of the values being measured, or yield a round LSB number.”

The power management engine calculates the Current and Power Register values according to the following equations,

Therefore, the Calibration Register value is simply a system-dependent scaling factor that converts the shunt voltage into current.

Starting with the equation for the shunt current,

Ohm’s law can be used to rearrange the equation for the Current Register,

Substituting for $V_{shunt}$,

Setting both Current Register equations equal to each other, it’s possible to solve for the Calibration Register,

Programming the Calibration Register

The INA219 datasheet provides a couple examples of how to program the Calibration Register. This example follows the same procedure described in the datasheet, where general equations are $\boxed{boxed}$, and followed by specific examples:

1. Determine the maximum bus voltage ($V_{bus\ max}$) for the system and configure BRNG based upon this value (16V or 32V):

$V_{bus\ max} = 16V$ (BRNG = 0)

2. Determine the maximum shunt voltage ($V_{shunt\ max}$) for the system and configure PGA gain based upon this value (÷ 1, ÷ 2, ÷ 4, or ÷ 8):

$V_{shunt\ max} = 40mV$ (PGA = ÷ 1)

3. Determine the value of the shunt resistor ($R_{shunt}$):

4. Based only on the values selected in the first three steps, calculate the maximum current that could possibly flow through the sense resistor:

5. Based on expected system performance, determine the actual expected maximum current where $I_{max\ expected} \leq I_{max\ possible}$.

For this system, let’s assume that it’s expected to draw up to 1A of current,

6. The Current Register is 16 bits wide, but since the device can measure bidirectional current, the MSB is used to indicate the sign in two’s compliment representation. Therefore, the remaining 15 bits can be used to represent the entire $I_{max\ expected}$ current range. Since the ADC resolution is 12 bits, it is desirable to choose the Current Register resolution between 12-15 bits, ideally as close to the 15-bit resolution as possible.

Calculate the minimum current LSB (15-bit resolution):

Calculate the maximum current LSB (12-bit resolution):

Choose a current LSB value, where $LSB_{minimum}$1 $\lt LSB_{current} \lt LSB_{maximum}$2. From the data sheet,

“Note that the results will have the most resolution when the minimum LSB is selected. Typically, an LSB is selected to be the nearest round number to the minimum LSB value.”

Let’s choose $LSB_{current} = 31μA$.

7. Compute the Calibration Register value:

8. The digital designers of the INA219 designed the power management engine to calculate the Power Register value according to the following equation3,

Substituting for each register variable,

Simplify,

Cancel the $P$ terms and take the reciprocal to obtain the $LSB_{power}$ equation,

Calculate the power LSB:

9. Compute the maximum current before overflow:

Since $1.015777A \gt I_{max\ possible}$,

10. Compute the maximum shunt voltage before overflow:

Since $0.04mV = V_{shunt\ max}$,

11. Compute the maximum power:

12. Optionally compute the corrected full-scale calibration based on measured current:

Revision History

Revision Date Description
1 07/06/2014 Initial release
2 08/19/2014 Fixes for Kramdown syntax
3 11/01/2014 Minor clarifications and fixes

Footnotes

1. If $LSB_{current} \lt LSB_{minimum}$, then the Current Register cannot express the full-scale range required by the maximum expected current (due to the 15-bit limitation). For example, if $I_{max\ expected}=1A$ and $LSB_{current} = 30μA$, then $30μA*32767=0.983A$, which will result in an overflow condition for any valid current in the range $0.983A$ to $1A$.

2. If $LSB_{current} \gt LSB_{maximum}$, the Current Register resolution decreases below 12-bits. For example, if $I_{max\ expected}=1A$ and $LSB_{current}=500μA$, the resolution decreases to 11-bits $% $.