INA219 interface help


Results 1 to 6 of 6

Threaded View

  1. #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.

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