Go Down

Topic: INA219 voltage/current sense module - Modifying the Library for 0.01R resistor (Read 250 times) previous topic - next topic

Castingflame

I have been working for 3 days solid trying to get better readings from a INA219 Adafruit module. While the device is quite accurate with the default Adafruit library (which is basically all taken from the INA219 Ti datasheet)  I have struggled to use it with a non standard value of shut resistor. I have several of these modules so one of them I modified, replacing the R100 (0.1 Ohm) with a R010 (0.01 Ohm). The actual measurement of the resistor is 0.02 Ohms but I have tried both 0.01 and 0.02 in the calculations.


 

My Target is 8Amps @ 24V

24V @ 4.5A   the INA219 is showing as   24.9V    @   3.9A /4A        <<< NOT so good at the higher current  end
24V@  4.9 / 5A   the INA219 is showing as  24.89V  @4.5/4.6A
24V@  1A  the INA219 is showing as  24.89V  @1.020Amps     <<< so good at the lower end



You will see all the comments in the Library and I have checked it against the Ti Datasheet for the INA219 and it looks okay. I have made changes to the..  'ina219_powerMultiplier_mW'   because I believe there is an error in the library. It looks like copy and paste error from the original author.


This is a section from the Adafruit Library that I have added based on an already working section but modified to use my resistor....

Code: [Select]

[code]void Adafruit_INA219::setCalibration_32V_16A(void)
{
// By default we use a pretty huge range for the input voltage,
// which probably isn't the most appropriate choice for system
// that don't use a lot of power. But all of the calculations
// are shown below if you want to change the settings. You will
// also need to change any relevant register settings, such as
// setting the VBUS_MAX to 16V instead of 32V, etc.

// VBUS_MAX = 32V (Assumes 32V, can also be set to 16V)
// VSHUNT_MAX = 0.32 (Assumes Gain 8, 320mV, can also be 0.16, 0.08, 0.04)
// RSHUNT = 0.02 (Resistor value in ohms)


// 1. Determine max possible current
// MaxPossible_I = VSHUNT_MAX / RSHUNT
// 0.32/ 0.02
// MaxPossible_I = 16A

// 2. Determine max expected current
// MaxExpected_I = 8.0A

// 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
// MinimumLSB = MaxExpected_I/32767
// MinimumLSB = 0.000244 (244uA per bit)
// MaximumLSB = MaxExpected_I/4096
// MaximumLSB = 0.001953 (1953uA per bit)

// 4. Choose an LSB between the min and max values
// (Preferrably a roundish number close to MinLSB)
// CurrentLSB = 0.000300 (300uA per bit)

// 5. Compute the calibration register
// Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
// 0.04096 / (0.000006)
// trunc Cal = 6826

ina219_calValue = 6826;

// 6. Calculate the power LSB
// PowerLSB = 20 * CurrentLSB
// PowerLSB = 0.006 (6mW per bit)

// 7. Compute the maximum current and shunt voltage values before overflow
//
// Max_Current = Current_LSB * 32767
// Max_Current = 9.9301A before overflow
//
// If Max_Current > Max_Possible_I then
// Max_Current_Before_Overflow = MaxPossible_I
// Else
// Max_Current_Before_Overflow = Max_Current
//
// SO - Max_Current_Before_Overflow = 9.9301A <<< True
//
//End If
//
// Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
// Max_ShuntVoltage = 0.198602V
//
// If Max_ShuntVoltage >= VSHUNT_MAX
// Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
// Else
// Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
//
// SO - Max_ShuntVoltage_Before_Overflow = 0.198602V <<< True
//
// End If

// 8. Compute the Maximum Power
// MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
// MaximumPower = 9.9301 * 32V
// MaximumPower = 317.7632Watts
//
// @ 24V Max= 9.9301 * 24V = 238.3224Watts


// Set multipliers to convert raw current/power values
ina219_currentDivider_mA = 3.33; // Current LSB = 300uA per bit (1000/300 = 3.33)
ina219_powerMultiplier_mW = 0.1666; // Power LSB = 6mW per bit (1/6)

// Set Calibration register to 'Cal' calculated above
wireWriteRegister(INA219_REG_CALIBRATION, ina219_calValue);

// Set Config register to take into account the settings above
uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
INA219_CONFIG_GAIN_8_320MV |
INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
wireWriteRegister(INA219_REG_CONFIG, config);
}

[/code]


Thanks in advance for any help you can give me.

WattsThat

1. What are the specs for the .01R device? Manufacturer/model?
2. What are you using to measure it to say it is .02 ohms?
3. What the specs of the ammeter you're using to measure the current you claim is wrong?

Vacuum tube guy in a solid state world

Castingflame

Quote
1. What are the specs for the .01R device? Manufacturer/model?
BOURNS  CRL2512-FU-R010ELF





Quote
2. What are you using to measure it to say it is .02 ohms?
https://www.amazon.co.uk/Acompatible-5000-Handheld-Meter-Tl-21/dp/B00S298KJO

in DC resistance mode.



Quote
3. What the specs of the ammeter you're using to measure the current you claim is wrong?
I have tried several meters including a clamp meter and they are similar. I am not just looking at what my Power supply is telling me, although it is not a mile out. The higher currents is where it goes wrong as you would expect.

hammy

The errors involved in measuring such small resistances are huge - you would need a four wire technique to eliminate contact resistance as voltage drop along leads .
The emf generated by the junction of different metals may be significant.

Self heating etc will have an effect at higher currents .

The only sensible thing is to calibrate your system in terms of measured current against output from the sensor . Trying to calculate it is pointless with the equipment and techniques you have.


WattsThat

Thank you for the detailed info, most helpful.

One last question, based on the comments in your code, is your intended maximum 16 amps? If so, your resistor is underrated and it's going to have significant drift since it's a 1 watt part and the tempco is 600 ppm. Even 4 amps is going to warm it up and have it change several percent.

I would trust the Bourns 1% resistor be really 10 milliohms at 25 C. But, with that tempco, it's not going to stay within tolerance under load since power is going up with the current squared.
Vacuum tube guy in a solid state world

Wawa

A 10A or 20A shunt with kelvin connections is many times bigger than that smd resistor.
They are about $2.50, shipped, on ebay.
Leo..

Castingflame

One last question, based on the comments in your code, is your intended maximum 16 amps? If so, your resistor is underrated and it's going to have significant drift since it's a 1 watt part and the tempco is 600 ppm. Even 4 amps is going to warm it up and have it change several percent.

Yes that is very true. That is the target, however, at the moment I am only using it up to 4(sh)Amps for the reasons you state. When I have managed to get this accurate enough I will redesign everything for a custom PCB and a different shunt as this is part of a larger project.




I would trust the Bourns 1% resistor be really 10 milliohms at 25 C. But, with that tempco, it's not going to stay within tolerance under load since power is going up with the current squared.
So far up to 4(ish) amps it is only a fraction warmer (just touching it with my hand). I do have a temp probe I could check it with. I will take this on-board when choosing my final Shunt so thanks for the advice there.




A 10A or 20A shunt with kelvin connections is many times bigger than that smd resistor.
They are about $2.50, shipped, on ebay.
Leo..
I have also been told about a 4 wire device elsewhere but you have given me the all important word. Kelvin! That is new to me and I have just done a five minute google about it. This will be the way I will go now. A big thanks for that.



Also, for the good of the thread I have also been pointed to an alternate library to the Adafruit one. It does not take 8 sets of calculations only a required Voltage and Current Target. You can find it here.

https://github.com/SV-Zanshin/INA



I will give the new library a go but I will definately buy a new 4 wire shut that will be suited up to 32v 10A target while having a good tempco for that target.



Thank you guys. You have given me some really good advice here and I will use it all. I will also report back here my final design for the good of the community.

SV_Zanshin

Have you used the library at https://github.com/SV-Zanshin/INA yet? If you call the begin() method with your 0.01 Ohm Kelvin-connected resistor as "begin(8,10000);" that will work correctly. But the INA219 is only rated to 26V and using a high voltage (such as when charging a 24V battery system with 28.8V) will blow out the INA219, other devices such as the INA226 or INA260 go all the way to 36V.

Go Up