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
  • I have already taken the approach you described: removing the Zephyr component and proceeding with pure C, without initializing the charger and utilizing dummy data. However, this method was not successful.

    If you don't mind, could you please attempt to run the project on NXP boards? I can provide you with my project files as they currently stand. Alternatively, we could arrange a brief meeting where I can demonstrate my project, allowing you to review it in more detail.

Children
  • Hello,

    Ishan Shah said:

    removing the Zephyr component and proceeding with pure C, without initializing the charger and utilizing dummy data. However, this method was not successful.

    Can you describe what you observe? Does it build without errors/warnings?

    What does the functions returns? 0, or some other value?

    Best regards,

    Edvin

  • It does compile without any errors or warnings. 

    The INIT() function does return 0. In my code - 
    else if (ret == 0)
    segger_printf("Fuel Gauge initialized!\n");

    This does get printed. Hence, confirming that the INIT() function does return 0. 

  • Edvin said:
    Ishan Shah said:

    removing the Zephyr component and proceeding with pure C, without initializing the charger and utilizing dummy data. However, this method was not successful.

    Can you describe what you observe?

    So what do you see?

  • 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

  • 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

Related