This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

INA220: INA220 - current calculation

Part Number: INA220
Other Parts Discussed in Thread: INA190

Hi,

I have INA220. And I need read current.

So my shunt resistor is: 0,2R

Read shunt register is: 1766 dec

And my measure current is: 0,022mA

INA220 is in default settings:

Configuration = 0x399F

And my question is: How to convert 1766dec to mA? I try everything, but I don't know why my calculation is fail.

  • Hi Rob,

    can you give us a code snippet showing how you configure the INA220? And a schematic would be helpful...

    Kai
  • I modification my code. And now I'm here:

    Caltulation with information:

    // VBUS_MAX = 16V             (Assumes 32V, can also be set to 16V)
    // VSHUNT_MAX = 0.04          (Assumes Gain 1, 40mV, can also be 0.32 0.16, 0.08, 0.04)
    // RSHUNT = 0.2               (Resistor value in ohms)
    
    // 1. Determine max possible current
    // MaxPossible_I = VSHUNT_MAX / RSHUNT
    // MaxPossible_I = 0,2A
    
    // 2. Determine max expected current
    // MaxExpected_I = 0.2A
    
    // 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
    // MinimumLSB = MaxExpected_I/32767
    // MinimumLSB = 0.0000061              (6.1uA per bit)
    // MaximumLSB = MaxExpected_I/4096
    // MaximumLSB = 0.000048            	(48uA per bit)
    
    // 4. Choose an LSB between the min and max values
    //    (Preferrably a roundish number close to MinLSB)
    // CurrentLSB = 0.00005 (50uA per bit)
    
    // 5. Compute the calibration register
    // Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
    // Cal = 2048 (0x1000)
    
    ina220_calValue = 4096;	//hex: 0x1000
    
    // 6. Calculate the power LSB
    // PowerLSB = 20 * CurrentLSB
    // PowerLSB = 0.001 (2mW per bit)
    
    // 7. Compute the maximum current and shunt voltage values before overflow
    //
    // Max_Current = Current_LSB * 32767
    // Max_Current = 1.63835A before overflow
    //
    // If Max_Current > Max_Possible_I then
    //    Max_Current_Before_Overflow = MaxPossible_I
    // Else
    //    Max_Current_Before_Overflow = 0.2
    // End If
    //
    // Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
    // Max_ShuntVoltage = 0.04V
    //
    // If Max_ShuntVoltage >= VSHUNT_MAX
    //    Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
    // Else
    //    Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
    // End If
    // Max_ShuntVoltage_Before_Overflow = 0.04V
    
    // 8. Compute the Maximum Power
    // MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
    // MaximumPower = 0.2 * 16V
    // MaximumPower = 3.2W
    
    // Set multipliers to convert raw current/power values
    // ina220_currentDivider_mA = 20;  // Current LSB = 50uA per bit (1000/50 = 20)
    // ina220_powerDivider_mW = 1;     // Power LSB = 1mW per bit

    And here is my call function:

    if (INA220__SetCalibrateRegister(I2Cbus_INA220, INA220_ADDRESS, 0x1000) < 0)
    {
    //fail write
    }
    //range 16V; range 40mV; 12bit; 12bit, continuous mode if (0 != INA220__init(I2Cbus_INA220, INA220_ADDRESS, AUBOARD_BSP_INVERSE_INA220_RESISTOR, 0x19F)) { //fail write }

    Can everybody verificatim my calculation??

  • Hello Rob,

    Thank you for using the TI forum.

    Looking at the numbers you gave us, it appears that you are trying to measure too small of a current for the INA220. The Vshunt LSB for this device is 10uV, and with your shunt and current we get 0.2ohms x 22uA = 4.4uV, which is less than half of the LSB. So, for your specific setup, you may want to consider using the INA190 and an ADC to measure your current.

  • I make a mistake in my calculation:

    So I repeated:

    I measure max I with INA220: 1,6A

    Real measure by multimeter:

    I real measure: 88mA

    Measure voltage on Vshunt: 17,66mV

    And my calculation:

    // VBUS_MAX = 32V             (Assumes 32V. can also be set to 16V)
    // VSHUNT_MAX = 0.32          (Assumes Gain 1. 40mV. can also be 0.32 0.16. 0.08. 0.04)
    // RSHUNT = 0.2               (Resistor value in ohms)
    
    // 1. Determine max possible current
    // MaxPossible_I = VSHUNT_MAX / RSHUNT
    // MaxPossible_I = 1.6A
    
    // 2. Determine max expected current
    // MaxExpected_I = 0.15A
    
    // 3. Calculate possible range of LSBs (Min = 15-bit. Max = 12-bit)
    // MinimumLSB = MaxExpected_I/32767
    // MinimumLSB = 0.0000046             (4.6uA per bit)
    // MaximumLSB = MaxExpected_I/4096
    // MaximumLSB = 0.000036               (36uA per bit)
    
    // 4. Choose an LSB between the min and max values
    //    (Preferrably a roundish number close to MinLSB)
    // CurrentLSB = 0.00005 (50uA per bit)
    
    // 5. Compute the calibration register
    // Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
    // Cal = 4096 (0x1000)
    
    ina220_calValue = 4096; //hex: 0x1000
    
    // 6. Calculate the power LSB
    // PowerLSB = 20 * CurrentLSB
    // PowerLSB = 0.001 (1mW per bit)
    
    // 7. Compute the maximum current and shunt voltage values before overflow
    //
    // Max_Current = Current_LSB * 32767
    // Max_Current = 1.63835A before overflow
    //
    // If Max_Current > Max_Possible_I then
    //    Max_Current_Before_Overflow = MaxPossible_I
    // Else
    //    Max_Current_Before_Overflow = 0.2
    // End If
    //
    // Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
    // Max_ShuntVoltage = 0.32767V
    //
    // If Max_ShuntVoltage >= VSHUNT_MAX
    //    Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
    // Else
    //    Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
    // End If
    // Max_ShuntVoltage_Before_Overflow = 0.04V
    
    // 8. Compute the Maximum Power
    // MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
    // MaximumPower = 1.6 * 32V
    // MaximumPower = 51W
    
    // Set multipliers to convert raw current/power values
    // ina220_currentDivider_mA = 0.2;  // Current LSB = 50uA per bit (1000/50 = 20)
    // ina220_powerDivider_mW = 1;     // Power LSB = 1mW per bit

    Now, when I set:

    INA220 - configuration register: 0x399f (default value)

    INA220 - Calibration register: 0x1000

    In current register is good value: 88mA. But I calculated currentDivider to = 20

    // ina220_currentDivider_mA = 0.2;  // Current LSB = 50uA per bit (1000/50 = 20

  • Hey Rob,

    I'm glad you were able to figure it out. Let us know if you have any more questions.