PX4 Firmware
PX4 Autopilot Software http://px4.io
ina226.cpp File Reference
#include <string.h>
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/getopt.h>
#include <drivers/device/i2c.h>
#include <lib/parameters/param.h>
#include <lib/perf/perf_counter.h>
#include <drivers/drv_hrt.h>
#include <uORB/uORB.h>
#include <uORB/topics/power_monitor.h>
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
Include dependency graph for ina226.cpp:

Go to the source code of this file.

Classes

class  INA226
 

Namespaces

 ina226
 Local functions in support of the shell command.
 

Macros

#define INA226_RAW
 
#define INA226_BUS_DEFAULT   PX4_I2C_BUS_EXPANSION
 
#define INA226_BASEADDR   0x41 /* 7-bit address. 8-bit address is 0x41 */
 
#define INA226_REG_CONFIGURATION   (0x00)
 
#define INA226_REG_SHUNTVOLTAGE   (0x01)
 
#define INA226_REG_BUSVOLTAGE   (0x02)
 
#define INA226_REG_POWER   (0x03)
 
#define INA226_REG_CURRENT   (0x04)
 
#define INA226_REG_CALIBRATION   (0x05)
 
#define INA226_REG_MASKENABLE   (0x06)
 
#define INA226_REG_ALERTLIMIT   (0x07)
 
#define INA226_MFG_ID   (0xfe)
 
#define INA226_MFG_DIEID   (0xff)
 
#define INA226_MFG_ID_TI   (0x5449)
 
#define INA226_MFG_DIE   (0x2260)
 
#define INA226_MODE_SHIFTS   (0)
 
#define INA226_MODE_MASK   (7 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_SHUTDOWN   (0 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_SHUNT_TRIG   (1 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_BUS_TRIG   (2 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_SHUNT_BUS_TRIG   (3 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_ADC_OFF   (4 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_SHUNT_CONT   (5 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_BUS_CONT   (6 << INA226_MODE_SHIFTS)
 
#define INA226_MODE_SHUNT_BUS_CONT   (7 << INA226_MODE_SHIFTS)
 
#define INA226_VSHCT_SHIFTS   (3)
 
#define INA226_VSHCT_MASK   (7 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_140US   (0 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_204US   (1 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_332US   (2 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_588US   (3 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_1100US   (4 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_2116US   (5 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_4156US   (6 << INA226_VSHCT_SHIFTS)
 
#define INA226_VSHCT_8244US   (7 << INA226_VSHCT_SHIFTS)
 
#define INA226_VBUSCT_SHIFTS   (6)
 
#define INA226_VBUSCT_MASK   (7 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_140US   (0 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_204US   (1 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_332US   (2 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_588US   (3 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_1100US   (4 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_2116US   (5 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_4156US   (6 << INA226_VBUSCT_SHIFTS)
 
#define INA226_VBUSCT_8244US   (7 << INA226_VBUSCT_SHIFTS)
 
#define INA226_AVERAGES_SHIFTS   (9)
 
#define INA226_AVERAGES_MASK   (7 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_1   (0 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_4   (1 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_16   (2 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_64   (3 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_128   (4 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_256   (5 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_512   (6 << INA226_AVERAGES_SHIFTS)
 
#define INA226_AVERAGES_1024   (7 << INA226_AVERAGES_SHIFTS)
 
#define INA226_CONFIG   (INA226_MODE_SHUNT_BUS_CONT | INA226_VSHCT_588US | INA226_VBUSCT_588US | INA226_AVERAGES_64)
 
#define INA226_RST   (1 << 15)
 
#define INA226_LEN   (1 << 0)
 
#define INA226_APOL   (1 << 1)
 
#define INA226_OVF   (1 << 2)
 
#define INA226_CVRF   (1 << 3)
 
#define INA226_AFF   (1 << 4)
 
#define INA226_CNVR   (1 << 10)
 
#define INA226_POL   (1 << 11)
 
#define INA226_BUL   (1 << 12)
 
#define INA226_BOL   (1 << 13)
 
#define INA226_SUL   (1 << 14)
 
#define INA226_SOL   (1 << 15)
 
#define INA226_CONVERSION_INTERVAL   (100000-7) /* 100 ms / 10 Hz */
 
#define MAX_CURRENT   164.0f /* 164 Amps */
 
#define DN_MAX   32768.0f /* 2^15 */
 
#define INA226_CONST   0.00512f /* is an internal fixed value used to ensure scaling is maintained properly */
 
#define INA226_SHUNT   0.0005f /* Shunt is 500 uOhm */
 
#define INA226_VSCALE   0.00125f /* LSB of voltage is 1.25 mV */
 
#define swap16(w)   __builtin_bswap16((w))
 

Functions

__EXPORT int ina226_main (int argc, char *argv[])
 
int ina226::start ()
 Attempt to start driver on all available I2C busses. More...
 
int ina226::start_bus (int i2c_bus)
 Start the driver on a specific bus. More...
 
int ina226::stop ()
 Stop the driver. More...
 
int ina226::info ()
 Print a little info about the driver. More...
 
static void ina2262_usage ()
 

Variables

INA226ina226::g_dev
 

Detailed Description

Author
David Sidrane david.nosp@m._s5@.nosp@m.usa.n.nosp@m.et

Driver for the I2C attached INA226

Definition in file ina226.cpp.

Macro Definition Documentation

◆ DN_MAX

#define DN_MAX   32768.0f /* 2^15 */

Definition at line 139 of file ina226.cpp.

Referenced by INA226::INA226().

◆ INA226_AFF

#define INA226_AFF   (1 << 4)

Definition at line 128 of file ina226.cpp.

◆ INA226_APOL

#define INA226_APOL   (1 << 1)

Definition at line 125 of file ina226.cpp.

◆ INA226_AVERAGES_1

#define INA226_AVERAGES_1   (0 << INA226_AVERAGES_SHIFTS)

Definition at line 109 of file ina226.cpp.

◆ INA226_AVERAGES_1024

#define INA226_AVERAGES_1024   (7 << INA226_AVERAGES_SHIFTS)

Definition at line 116 of file ina226.cpp.

◆ INA226_AVERAGES_128

#define INA226_AVERAGES_128   (4 << INA226_AVERAGES_SHIFTS)

Definition at line 113 of file ina226.cpp.

◆ INA226_AVERAGES_16

#define INA226_AVERAGES_16   (2 << INA226_AVERAGES_SHIFTS)

Definition at line 111 of file ina226.cpp.

◆ INA226_AVERAGES_256

#define INA226_AVERAGES_256   (5 << INA226_AVERAGES_SHIFTS)

Definition at line 114 of file ina226.cpp.

◆ INA226_AVERAGES_4

#define INA226_AVERAGES_4   (1 << INA226_AVERAGES_SHIFTS)

Definition at line 110 of file ina226.cpp.

◆ INA226_AVERAGES_512

#define INA226_AVERAGES_512   (6 << INA226_AVERAGES_SHIFTS)

Definition at line 115 of file ina226.cpp.

◆ INA226_AVERAGES_64

#define INA226_AVERAGES_64   (3 << INA226_AVERAGES_SHIFTS)

Definition at line 112 of file ina226.cpp.

◆ INA226_AVERAGES_MASK

#define INA226_AVERAGES_MASK   (7 << INA226_AVERAGES_SHIFTS)

Definition at line 108 of file ina226.cpp.

◆ INA226_AVERAGES_SHIFTS

#define INA226_AVERAGES_SHIFTS   (9)

Definition at line 107 of file ina226.cpp.

◆ INA226_BASEADDR

#define INA226_BASEADDR   0x41 /* 7-bit address. 8-bit address is 0x41 */

Definition at line 56 of file ina226.cpp.

Referenced by INA226::init().

◆ INA226_BOL

#define INA226_BOL   (1 << 13)

Definition at line 133 of file ina226.cpp.

◆ INA226_BUL

#define INA226_BUL   (1 << 12)

Definition at line 132 of file ina226.cpp.

◆ INA226_BUS_DEFAULT

#define INA226_BUS_DEFAULT   PX4_I2C_BUS_EXPANSION

Definition at line 55 of file ina226.cpp.

Referenced by ina2262_usage(), and ina226_main().

◆ INA226_CNVR

#define INA226_CNVR   (1 << 10)

Definition at line 130 of file ina226.cpp.

◆ INA226_CONFIG

Definition at line 118 of file ina226.cpp.

Referenced by INA226::INA226().

◆ INA226_CONST

#define INA226_CONST   0.00512f /* is an internal fixed value used to ensure scaling is maintained properly */

Definition at line 140 of file ina226.cpp.

Referenced by INA226::init().

◆ INA226_CONVERSION_INTERVAL

#define INA226_CONVERSION_INTERVAL   (100000-7) /* 100 ms / 10 Hz */

Definition at line 137 of file ina226.cpp.

Referenced by INA226::Run(), and INA226::start().

◆ INA226_CVRF

#define INA226_CVRF   (1 << 3)

Definition at line 127 of file ina226.cpp.

◆ INA226_LEN

#define INA226_LEN   (1 << 0)

Definition at line 124 of file ina226.cpp.

◆ INA226_MFG_DIE

#define INA226_MFG_DIE   (0x2260)

Definition at line 71 of file ina226.cpp.

Referenced by INA226::probe().

◆ INA226_MFG_DIEID

#define INA226_MFG_DIEID   (0xff)

Definition at line 68 of file ina226.cpp.

Referenced by INA226::probe().

◆ INA226_MFG_ID

#define INA226_MFG_ID   (0xfe)

Definition at line 67 of file ina226.cpp.

Referenced by INA226::probe().

◆ INA226_MFG_ID_TI

#define INA226_MFG_ID_TI   (0x5449)

Definition at line 70 of file ina226.cpp.

Referenced by INA226::probe().

◆ INA226_MODE_ADC_OFF

#define INA226_MODE_ADC_OFF   (4 << INA226_MODE_SHIFTS)

Definition at line 80 of file ina226.cpp.

◆ INA226_MODE_BUS_CONT

#define INA226_MODE_BUS_CONT   (6 << INA226_MODE_SHIFTS)

Definition at line 82 of file ina226.cpp.

◆ INA226_MODE_BUS_TRIG

#define INA226_MODE_BUS_TRIG   (2 << INA226_MODE_SHIFTS)

Definition at line 78 of file ina226.cpp.

◆ INA226_MODE_MASK

#define INA226_MODE_MASK   (7 << INA226_MODE_SHIFTS)

Definition at line 75 of file ina226.cpp.

Referenced by INA226::INA226().

◆ INA226_MODE_SHIFTS

#define INA226_MODE_SHIFTS   (0)

Definition at line 74 of file ina226.cpp.

Referenced by INA226::INA226().

◆ INA226_MODE_SHUNT_BUS_CONT

#define INA226_MODE_SHUNT_BUS_CONT   (7 << INA226_MODE_SHIFTS)

Definition at line 83 of file ina226.cpp.

◆ INA226_MODE_SHUNT_BUS_TRIG

#define INA226_MODE_SHUNT_BUS_TRIG   (3 << INA226_MODE_SHIFTS)

Definition at line 79 of file ina226.cpp.

Referenced by INA226::INA226().

◆ INA226_MODE_SHUNT_CONT

#define INA226_MODE_SHUNT_CONT   (5 << INA226_MODE_SHIFTS)

Definition at line 81 of file ina226.cpp.

◆ INA226_MODE_SHUNT_TRIG

#define INA226_MODE_SHUNT_TRIG   (1 << INA226_MODE_SHIFTS)

Definition at line 77 of file ina226.cpp.

◆ INA226_MODE_SHUTDOWN

#define INA226_MODE_SHUTDOWN   (0 << INA226_MODE_SHIFTS)

Definition at line 76 of file ina226.cpp.

◆ INA226_OVF

#define INA226_OVF   (1 << 2)

Definition at line 126 of file ina226.cpp.

◆ INA226_POL

#define INA226_POL   (1 << 11)

Definition at line 131 of file ina226.cpp.

◆ INA226_RAW

#define INA226_RAW

Definition at line 40 of file ina226.cpp.

◆ INA226_REG_ALERTLIMIT

#define INA226_REG_ALERTLIMIT   (0x07)

Definition at line 66 of file ina226.cpp.

Referenced by INA226::collect().

◆ INA226_REG_BUSVOLTAGE

#define INA226_REG_BUSVOLTAGE   (0x02)

Definition at line 61 of file ina226.cpp.

Referenced by INA226::collect().

◆ INA226_REG_CALIBRATION

#define INA226_REG_CALIBRATION   (0x05)

Definition at line 64 of file ina226.cpp.

Referenced by INA226::collect(), and INA226::init().

◆ INA226_REG_CONFIGURATION

#define INA226_REG_CONFIGURATION   (0x00)

Definition at line 59 of file ina226.cpp.

Referenced by INA226::collect(), INA226::init(), and INA226::measure().

◆ INA226_REG_CURRENT

#define INA226_REG_CURRENT   (0x04)

Definition at line 63 of file ina226.cpp.

Referenced by INA226::collect().

◆ INA226_REG_MASKENABLE

#define INA226_REG_MASKENABLE   (0x06)

Definition at line 65 of file ina226.cpp.

Referenced by INA226::collect().

◆ INA226_REG_POWER

#define INA226_REG_POWER   (0x03)

Definition at line 62 of file ina226.cpp.

Referenced by INA226::collect().

◆ INA226_REG_SHUNTVOLTAGE

#define INA226_REG_SHUNTVOLTAGE   (0x01)

Definition at line 60 of file ina226.cpp.

Referenced by INA226::collect().

◆ INA226_RST

#define INA226_RST   (1 << 15)

Definition at line 120 of file ina226.cpp.

Referenced by INA226::init().

◆ INA226_SHUNT

#define INA226_SHUNT   0.0005f /* Shunt is 500 uOhm */

Definition at line 141 of file ina226.cpp.

Referenced by INA226::INA226(), and INA226::init().

◆ INA226_SOL

#define INA226_SOL   (1 << 15)

Definition at line 135 of file ina226.cpp.

◆ INA226_SUL

#define INA226_SUL   (1 << 14)

Definition at line 134 of file ina226.cpp.

◆ INA226_VBUSCT_1100US

#define INA226_VBUSCT_1100US   (4 << INA226_VBUSCT_SHIFTS)

Definition at line 102 of file ina226.cpp.

◆ INA226_VBUSCT_140US

#define INA226_VBUSCT_140US   (0 << INA226_VBUSCT_SHIFTS)

Definition at line 98 of file ina226.cpp.

◆ INA226_VBUSCT_204US

#define INA226_VBUSCT_204US   (1 << INA226_VBUSCT_SHIFTS)

Definition at line 99 of file ina226.cpp.

◆ INA226_VBUSCT_2116US

#define INA226_VBUSCT_2116US   (5 << INA226_VBUSCT_SHIFTS)

Definition at line 103 of file ina226.cpp.

◆ INA226_VBUSCT_332US

#define INA226_VBUSCT_332US   (2 << INA226_VBUSCT_SHIFTS)

Definition at line 100 of file ina226.cpp.

◆ INA226_VBUSCT_4156US

#define INA226_VBUSCT_4156US   (6 << INA226_VBUSCT_SHIFTS)

Definition at line 104 of file ina226.cpp.

◆ INA226_VBUSCT_588US

#define INA226_VBUSCT_588US   (3 << INA226_VBUSCT_SHIFTS)

Definition at line 101 of file ina226.cpp.

◆ INA226_VBUSCT_8244US

#define INA226_VBUSCT_8244US   (7 << INA226_VBUSCT_SHIFTS)

Definition at line 105 of file ina226.cpp.

◆ INA226_VBUSCT_MASK

#define INA226_VBUSCT_MASK   (7 << INA226_VBUSCT_SHIFTS)

Definition at line 97 of file ina226.cpp.

◆ INA226_VBUSCT_SHIFTS

#define INA226_VBUSCT_SHIFTS   (6)

Definition at line 96 of file ina226.cpp.

◆ INA226_VSCALE

#define INA226_VSCALE   0.00125f /* LSB of voltage is 1.25 mV */

Definition at line 142 of file ina226.cpp.

Referenced by INA226::collect().

◆ INA226_VSHCT_1100US

#define INA226_VSHCT_1100US   (4 << INA226_VSHCT_SHIFTS)

Definition at line 91 of file ina226.cpp.

◆ INA226_VSHCT_140US

#define INA226_VSHCT_140US   (0 << INA226_VSHCT_SHIFTS)

Definition at line 87 of file ina226.cpp.

◆ INA226_VSHCT_204US

#define INA226_VSHCT_204US   (1 << INA226_VSHCT_SHIFTS)

Definition at line 88 of file ina226.cpp.

◆ INA226_VSHCT_2116US

#define INA226_VSHCT_2116US   (5 << INA226_VSHCT_SHIFTS)

Definition at line 92 of file ina226.cpp.

◆ INA226_VSHCT_332US

#define INA226_VSHCT_332US   (2 << INA226_VSHCT_SHIFTS)

Definition at line 89 of file ina226.cpp.

◆ INA226_VSHCT_4156US

#define INA226_VSHCT_4156US   (6 << INA226_VSHCT_SHIFTS)

Definition at line 93 of file ina226.cpp.

◆ INA226_VSHCT_588US

#define INA226_VSHCT_588US   (3 << INA226_VSHCT_SHIFTS)

Definition at line 90 of file ina226.cpp.

◆ INA226_VSHCT_8244US

#define INA226_VSHCT_8244US   (7 << INA226_VSHCT_SHIFTS)

Definition at line 94 of file ina226.cpp.

◆ INA226_VSHCT_MASK

#define INA226_VSHCT_MASK   (7 << INA226_VSHCT_SHIFTS)

Definition at line 86 of file ina226.cpp.

◆ INA226_VSHCT_SHIFTS

#define INA226_VSHCT_SHIFTS   (3)

Definition at line 85 of file ina226.cpp.

◆ MAX_CURRENT

#define MAX_CURRENT   164.0f /* 164 Amps */

Definition at line 138 of file ina226.cpp.

Referenced by INA226::INA226().

◆ swap16

#define swap16 (   w)    __builtin_bswap16((w))

Definition at line 144 of file ina226.cpp.

Referenced by INA226::read().

Function Documentation

◆ ina2262_usage()

static void ina2262_usage ( )
static

Definition at line 613 of file ina226.cpp.

References INA226_BUS_DEFAULT.

Referenced by ina226_main().

Here is the caller graph for this function:

◆ ina226_main()

int ina226_main ( int  argc,
char *  argv[] 
)

Definition at line 624 of file ina226.cpp.

References ina2262_usage(), INA226_BUS_DEFAULT, ina226::info(), ina226::start(), ina226::start_bus(), and ina226::stop().

Here is the call graph for this function: