Skip to main content

Module ina226

Module ina226 

Source
Expand description

Texas Instruments INA226 high-side or low-side current, voltage, and power monitor.

The INA226 measures the voltage across a shunt resistor and the bus voltage on common-mode voltages from 0 V to 36 V and, once its calibration register is programmed, computes current and power on the chip. It adds programmable conversion times and averaging, and an alert pin driven by a single limit register. This module builds the calibration and configuration values and decodes each register into a physical quantity, following the datasheet’s equations and its worked example, so a battery-balancer or rack-power node reads amps and watts directly.

Shunt voltages are returned in nanovolts, bus voltages in microvolts, and current and power in microamps and microwatts, so the 2.5 µV and 1.25 mV register LSBs convert exactly without floating point. f32 conveniences sit beside them.

Modules§

register
The INA226 register pointer addresses.

Structs§

Configuration
The configuration register (0x00), decoded into its fields.
DieId
The die ID register (0xFF), split into its device and revision fields.
MaskEnable
The Mask/Enable register (0x06): which alert function drives the pin, how the pin behaves, and the status flags the chip reports back.

Enums§

AddressPin
What an address pin is tied to; each of A1 and A0 takes one of four levels.
AlertFunction
The five limit comparisons the alert pin can be assigned to.
Averaging
The number of samples the ADC averages before updating the result registers.
ConversionTime
The ADC conversion time for one shunt or bus voltage measurement.
Mode
The operating mode: which inputs are converted, and whether once or continuously.

Constants§

BASE_ADDRESS
The base I2C address, selected when both address pins are tied to ground.
BUS_LSB_MICROVOLTS
The bus voltage register LSB, 1.25 mV, in microvolts.
CONFIG_RESET
The power-on value of the configuration register (0x4127): averaging off, 1.1 ms conversion time for both bus and shunt, and continuous shunt-and-bus conversion.
DEVICE_ID
The 12-bit device ID carried in bits 15:4 of the die ID register.
MANUFACTURER_ID
The value the manufacturer ID register always reads (0x5449, “TI”).
POWER_LSB_RATIO
The fixed ratio between the power LSB and the programmed current LSB.
SHUNT_LSB_NANOVOLTS
The shunt voltage register LSB, 2.5 µV, in nanovolts.

Functions§

address
Returns the 7-bit I2C address selected by the A1 and A0 pins.
bus_microvolts
Decodes the bus voltage register to microvolts.
bus_register
Builds the bus voltage register a monitor reports for a bus voltage.
bus_volts_f32
Decodes the bus voltage register to volts as a float.
calibration
Computes the calibration register value for a chosen current resolution and shunt.
current_amps_f32
Decodes the current register to amps as a float.
current_microamps
Decodes the current register to microamps for a given current LSB.
current_register
Builds the current register a monitor reports for a current.
current_register_from_shunt
Reproduces the chip’s current calculation from a shunt reading and calibration.
identify
Checks that the identification registers belong to an INA226.
minimum_current_lsb_microamps
Returns the smallest current LSB, in microamps, that still spans a full-scale current.
power_microwatts
Decodes the power register to microwatts for a given current LSB.
power_register
Builds the power register a monitor reports for a power.
power_register_from_current
Reproduces the chip’s power calculation from the current and bus registers.
power_watts_f32
Decodes the power register to watts as a float.
shunt_millivolts_f32
Decodes the shunt voltage register to millivolts as a float.
shunt_nanovolts
Decodes the shunt voltage register to nanovolts.
shunt_register
Builds the shunt voltage register a monitor reports for a shunt voltage.