Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Driver Initialization

To initialize the max17261 driver you need to provide the the max17261_init function with a reference to a Max17261Storage struct and a populated Max17261Settings struct.

Calculating Max17261Settings Values

// found in fwxv/libraries/ms-drivers/inc/max17261_fuel_gauge.h

typedef struct {
  I2CPort i2c_port;
  I2CAddress i2c_address;

  uint16_t design_capacity;      // LSB = 5.0 (micro Volt Hours / R Sense)
  uint16_t empty_voltage;        // Only a 9-bit field, LSB = 78.125 (micro Volts)
  uint16_t charge_term_current;  // LSB = 1.5625 (micro Volts / R Sense)

  uint16_t r_sense_ohms;
} Max17261Settings;

The first two members of the struct will just be the I2C port and address corresponding to the device. The slave address for the Max17261 is 0x6C. Note that the last bit is used to indicate whether you are reading or writing so only the first 7 bits need to match 0x6C.

The following 3 members are battery characteristics used by the fuel gauge. They do not map directly to real world units but instead each field has a LSB (least significant bit) value which indicates the value in real world units of a single bit.

Taking design capacity as an example. First we need to determine the value of the LSB. If the sense resistor (a resistor used for calculating current) has a value of 2 ohms then our LSB would have a value of 5/2 = 2.5. The units for the LSB is micro volts hours / ohms which is just micro amp hours. If we have a battery that has a capacity of 1000000 micro amp hours, the value of the design_capacity field will be (1000000 / 2.5) = 400000.

  • No labels