Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Low_Power_Long_Distance_IR_Vision_Robot MAX17055_EZconfig MAX17055_EZconfig_Sample Low_Power_Long_Distance_IR_Vision_Robot
Fork of max17055 by
MAX17055 Class Reference
MBED Library for the MAX17055
The MAX17055 is a low 7μA operating current fuel gauge which
implements Maxim ModelGauge™ m5 EZ algorithm.
More...
#include <max17055.h>
Data Structures | |
struct | platform_data |
Saved Platform Data for Fuel Gauge Model. More... | |
struct | saved_FG_params_t |
Saved Fuel Gauge Parameters. More... | |
Public Types | |
enum | Registers_e { STATUS_REG = 0x00, VALRTTH_REG = 0x01, TALRTTH_REG = 0x02, SALRTTH_REG = 0x03, ATRATE_REG = 0x04, REPCAP_REG = 0x05, REPSOC_REG = 0x06, TEMP_REG = 0x08, VCELL_REG = 0x09, CURRENT_REG = 0x0A, AVGCURRENT_REG = 0x0B, MIXSOC_REG = 0x0D, AVSOC_REG = 0x0E, MIXCAP_REG = 0x0F, FULLCAPREP_REG = 0x10, TTE_REG = 0X11, QRTABLE00_REG = 0x12, FULLSOCTHR_REG = 0x13, CYCLES_REG = 0x17, DESIGNCAP_REG = 0x18, AVGVCELL_REG = 0x19, MAXMINVOLT_REG = 0x1B, CONFIG_REG = 0x1D, ICHGTERM_REG = 0x1E, TTF_REG = 0x20, VERSION_REG = 0x21, QRTABLE10_REG = 0x22, FULLCAPNOM_REG = 0x23, LEARNCFG_REG = 0x28, RELAXCFG_REG = 0x2A, TGAIN_REG = 0x2C, TOFF_REG = 0x2D, QRTABLE20_REG = 0x32, RCOMP0_REG = 0x38, TEMPCO_REG = 0x39, VEMPTY_REG = 0x3A, FSTAT_REG = 0x3D, QRTABLE30_REG = 0x42, DQACC_REG = 0x45, DPACC_REG = 0x46, VFSOC0_REG = 0x48, QH0_REG = 0x4C, QH_REG = 0x4D, VFSOC0_QH0_LOCK_REG = 0x60, LOCK1_REG = 0x62, LOCK2_REG = 0x63, MODELDATA_START_REG = 0x80, IALRTTH_REG = 0xB4, CURVE_REG = 0xB9, HIBCFG_REG = 0xBA, CONFIG2_REG = 0xBB, MODELCFG_REG = 0xDB, ATTTE_REG = 0xDD, ATAVSOC_REG = 0xDE, ATAVCAP_REG = 0xDF, OCV_REG = 0xFB, VFSOC_REG = 0xFF } |
Register Addresses for the MAX17055. More... | |
Public Member Functions | |
MAX17055 (I2C &i2c) | |
max17055 Constructor | |
~MAX17055 () | |
Fuel Gauge Destructor. | |
int | poll_flag_clear (Registers_e reg_addr, int mask, int timeout) |
Poll Flag clear Function. | |
int | check_POR_func () |
Check POR function. | |
int | clear_POR_bit () |
clear POR bit function | |
int | write_and_verify_reg (Registers_e reg_addr, uint16_t reg_data) |
Write and Verify a MAX17055 register. | |
int | init (platform_data des_data) |
Initialization Function for MAX17055. | |
int | get_temperature () |
Get Temperature Function from the MAX17055 TEMP register. | |
uint16_t | forcedExitHiberMode () |
Forced Exit Hibernate Mode Function for MAX17055. | |
uint16_t | EZconfig (platform_data des_data) |
EZ Config function. | |
int | get_battCAP (platform_data des_data) |
Get reported Battery Capacity Function from MAX17055 Fuel Gauge. | |
int | get_SOC () |
Get reported State Of Charge(SOC) Function from MAX17055 Fuel Gauge. | |
int | get_atAvSOC () |
Get at rate Average State Of Charge(SOC) Function from MAX17055 Fuel Gauge. | |
float | get_TTE () |
Get the Time to Empty(TTE) Function form MAX17055 Fuel Gauge. | |
float | get_atTTE () |
Get the at Time to Empty(atTTE) value Function for MAX17055 Fuel Gauge. | |
int | get_mixSOC () |
Get mix State Of Charge(SOC) Function for MAX17055 Fuel Gauge. | |
float | get_TTF () |
Get the Time to Full(TTE) values Function for MAX17055 Fuel Gauge. | |
int | get_Vcell () |
Get voltage of the cell Function for MAX17055 Fuel Gauge. | |
int | get_avgVcell () |
Get average voltage of the cell Function for MAX17055 Fuel Gauge. | |
float | get_Current (platform_data des_data) |
Get current Function for MAX17055 Fuel Gauge. | |
float | get_AvgCurrent (platform_data des_data) |
Get average current Function for MAX17055 Fuel Gauge. | |
int | lsb_to_uvolts (uint16_t lsb) |
lsb_to_uvolts Conversion Function | |
float | raw_current_to_uamps (uint32_t curr, int rsense_value) |
raw_current_to_uamp Conversion Function | |
int | raw_cap_to_uAh (uint32_t raw_cap, int rsense_value) |
raw_cap_to_uAh Conversion Function | |
int | save_Params (saved_FG_params_t FG_params) |
Save Learned Parameters Function for battery Fuel Gauge model. | |
int | restore_Params (saved_FG_params_t FG_params) |
Restore Parameters Function for battery Fuel Gauge model. | |
int | avCurr_2_atRate () |
Function to Save Average Current to At Rate register. | |
int16_t | get_regInfo (Registers_e reg_addr) |
Get specified register info Function for MAX17055 Fuel Gauge. | |
Static Public Attributes | |
static const uint8_t | I2C_W_ADRS = 0x6C |
8-bit write address | |
static const uint8_t | I2C_R_ADRS = 0x6D |
8-bit read address | |
Protected Member Functions | |
int | writeReg (const Registers_e reg_addr, uint16_t reg_data) |
Writes to MAX17055 register. | |
int32_t | readReg (Registers_e reg_addr, uint16_t &value) |
Reads from MAX17055 register. |
Detailed Description
MBED Library for the MAX17055
The MAX17055 is a low 7μA operating current fuel gauge which
implements Maxim ModelGauge™ m5 EZ algorithm.
ModelGauge m5 EZ makes fuel gauge implementation easy by eliminating
battery characterization requirements and simplifying host
software interaction. The ModelGauge m5 EZ robust algorithm
provides tolerance against battery diversity for most lithium
batteries and applications. Communication is through a
I2C interface. The MAX17055 comes as part of the
MAX32620FTHR MBED enable development board.
Visit the product page for more information: MAX17055 Product Page
MAX17055 Data Sheet
MAX32620FTHR Product Page
MAX32620FTHR Data Sheet
Battery Recommendations based on sense Resistor Values (MAX32620FTHR comes with a 5 mOhm rsense resistor)
| BATTERY FULL CAPACITY(mAh) | Sense Resistor | Current Register Resolution(uA) | Current Register Range(A) | Capacity Resolution(mAh) |
|----------------------------|----------------|---------------------------------|---------------------------|--------------------------|
| 1600 - 24576 | 5 | 312.5 | +/- 10.24 | 1 |
| 8000 - 12288 | 10 | 156.25 | +/- 5.12 | 0.5 |
| 400-6144 | 20 | 78.125 | +/- 2.56 | 0.25 |
| 160-2458 | 50 | 31.25 | +/- 1.024 | 0.1 |
| 40-614 | 200 | 7.8125 | +/- 0.256 | 0.025 |
#include "mbed.h" #include "max17055.h" //LED indication DigitalOut rled(LED1); //I2C communications I2C i2cBus(P5_7, P6_0); //Fuel Gauge MAX17055 fuelGauge(i2cBus); MAX17055::platform_data design_param; MAX17055::saved_FG_params_t saved_param; //MAX77650 PMIC #define POWER_HOLD_ON 1 #define POWER_HOLD_OFF 0 DigitalOut pw_Hold(P2_2, POWER_HOLD_ON); //To enable battery operation from the PMIC //Battery Parameters Storage from the Fuel Gauge MAX17055 union max17055_u { struct battery { uint8_t avg_soc_FG; // in Battery Percent float tte_FG; // in seconds float ttf_FG; // in seconds int avg_vcell_FG; // in 78.125uV per bit float avg_curr_FG; // in uAmps float curr_FG; // in uAmps int rep_cap; // in mAh int rep_SOC; // in % } battery; } max17055_u; int main(void) { rled = true; //These are the calculated parameters for rsense 5mOhm found in the MAX32620FTHR and a 350mAh Li+ Cell. design_param.designcap = 0x015E; //Design Battery Capacity mAh this can change depending on the batteries implemented see battery data sheet for details. design_param.ichgterm = 0x0070; // Charge Termination Current for the Battery This is specified by the manufacturer. design_param.vempty = 0x9600; // Battery Empty Voltage This is specified by design, but manufacturer has a min Empty voltage specification. design_param.vcharge = 4200; // Battery Charge Voltage can be obtained from MAX77650 configuration design_param.rsense = 5; //5mOhms for MAX32620, keep in mind the MAX17055EVKIT has a 10mOhm resistor. This is a design specific value. Used for calculation results. //Saved Parameters //saved_param.cycles = 0; //This value is used for the save parameters function status = fuelGauge.init(design_param); // printf("Init FuelGauge Function Status= %X \r\n",status); if (status == 0) fuelGauge.save_Params(saved_param); while (1) { //This code is an example to illustrate the performance or the Fuel Gauge. This can change with the design requirements. Use this as a way to troubleshoot the FuelGauge. rled = !rled; max17055_u.battery.avg_vcell_FG = fuelGauge.get_avgVcell(); max17055_u.battery.avg_curr_FG = fuelGauge.get_AvgCurrent(design_param); max17055_u.battery.curr_FG = fuelGauge.get_Current(design_param); max17055_u.battery.rep_cap = fuelGauge.get_battCAP(design_param); max17055_u.battery.rep_SOC = fuelGauge.get_SOC(); //This code works with Arduino Serial Plotter to visualize data printf("%f " ,(max17055_u.battery.avg_vcell_FG/1000000.0)); //V printf("%f " ,max17055_u.battery.avg_curr_FG); //uA printf("%f " ,max17055_u.battery.curr_FG); //uA printf("%d " ,max17055_u.battery.rep_cap); //mAh printf("%d " ,max17055_u.battery.rep_SOC); //% printf("\n"); wait(1); } }
MAX17055 Class Class for MAX17055 Battery Fuel Gauge
- Generic API for Implementing the Battery Fuel Gauge
Definition at line 165 of file max17055.h.
Member Enumeration Documentation
enum Registers_e |
Register Addresses for the MAX17055.
Enumerated register addresses
- Enumerator:
Definition at line 179 of file max17055.h.
Constructor & Destructor Documentation
MAX17055 | ( | I2C & | i2c ) |
max17055 Constructor
max17055 Constructor with battery and i2c as parameters
Definition at line 65 of file max17055.cpp.
~MAX17055 | ( | ) |
Fuel Gauge Destructor.
Definition at line 74 of file max17055.cpp.
Member Function Documentation
int avCurr_2_atRate | ( | ) |
Function to Save Average Current to At Rate register.
- Details
- For User friendliness display of atTTE, atAvSOC, atAvCAP write the average current to At Rate registers every 10sec when the battery is in use. NOTE: do not use this function when the Battery is charging.
- Return values:
-
0 for success non-0 negative for errors
Definition at line 904 of file max17055.cpp.
int check_POR_func | ( | ) |
Check POR function.
- Details
- This function check is there was a power on reset event for the MAX17055
- Return values:
-
0 on success (POR detected) non-0 for errors (POR not detected)
Definition at line 260 of file max17055.cpp.
int clear_POR_bit | ( | ) |
clear POR bit function
- Details
- This function clear the indicating bit for POR - MAX17055
- Return values:
-
0 for Success non-0 for errors
Definition at line 280 of file max17055.cpp.
uint16_t EZconfig | ( | platform_data | des_data ) |
EZ Config function.
- Details
- This function implements the steps for the EZ config m5 FuelGauge
- Parameters:
-
[in] des_data - Plataform_data struct with information about the design.
- Return values:
-
0 on success non-zero for errors
STEP 2.1.1 EZ config values suggested by manufacturer.
STEP 2.1.2 Store the EZ Config values into the appropriate registers.
Definition at line 402 of file max17055.cpp.
uint16_t forcedExitHiberMode | ( | ) |
Forced Exit Hibernate Mode Function for MAX17055.
- Details
- This function executes a force exit from hibernate mode.
- Return values:
-
HibCFG original value before forced Exit Hibernate mode *
Definition at line 374 of file max17055.cpp.
int get_atAvSOC | ( | ) |
Get at rate Average State Of Charge(SOC) Function from MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the atAvSOC register of the MAX17055. The AvSOC registers hold the calculated available capacity and percentage of the battery based on all inputs from the ModelGauge m5 algorithm including empty compensation. These registers provide unfiltered results. Jumps in the reported values can be caused by abrupt changes in load current or temperature.
- Return values:
-
atAvSOC_data - Average SOC data from the atAVSOC register in % value. non-0 negative values check for errors
Definition at line 496 of file max17055.cpp.
float get_atTTE | ( | ) |
Get the at Time to Empty(atTTE) value Function for MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the internal register of the MAX17055
- Return values:
-
atTTE_data - Time to Empty data from the atTTE register in seconds. non-0 negative values check for errors
Definition at line 573 of file max17055.cpp.
float get_AvgCurrent | ( | platform_data | des_data ) |
Get average current Function for MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the aveCURRENT register of the MAX17055 to read the average current readings.
- Parameters:
-
[in] des_data - Plataform_data struct with information about the design.
- Return values:
-
aveCurr_data - current data from the AVGCURRENT register in uAmps. non-0 negative values check for errors.
Definition at line 703 of file max17055.cpp.
int get_avgVcell | ( | ) |
Get average voltage of the cell Function for MAX17055 Fuel Gauge.
Gets Average voltage of the cell Function for MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the AvgVCell Register of the MAX17055 to read the measured voltage from the cell.
- Return values:
-
avgVcell_data - avgvcell data from the AVGVCELL_REG register in uVolts. non-0 negative values check for errors
Definition at line 651 of file max17055.cpp.
int get_battCAP | ( | platform_data | des_data ) |
Get reported Battery Capacity Function from MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the RepCAP register of the MAX17055. RepCAP is the reported Battery Capacity in mAh of the battery based on the calculation by the Fuel Gauge algorithm.
- Return values:
-
repcap_data - Reported SOC data from the RepSOC register in % value. non-0 negative values check for errors
Definition at line 443 of file max17055.cpp.
float get_Current | ( | platform_data | des_data ) |
Get current Function for MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the CURRENT register of the MAX17055 to read the current readings.
- Parameters:
-
[in] des_data - Plataform_data struct with information about the design.
- Return values:
-
curr_data - current data from the CURRENT register in uAmps. non-0 negative values check for errors.
Definition at line 676 of file max17055.cpp.
int get_mixSOC | ( | ) |
Get mix State Of Charge(SOC) Function for MAX17055 Fuel Gauge.
- Details
- This function sends a request to access mixSOC register of the MAX17055. The MixSOC registers holds the calculated remaining capacity and percentage of the cell before any empty compensation adjustments are performed.
- Return values:
-
mixSOC_data - Mixed SOC register values from the mixSOC register in % value. non-0 for errors
Definition at line 521 of file max17055.cpp.
int16_t get_regInfo | ( | Registers_e | reg_addr ) |
Get specified register info Function for MAX17055 Fuel Gauge.
Reads an specified register from the MAX17055 register.
- Parameters:
-
[in] reg_addr The register address value The value
- Return values:
-
reg_data register data statusRead non-0 for errors
Definition at line 144 of file max17055.cpp.
int get_SOC | ( | ) |
Get reported State Of Charge(SOC) Function from MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the RepSOC register of the MAX17055. RepSOC is the reported state-of-charge percentage output of the fuel gauge.
- Return values:
-
soc_data - Reported SOC data from the RepSOC register in % value. non-0 negative values check for errors
Definition at line 469 of file max17055.cpp.
int get_temperature | ( | ) |
Get Temperature Function from the MAX17055 TEMP register.
- Details
- This function sends a request to access the TEMP register of the MAX17055, which reflects the temperature measured for the fuel gauge. The temperature values will reflect the Config Register (0x1D) selections for Tsel bit (D15). For this library the setting are for die temperature. The MAX32620FTHR thermistor bias pin is not connected. The biasing of the thermistor is done by the MAX77650. See MAX77650 library for how to enable the thermistor biasing.
- Return values:
-
temp - Temperature value from TEMP register in C non-0 negative values check for errors
Definition at line 346 of file max17055.cpp.
float get_TTE | ( | ) |
Get the Time to Empty(TTE) Function form MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the TTE register of the MAX17055 The TTE register holds the estimated time to empty for the application under present temperature and load conditions. The TTE value is determined by relating AvCap with AvgCurrent. The corresponding AvgCurrent filtering gives a delay in TTE, but provides more stable results.
- Return values:
-
tte_data - Time to Empty data from the TTE register in seconds. non-0 negative values check for errors
Definition at line 548 of file max17055.cpp.
float get_TTF | ( | ) |
Get the Time to Full(TTE) values Function for MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the internal register of the MAX17055 The TTF register holds the estimated time to full for the application under present conditions. The TTF value is determined by learning the constant current and constant voltage portions of the charge cycle based on experience of prior charge cycles. Time to full is then estimate by comparing present charge current to the charge termination current. Operation of the TTF register assumes all charge profiles are consistent in the application.
- Return values:
-
ttf_data - Time to Full data from the TTF register in seconds. non-0 negative values check for errors
Definition at line 603 of file max17055.cpp.
int get_Vcell | ( | ) |
Get voltage of the cell Function for MAX17055 Fuel Gauge.
- Details
- This function sends a request to access the VCell Register of the MAX17055 to read the measured voltage from the cell.
- Return values:
-
vcell_data - vcell data from the VCELL_REG register in uVolts. non-0 negative values check for errors
Definition at line 628 of file max17055.cpp.
int init | ( | platform_data | des_data ) |
Initialization Function for MAX17055.
- Details
- This function initializes the MAX17055 for the implementation of the EZconfig model.
The library needs to be customized for the implementation of customize model.
- Return values:
-
0 on success non-0 for errors
STEP 0. Check for POR (Skip load model if POR bit is cleared)
STEP 1. Check if FStat.DNR == 0 (Do not continue until FSTAT.DNR == 0)
STEP 1.2. Force exit from hibernate
STEP 2. Initialize configuration STEP 2.1. Load EZ Config
STEP 2.2. Poll ModelCFG.ModelRefresh bit for clear
STEP3. Restore original HibCfg
Definition at line 200 of file max17055.cpp.
int lsb_to_uvolts | ( | uint16_t | lsb ) |
lsb_to_uvolts Conversion Function
- Details
- This function takes the lsb value of the register and convert it to uvolts
- Parameters:
-
[in] lsb - value of register lsb
- Return values:
-
conv_2_uvolts - value converted lsb to uvolts
Definition at line 728 of file max17055.cpp.
int poll_flag_clear | ( | Registers_e | reg_addr, |
int | mask, | ||
int | timeout | ||
) |
Poll Flag clear Function.
- Details
- This function clears status flags for the MAX17055
- Parameters:
-
[in] reg_addr - register address [in] mask - register address [in] timeout - register data
- Return values:
-
0 on success non-0 negative for errors
Definition at line 308 of file max17055.cpp.
int raw_cap_to_uAh | ( | uint32_t | raw_cap, |
int | rsense_value | ||
) |
raw_cap_to_uAh Conversion Function
- Details
- This function takes the raw battery capacity value of the register and converts it to uAh
- Parameters:
-
[in] raw_cap - raw capacity value of register
- Return values:
-
res - converted raw capacity to uAh
Definition at line 767 of file max17055.cpp.
float raw_current_to_uamps | ( | uint32_t | curr, |
int | rsense_value | ||
) |
raw_current_to_uamp Conversion Function
- Details
- This function takes the raw current value of the register and converts it to uamps
- Parameters:
-
[in] curr - raw current value of register
- Return values:
-
res - converted raw current to uamps (Signed 2's complement)
Definition at line 744 of file max17055.cpp.
int32_t readReg | ( | Registers_e | reg_addr, |
uint16_t & | value | ||
) | [protected] |
Reads from MAX17055 register.
- Parameters:
-
[in] reg_addr The register address value The value
- Return values:
-
0 on success non-0 for errors
Definition at line 115 of file max17055.cpp.
int restore_Params | ( | saved_FG_params_t | FG_params ) |
Restore Parameters Function for battery Fuel Gauge model.
- Details
- If power is lost, then the capacity information can be easily restored with this function.
- Parameters:
-
[in] FG_params Struct for Fuel Gauge Parameters
- Return values:
-
0 for success non-0 negative for errors
STEP 1. Restoring capacity parameters
STEP 2. Restore FullCap
STEP 3. Write DQACC to 200% of Capacity and DPACC to 200%
STEP 4. Restore Cycles register
Definition at line 851 of file max17055.cpp.
int save_Params | ( | saved_FG_params_t | FG_params ) |
Save Learned Parameters Function for battery Fuel Gauge model.
- Details
- It is recommended to save the learned capacity parameters every time bit 2 of the Cycles register toggles (so that it is saved every 64% change in the battery) so that if power is lost the values can easily be restored. Make sure the data is saved on a non-volatile memory. Call this function after first initialization for reference in future function calls. Max number of cycles is 655.35 cycles with a LSB of 1% for the cycles register.
- Parameters:
-
[in] FG_params Fuel Gauge Parameters based on design details.
- Return values:
-
0 for success non-0 negative for errors
STEP 1. Checks if the cycle register bit 2 has changed.
STEP 2. Save the capacity parameters for the specific battery.
Definition at line 789 of file max17055.cpp.
int write_and_verify_reg | ( | Registers_e | reg_addr, |
uint16_t | reg_data2write | ||
) |
Write and Verify a MAX17055 register.
- Details
- This function writes and verifies if the writing process was successful
- Parameters:
-
[in] reg_addr - register address [out] reg_data - the variable that contains the data to write to the register address
- Return values:
-
0 on success non-0 for errors
Definition at line 169 of file max17055.cpp.
int writeReg | ( | const Registers_e | reg_addr, |
uint16_t | reg_data | ||
) | [protected] |
Writes to MAX17055 register.
Writes a register.
- Parameters:
-
[in] reg_addr The register address [in] reg_data The register data
- Return values:
-
0 on success non-0 for errors
Definition at line 88 of file max17055.cpp.
Field Documentation
const uint8_t I2C_R_ADRS = 0x6D [static] |
8-bit read address
Definition at line 173 of file max17055.h.
const uint8_t I2C_W_ADRS = 0x6C [static] |
8-bit write address
Definition at line 171 of file max17055.h.
Generated on Sat Jul 16 2022 18:51:08 by
