Fuel Gauge Algorithm not functioning

We are using the Murata Type 2FR dev kit - https://www.murata.com/en-us/products/connectivitymodule/wi-fi-bluetooth/overview/lineup/type2fr 

Internally, this has NXP's RW612 processor which is Cortex M33 core. We are using NXP's proprietary MCUXpresso IDE for development, utilizing pure C and FreeRTOS. 

Here is a pseudocode - 

#include "nrf_fuel_gauge.h"


static const struct battery_model battery_model = {
#include "battery_model.inc"
};

struct nrf_fuel_gauge_init_parameters parameters = {
.model = &battery_model,
.opt_params = NULL,
.v0 = 3.315,
.i0 = -0.012895,
.t0 = 25.21,
};

segger_printf("Initializing Fuel Gauge....\n");
int ret = nrf_fuel_gauge_init(&parameters, NULL);
if (ret < 0) {
segger_printf("Error: Could not initialise fuel gauge\n");
return ret;
}
else if (ret == 0)
segger_printf("Fuel Gauge initialized!\n");

segger_printf("nRF Fuel Gauge version: %s\n", nrf_fuel_gauge_version);

float soc = nrf_fuel_gauge_process(3.27, -0.01256, 24.53, 1.0, NULL);
segger_printf("SoC: %.2f", (double)soc);

Note, this is the only code pertaining to fuel gauge algorithm. We do not yet have the I2C read/write driver code. We are using some dummy values to get started with. We are just trying to evaluate the process function and get a battery percentage. Then, we will add the actual fuel gauge code and charger code to get the accurate percentage value. Points to note - 

1. We found some .a binary files in the sdk folder here - C:\ncs\v3.0.2\nrfxlib\nrf_fuel_gauge\lib\cortex-m33\hard-float. We have linked both the .a binaries available here to our binaries along with some other dependencies. 

2. We are using segger_printf here which is basically just a printf command. 

3. When we run this code, we do see that the nrf_fuel_gauge_init() does return 0, meaning successful initialization. I'm able to retrieve the nrf_fuel_gauge_version as well. However, when we run the nrf_fuel_gauge_process() function with dummy values, it just stops working and crashes. Here is the output - 

00> Initializing Fuel Gauge....
00> Fuel Gauge initialized!
00> nRF Fuel Gauge version: 1.0.1

Are there any pre-requisites which are needed to successfully run the nrf_fuel_gauge_process() function? Does this function depend on charger initialization or fuel gauge structures? 

Parents Reply
  • Edwin,

    I see that the INIT() function returns 0 and prints "Fuel Gauge initialized!" on the console. Then, since I print the nrf_fuel_gauge_version, I get versionas v1.0.1

    Further, when I call the PROCESS() function, nothing gets printed on the console. 

    The following is the output from the console as sent in my initial message - 

    00> Initializing Fuel Gauge....
    00> Fuel Gauge initialized!
    00> nRF Fuel Gauge version: 1.0.1

Children
  • Hello,

    I discussed this with our PMIC Team, and they said that without having the physical HW that you are trying, our best suggestion is that you can have a look at the compiler flags that we used to build the Fuel Gauge static library .a files. Perhaps you can try enabling these in your project too, and see if it makes any difference:

    -O2
    -mthumb
    -mabi=aapcs
    -Wall
    -Werror
    -ffunction-sections
    -fdata-sections
    -fno-strict-aliasing
    -fno-builtin
    -fshort-enums
    -nostdlib
    -Wno-maybe-uninitialized
    -Wdouble-promotion
    -Wfloat-conversion

    Best regards,

    Edvin

  • Can you please ask the PMiC team this question?

    "Do we need to initialize the charger feature of the PMiC for the fuel gauge to work? Or is there any pre-requisite to use the PROCESS() function? The example available on Github initializes Charger first and then uses the PROCESS() function."

    I've added all these flags as you mentioned and I'm still getting the same results. I think something fundamental is missing from the project and hence the failed PROCESS() function. 

  • It only depends that nrf_fuel_gauge_init() has been called, but I understand that you have already done this. Unfortunately, we have not tested this on NXP devices. Have you been in contact with our sales team? If we are to test, it might help speed things up bringing in a feature request through that channel. If you don't have the contact information for our sales representative for your area, please send me a direct message here on DevZone, with a link to this ticket, and let me know where you are located, and I can hand it to you.

    Best regards,

    Edvin

Related