INA220 current/power monitor

Device driver for Texas Instruments INA220 High or Low Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface. More...

Detailed Description

Device driver for Texas Instruments INA220 High or Low Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface.

Files

file  ina220-regs.h
 Register definitions for Texas Instruments INA220 High or Low Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface.
 
file  ina220.h
 Device driver interface for Texas Instruments INA220 High or Low Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface.
 

Data Structures

struct  ina220_t
 Device descriptor for INA220 sensors. More...
 

Macros

#define INA220_RESET_BIT   (0x8000)
 INA220 reset command bit (in configuration register)
 
#define INA220_BUS_VOLTAGE_SHIFT   (3)
 Location of the bus voltage in the INA220 bus voltage register.
 

Typedefs

typedef enum ina220_mode ina220_mode_t
 INA220 possible mode settings.
 
typedef enum ina220_range ina220_range_t
 Shunt voltage measurement range (PGA settings)
 
typedef enum ina220_brng ina220_brng_t
 Bus voltage measurement range.
 
typedef enum ina220_sadc ina220_sadc_t
 Shunt ADC settings. More...
 
typedef enum ina220_badc ina220_badc_t
 Bus ADC settings. More...
 

Enumerations

enum  ina220_mode {
  INA220_MODE_POWERDOWN = 0x0000, INA220_MODE_TRIGGER_SHUNT_ONLY = 0x0001, INA220_MODE_TRIGGER_BUS_ONLY = 0x0002, INA220_MODE_TRIGGER_SHUNT_BUS = 0x0003,
  INA220_MODE_ADC_DISABLE = 0x0004, INA220_MODE_CONTINUOUS_SHUNT_ONLY = 0x0005, INA220_MODE_CONTINUOUS_BUS_ONLY = 0x0006, INA220_MODE_CONTINUOUS_SHUNT_BUS = 0x0007
}
 INA220 possible mode settings. More...
 
enum  ina220_range { INA220_RANGE_40MV = 0x0000, INA220_RANGE_80MV = 0x0800, INA220_RANGE_160MV = 0x1000, INA220_RANGE_320MV = 0x1800 }
 Shunt voltage measurement range (PGA settings) More...
 
enum  ina220_brng { INA220_BRNG_16V_FSR = 0x0000, INA220_BRNG_32V_FSR = 0x0200 }
 Bus voltage measurement range. More...
 
enum  ina220_sadc {
  INA220_SADC_9BIT = 0x0000, INA220_SADC_10BIT = 0x0008, INA220_SADC_11BIT = 0x0010, INA220_SADC_12BIT = 0x0018,
  INA220_SADC_AVG_1_SAMPLE = 0x0040, INA220_SADC_AVG_2_SAMPLES = 0x0048, INA220_SADC_AVG_4_SAMPLES = 0x0050, INA220_SADC_AVG_8_SAMPLES = 0x0058,
  INA220_SADC_AVG_16_SAMPLES = 0x0060, INA220_SADC_AVG_32_SAMPLES = 0x0068, INA220_SADC_AVG_64_SAMPLES = 0x0070, INA220_SADC_AVG_128_SAMPLES = 0x0078
}
 Shunt ADC settings. More...
 
enum  ina220_badc {
  INA220_BADC_9BIT = 0x0000, INA220_BADC_10BIT = 0x0080, INA220_BADC_11BIT = 0x0100, INA220_BADC_12BIT = 0x0180,
  INA220_BADC_AVG_1_SAMPLE = 0x0400, INA220_BADC_AVG_2_SAMPLES = 0x0480, INA220_BADC_AVG_4_SAMPLES = 0x0500, INA220_BADC_AVG_8_SAMPLES = 0x0580,
  INA220_BADC_AVG_16_SAMPLES = 0x0600, INA220_BADC_AVG_32_SAMPLES = 0x0680, INA220_BADC_AVG_64_SAMPLES = 0x0700, INA220_BADC_AVG_128_SAMPLES = 0x0780
}
 Bus ADC settings. More...
 

Functions

int ina220_init (ina220_t *dev, i2c_t i2c, uint8_t address)
 Initialize a current sensor. More...
 
int ina220_set_calibration (const ina220_t *dev, uint16_t calibration)
 Write to calibration register. More...
 
int ina220_set_config (const ina220_t *dev, uint16_t config)
 Write to configuration register. More...
 
int ina220_read_shunt (const ina220_t *dev, int16_t *voltage)
 Read shunt voltage. More...
 
int ina220_read_bus (const ina220_t *dev, int16_t *voltage)
 Read bus voltage register. More...
 
int ina220_read_current (const ina220_t *dev, int16_t *current)
 Read shunt current. More...
 
int ina220_read_power (const ina220_t *dev, int16_t *power)
 Read power consumption. More...
 

Typedef Documentation

◆ ina220_badc_t

typedef enum ina220_badc ina220_badc_t

Bus ADC settings.

See also
Table 5 in INA220 data sheet

◆ ina220_sadc_t

typedef enum ina220_sadc ina220_sadc_t

Shunt ADC settings.

See also
Table 5 in INA220 data sheet

Enumeration Type Documentation

◆ ina220_badc

Bus ADC settings.

See also
Table 5 in INA220 data sheet
Enumerator
INA220_BADC_9BIT 

9 bit resolution, 84 us conversion time

INA220_BADC_10BIT 

10 bit resolution, 148 us conversion time

INA220_BADC_11BIT 

11 bit resolution, 276 us conversion time

INA220_BADC_12BIT 

12 bit resolution, 532 us conversion time, default

INA220_BADC_AVG_1_SAMPLE 

12 bit resolution, 532 us conversion time, same as INA220_BADC_12BIT

INA220_BADC_AVG_2_SAMPLES 

2 sample average, 1.06 ms conversion time

INA220_BADC_AVG_4_SAMPLES 

4 sample average, 2.13 ms conversion time

INA220_BADC_AVG_8_SAMPLES 

8 sample average, 4.26 ms conversion time

INA220_BADC_AVG_16_SAMPLES 

16 sample average, 8.51 ms conversion time

INA220_BADC_AVG_32_SAMPLES 

32 sample average, 17.02 ms conversion time

INA220_BADC_AVG_64_SAMPLES 

64 sample average, 34.05 ms conversion time

INA220_BADC_AVG_128_SAMPLES 

128 sample average, 68.10 ms conversion time

Definition at line 112 of file ina220.h.

◆ ina220_brng

Bus voltage measurement range.

Enumerator
INA220_BRNG_16V_FSR 

16 V bus voltage full scale range

INA220_BRNG_32V_FSR 

32 V bus voltage full scale range, default.

Definition at line 70 of file ina220.h.

◆ ina220_mode

INA220 possible mode settings.

Enumerator
INA220_MODE_POWERDOWN 

Power down.

INA220_MODE_TRIGGER_SHUNT_ONLY 

Shunt Voltage, Triggered.

INA220_MODE_TRIGGER_BUS_ONLY 

Bus Voltage, Triggered.

INA220_MODE_TRIGGER_SHUNT_BUS 

Shunt and Bus, Triggered.

INA220_MODE_ADC_DISABLE 

ADC Off (disabled)

INA220_MODE_CONTINUOUS_SHUNT_ONLY 

Shunt Voltage, Continuous.

INA220_MODE_CONTINUOUS_BUS_ONLY 

Bus Voltage, Continuous.

INA220_MODE_CONTINUOUS_SHUNT_BUS 

Shunt and Bus, Continuous, default.

Definition at line 46 of file ina220.h.

◆ ina220_range

Shunt voltage measurement range (PGA settings)

Enumerator
INA220_RANGE_40MV 

+/- 40 mV range

INA220_RANGE_80MV 

+/- 80 mV range

INA220_RANGE_160MV 

+/- 160 mV range

INA220_RANGE_320MV 

+/- 320 mV range, default

Definition at line 60 of file ina220.h.

◆ ina220_sadc

Shunt ADC settings.

See also
Table 5 in INA220 data sheet
Enumerator
INA220_SADC_9BIT 

9 bit resolution, 84 us conversion time

INA220_SADC_10BIT 

10 bit resolution, 148 us conversion time

INA220_SADC_11BIT 

11 bit resolution, 276 us conversion time

INA220_SADC_12BIT 

12 bit resolution, 532 us conversion time, default

INA220_SADC_AVG_1_SAMPLE 

12 bit resolution, 532 us conversion time, same as INA220_SADC_12BIT

INA220_SADC_AVG_2_SAMPLES 

2 sample average, 1.06 ms conversion time

INA220_SADC_AVG_4_SAMPLES 

4 sample average, 2.13 ms conversion time

INA220_SADC_AVG_8_SAMPLES 

8 sample average, 4.26 ms conversion time

INA220_SADC_AVG_16_SAMPLES 

16 sample average, 8.51 ms conversion time

INA220_SADC_AVG_32_SAMPLES 

32 sample average, 17.02 ms conversion time

INA220_SADC_AVG_64_SAMPLES 

64 sample average, 34.05 ms conversion time

INA220_SADC_AVG_128_SAMPLES 

128 sample average, 68.10 ms conversion time

Definition at line 80 of file ina220.h.

Function Documentation

◆ ina220_init()

int ina220_init ( ina220_t dev,
i2c_t  i2c,
uint8_t  address 
)

Initialize a current sensor.

Parameters
[out]devdevice descriptor of sensor to initialize
[in]i2cI2C bus the sensor is connected to
[in]addressI2C slave address of the sensor
Returns
0 on success
<0 on error

◆ ina220_read_bus()

int ina220_read_bus ( const ina220_t dev,
int16_t *  voltage 
)

Read bus voltage register.

The bus voltage can be found in the most significant bits of the bus voltage register, the lower three bits are flags/reserved.

See the device data sheet for details.

Parameters
[in]devdevice descriptor of sensor
[out]voltagemeasured bus voltage
Returns
0 on success
<0 on error

◆ ina220_read_current()

int ina220_read_current ( const ina220_t dev,
int16_t *  current 
)

Read shunt current.

Parameters
[in]devdevice descriptor of sensor
[out]currentmeasured current through shunt resistor
Returns
0 on success
<0 on error

◆ ina220_read_power()

int ina220_read_power ( const ina220_t dev,
int16_t *  power 
)

Read power consumption.

Parameters
[in]devdevice descriptor of sensor
[out]powermeasured power consumption
Returns
0 on success
<0 on error

◆ ina220_read_shunt()

int ina220_read_shunt ( const ina220_t dev,
int16_t *  voltage 
)

Read shunt voltage.

Parameters
[in]devdevice descriptor of sensor
[out]voltagemeasured voltage across shunt resistor
Returns
0 on success
<0 on error

◆ ina220_set_calibration()

int ina220_set_calibration ( const ina220_t dev,
uint16_t  calibration 
)

Write to calibration register.

Parameters
[in]devdevice descriptor of sensor to configure
[in]calibrationcalibration register settings, see data sheet
Returns
0 on success
<0 on error

◆ ina220_set_config()

int ina220_set_config ( const ina220_t dev,
uint16_t  config 
)

Write to configuration register.

Parameters
[in]devdevice descriptor of sensor to configure
[in]configconfiguration register settings, see data sheet
Returns
0 on success
<0 on error