INA219 interface help


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326

    Default INA219 interface help

    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

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: INA219 interface help

    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/...r-breakout.pdf
    http://www.parallax.com/product/29130

  3. #3
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: INA219 interface help

    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

  4. #4
    Join Date
    Dec 2013
    Posts
    1


    Did you find this post helpful? Yes | No

    Default Re: INA219 interface help

    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
    Last edited by Brice138; - 1st December 2013 at 19:17. Reason: Make post clearer.

  5. #5
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: INA219 interface help

    Thanks a lot Brice.
    That is very useful to me.
    best regards,
    Ambrogio
    iw2fvo
    North Italy

  6. #6
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: INA219 interface help

    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?

Similar Threads

  1. SPI interface
    By malc-c in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 9th January 2011, 01:06
  2. Interface for 16f818
    By davekav in forum Serial
    Replies: 4
    Last Post: - 17th April 2008, 11:33
  3. 'SCI' interface
    By ecua64 in forum Off Topic
    Replies: 0
    Last Post: - 29th September 2005, 16:02
  4. DMX Interface
    By electronicsuk in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th July 2005, 13:13
  5. PC interface
    By tigrot in forum Schematics
    Replies: 1
    Last Post: - 9th October 2004, 19:32

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts