PDA

View Full Version : INA219 interface help



iw2fvo
- 28th November 2013, 15:53
Good day to all of you in the forum,

I have to use the INA219 from Texas Instrument to monitor power, current and voltage .
I saw the data sheet but I found its intrface and setup very difficult and complicated for me.
Is there anyone in the forum that had some experience to share ?
Thanks for any help on the matter.
Regards,
Ambrogio

Amoque
- 29th November 2013, 13:32
I have no experience with the chip, but both Adafruit (Arduino) and Parallax (Propeller chip) have tutorials that will help with connection and set up (presuming that hints in other languages are enough). At least you might get some code started to post for further help...

http://learn.adafruit.com/downloads/pdf/adafruit-ina219-current-sensor-breakout.pdf
http://www.parallax.com/product/29130

iw2fvo
- 29th November 2013, 22:54
thanks Amoque for the suggestions.
A picBasic sample code will be useful to start. I am not familiary with Arduino and C !
I hope for someone to help with the picbasic code .
Thanks again,
Ambrogio
IW2FVO

Brice138
- 1st December 2013, 19:09
I have worked with that chip. Here is some sample code written for the PIC18F6720.
Only the voltage math is done here, you'll have to figure out the current and power figure's based on your sense resistor.
Hope this helps.... Brice.

#CONFIG
__config _HS_OSC & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF

#ENDCONFIG

Include "modedefs.bas" ' Include serial modes
DEFINE OSC 20
DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 1
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0
DEFINE DEBUG_PACING 1000
DEFINE I2C_SLOW 1

DPIN Var PORTB.4 ' I2C data pin
CPIN Var PORTB.5 ' I2C clock pin
B0 Var Word
B1 Var Word
B2 Var Word
B22 Var Word
B3 Var Word
B4 Var Word
B5 Var Word
ADDR Var Byte

ADDR=$80 'I2C ADDRESS OF INA219

'I2CWRITE DPIN,CPIN,ADDR,$00,[$1FFF] 'SET 16V RANGE, 128 SAMPLES, 68.1 MS.
PAUSE 100
I2CWRITE DPIN,CPIN,ADDR,$05,[$2000] 'CAL REG 10uA/BIT RES.
PAUSE 100
mainloop:
I2CREAD DPIN,CPIN,ADDR,$00,[B0] 'GET CONFIG
I2CREAD DPIN,CPIN,ADDR,$01,[B1] 'GET SHUNT VOLTAGE
I2CREAD DPIN,CPIN,ADDR,$02,[B2] 'GET BUS VOLTAGE
I2CREAD DPIN,CPIN,ADDR,$03,[B3] 'GET POWER
I2CREAD DPIN,CPIN,ADDR,$04,[B4] 'GET CURRENT
I2CREAD DPIN,CPIN,ADDR,$05,[B5] 'GET CALIBRATION

B2=B2>>3 'SHIFT RIGHT 3 PLACES D3-D0
B2=B2*4 'MULTIPLY RESULT BY 4
B22=B2 'SAVE TO EXTRACT MICRO AND MILLI VOLT
B2=B2/1000 'DIVIDE BY 1000 TO GET ONE AND TENS VOLT
'FORMULA: BUS VOTAGE/4mv = BUS VOLTAGE
'IN DECIMAL.
DEBUG "CONFIG: ",DEC B0,13
DEBUG "SHUNT VOLAGE: ",DEC B1,13
DEBUG "BUS VOLTAGE: ",DEC B2,".",DEC3 B22,13
DEBUG "POWER: ",DEC B3,13
DEBUG "CURRENT: ",DEC B4,13
DEBUG "CALIBRATION: ",DEC B5,13
DEBUG " ",13
PAUSE 10000
GOTO mainloop
END

iw2fvo
- 2nd December 2013, 07:57
Thanks a lot Brice.
That is very useful to me.
best regards,
Ambrogio
iw2fvo
North Italy

iw2fvo
- 19th June 2017, 14:23
Good day Brice,
I used for years the program you have sent to me and it worked well sine I had the need to know the bus voltage only.
Now I am interested in getting the power and the current in addition to the voltage.
I have to read a max current of 3A and I used a 0.1 ohm shunt resistor.
By applying the formula I did set the currentLSB= 100uA/bit and the calibration at 4096 dec ( 1000h).
The real current into the load is about 50 mA and the power is 248 mW calculated by hand calculator.
My Pic gives the following results:

CONFIG: 8191
SHUNT VOLAGE: 501
BUS VOLTAGE: 4.968
POWER: 125
CURRENT: 501
CALIBRATION: 4096

the bus volt is OK but current and power are not_OK.

I read the data sheet but I am not able to find the solution at the moment.
I think there is a scaling problem somewhere around ... current is 10 times more , power is the double .. shunt_volt is 100 time more.
I will appreciate very much if You could help me in find out a solution.
Thanks in advance for the assistance.
regards,
Ambrogio

ps: when we write the calculated CAL value ( 4096 dec ) do we have to take into account that bit_0 is not used and so write 8192 or just write 4096 in the relevant register?