View Source Soleil.BQ27427 (soleil v0.1.1)
Driver for the Texas Instruments BQ27427 Battery Fuel Gauge.
This module provides a complete interface to the BQ27427 fuel gauge, including:
- Battery measurements (voltage, current, power)
- State of charge and capacity readings
- Temperature measurements
- Status flags and control operations
- Configuration mode management
Summary
Types
The battery chemistry type. According to the datasheet, the types correspond to the following battery properties
Functions
Get the chemical ID of the battery profile.
Configures the GPOUT pin as a State of Charge interrupt with the given threshold.
Get control status as a map.
Get the average current in amps. Positive values indicate charging, negative values indicate discharging.
Enter configuration mode. The device must be unsealed before this can be used.
Get all status flags as a map.
Get the full charge capacity in mAh.
Gets the design capacity of the battery in mAh. The device must be unsealed to use this function
Gets the design capacity of the battery in mWh. The device must be unsealed to use this function
Get the average power in watts. Positive values indicate charging, negative values indicate discharging.
Get the remaining capacity in mAh.
Perform a hard reset of the device. This will reset all registers to their default values.
Seal the device to prevent configuration changes.
Sets the bit to configure sign of the CC_Gain parameter. The default firmware for the BQ27427 for some reason shipped with the wrong value, and isn't documented in the datasheet. See the TI support issue for more information
Sets the chemistry ID of the battery profile. The device must be unsealed to use this function
Sets the design capacity of the battery in mAh. The device must be unsealed to use this function
Sets the design energy of the battery in mWh. The device must be unsealed to use this function
Perform a soft reset of the device. This maintains configuration but resets calculations. Used to exit configuration mode (has the side effect of re-sealing the device)
Get the state of charge as a percentage (0-100).
Get the internal chip temperature in degrees Celsius. Future versions of hardware may support reading temperature from the battery internal NTC sensor.
Unseal the device to allow configuration changes.
Gets the battery voltage in volts.
Types
@type chem_id() :: :chemistry_a | :chemistry_b | :chemistry_c
The battery chemistry type. According to the datasheet, the types correspond to the following battery properties:
:chemistry_a
: 4.35 V
:chemistry_b
: 4.2 V
:chemistry_c
: 4.4 V
Note: :chemistry_b
corresponds to LiPo batteries, which is the only battery
chemistry supported by the battery charger in the Soleil board. Future versions
may allow for use with other battery chemistries
@type i2c_bus() :: Circuits.I2C.bus()
Functions
Get the chemical ID of the battery profile.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.chemistry_id(ref)
{:ok, :chemistry_b} # using chemistry B for SOC algorithm
Configures the GPOUT pin as a State of Charge interrupt with the given threshold.
Parameters
- threshold: Percentage (0-100) at which to trigger the interrupt
- clear_threshold: Percentage (0-100) at which to clear the interrupt
Example
iex> Soleil.BQ27427.configure_soc1_interrupt(i2c, 20, 25) # Trigger at 20%, clear at 25%
Get control status as a map.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.control_status(ref)
{:ok, %{
sleep: false,
bca: false,
calmode: false,
cca: false,
chemchange: false,
initcomp: true,
ldmd: true,
qmax_up: false,
res_up: false,
rup_dis: true,
sealed: false,
shutdown_enabled: false,
vok: false,
wdreset: false
}}
Get the average current in amps. Positive values indicate charging, negative values indicate discharging.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.current(ref)
{:ok, -0.250} # Discharging at 250mA
Enter configuration mode. The device must be unsealed before this can be used.
Get all status flags as a map.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.flags(ref)
{:ok, %{
over_temp_flag: false,
under_temp_flag: false,
full_charge: false,
charging: true,
ocv_taken: true,
dod_correct: true,
itpor: false,
cfgupmode: false,
bat_det: true,
soc1: false,
socf: false,
discharging: true
}}
Get the full charge capacity in mAh.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.full_charge_capacity(ref)
{:ok, 1980} # battery has an estimated capacity of 1980mAh at full charge
Gets the design capacity of the battery in mAh. The device must be unsealed to use this function
Example
iex> Soleil.BQ27427.get_design_capacity(i2c)
{:ok, 1200} # 1200 mAh battery
Gets the design capacity of the battery in mWh. The device must be unsealed to use this function
Example
iex> Soleil.BQ27427.get_design_energy(i2c)
{:ok, 3000} # 3000 mWh battery
Get the average power in watts. Positive values indicate charging, negative values indicate discharging.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.current(ref)
{:ok, -0.850} # Discharging at 850mW
Get the remaining capacity in mAh.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.remaining_capacity(ref)
{:ok, 1128} # battery has an estimated 1128mAh remaining
Perform a hard reset of the device. This will reset all registers to their default values.
Seal the device to prevent configuration changes.
Sets the bit to configure sign of the CC_Gain parameter. The default firmware for the BQ27427 for some reason shipped with the wrong value, and isn't documented in the datasheet. See the TI support issue for more information:
Example
iex> Soleil.BQ27427.set_charge_direction(i2c)
:ok
Sets the chemistry ID of the battery profile. The device must be unsealed to use this function
Example
iex> {:ok, i2c} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.set_chemistry_id(i2c, :chemistry_a)
:ok
Sets the design capacity of the battery in mAh. The device must be unsealed to use this function
Example
iex> Soleil.BQ27427.set_design_capacity(i2c, 1200) # 1200mAh battery
Sets the design energy of the battery in mWh. The device must be unsealed to use this function
Example
iex> Soleil.BQ27427.set_design_energy(i2c, 4440) # 4440mWh battery
Perform a soft reset of the device. This maintains configuration but resets calculations. Used to exit configuration mode (has the side effect of re-sealing the device)
Get the state of charge as a percentage (0-100).
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.state_of_charge(ref)
{:ok, 37} # battery is at 37%
Get the internal chip temperature in degrees Celsius. Future versions of hardware may support reading temperature from the battery internal NTC sensor.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.temperature(ref)
{:ok, 25.7} # chip temperature is 25.7C
Unseal the device to allow configuration changes.
Gets the battery voltage in volts.
Examples
iex> {:ok, ref} = Circuits.I2C.open("i2c-1")
iex> Soleil.BQ27427.voltage(ref)
{:ok, 3.750}