nPM1300 fuel gauge SoC

Hi

Setup: nPM1300, nRF54L15-based board, SDK 2.9.2

I am trying to figure out how to use the nPM1300.


So far, I have not succeeded. Quite frequently, after power cycling my device, the SoC read from the fuel gauge, after rebooting, is quite different (e.g. 20% difference) from the SoC before power down.


My code calls nrf_fuel_gauge_process() every 100 ms.

ret = read_sensors(charger, &voltage, &current, &temp, &chg_status);
:
soc = nrf_fuel_gauge_process(voltage, current, temp, delta, charging_active, NULL);


Some of the things I have tried…


ONE


Simple usage.

Provide no further information to the fuel gauge.

On power up, initialise the fuel gauge straight away.

ret = read_sensors(charger, &p.v0, &p.i0, &p.t0, &chg_status);
:
sensor_channel_get(charger, SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT, &v);
:
nrf_fuel_gauge_init(&p, NULL);


TWO


Same as ONE, except wait 30 seconds before initialising


THREE


When the SoC reaches 100%, re-initialise the fuel gauge:


int ret = read_sensors(charger, &p.v0, &p.i0, &p.t0, &chg_status);
:
nrf_fuel_gauge_init(&p, NULL);

FOUR


After a few seconds after powering up, read the V,I,T


ret = read_sensors(charger, &p.v0, &p.i0, &p.t0, &chg_status);


then initialise the fuel gauge using these values


FIVE

Save V,I,T values to Flash on a regular basis, and on power-up, restore these  saved values and use them to initialise the fuel gauge.

SIX


Maintain an array of saved V,I,T values (e.g. size 120), and save the average of this circular array to Flash every so often (e.g. every 2 minutes for test purposes).
On power-up, restore these saved averages, and use them to initialise the fuel gauge.

FURTHER INFORMATION

In all cases, there is often quite a large drop or rise in the SoC after power cycling the device.

Here is a sample of the output while charging / discharging (from two separate logs).
One thing of note: the voltage and current fluctuate quite a bit during discharge.

Charging:

[00:13:31.976,257] : delta: 0.100000, V: 4.233, I: -0.019, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2122, Chging 1, Conn 1, ChgSt 17
[00:13:32.076,293] : delta: 0.100000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2095, Chging 1, Conn 1, ChgSt 17
[00:13:32.176,239] : delta: 0.100000, V: 4.233, I: -0.018, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2107, Chging 1, Conn 1, ChgSt 17
[00:13:32.276,275] : delta: 0.100000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2092, Chging 1, Conn 1, ChgSt 17
[00:13:32.376,312] : delta: 0.100000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2091, Chging 1, Conn 1, ChgSt 17
[00:13:32.476,379] : delta: 0.101000, V: 4.233, I: -0.019, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2115, Chging 1, Conn 1, ChgSt 17
[00:13:32.576,293] : delta: 0.099000, V: 4.233, I: -0.018, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2101, Chging 1, Conn 1, ChgSt 17
[00:13:32.676,300] : delta: 0.100000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2087, Chging 1, Conn 1, ChgSt 17
[00:13:32.776,367] : delta: 0.101000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2085, Chging 1, Conn 1, ChgSt 17
[00:13:32.876,312] : delta: 0.099000, V: 4.233, I: -0.019, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2110, Chging 1, Conn 1, ChgSt 17
[00:13:32.976,348] : delta: 0.101000, V: 4.233, I: -0.018, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2096, Chging 1, Conn 1, ChgSt 17
[00:13:33.076,385] : delta: 0.100000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2081, Chging 1, Conn 1, ChgSt 17
[00:13:33.176,330] : delta: 0.099000, V: 4.228, I: -0.018, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2093, Chging 1, Conn 1, ChgSt 17
[00:13:33.276,336] : delta: 0.100000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2079, Chging 1, Conn 1, ChgSt 17
[00:13:33.376,403] : delta: 0.101000, V: 4.233, I: -0.019, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2103, Chging 1, Conn 1, ChgSt 17
[00:13:33.476,348] : delta: 0.100000, V: 4.228, I: -0.018, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2090, Chging 1, Conn 1, ChgSt 17
[00:13:33.576,354] : delta: 0.100000, V: 4.233, I: -0.018, T: 25.82, SoC: 98.59, TTE: nan, TTF: 2088, Chging 1, Conn 1, ChgSt 17
[00:13:33.676,452] : delta: 0.100000, V: 4.233, I: -0.019, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2100, Chging 1, Conn 1, ChgSt 17
[00:13:33.776,367] : delta: 0.100000, V: 4.228, I: -0.018, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2086, Chging 1, Conn 1, ChgSt 17
[00:13:33.876,342] : delta: 0.100000, V: 4.233, I: -0.016, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2057, Chging 1, Conn 1, ChgSt 17
[00:13:33.976,470] : delta: 0.100000, V: 4.233, I: -0.019, T: 25.93, SoC: 98.59, TTE: nan, TTF: 2096, Chging 1, Conn 1, ChgSt 17
[00:13:34.076,354] : delta: 0.100000, V: 4.228, I: -0.018, T: 25.93, SoC: 98.60, TTE: nan, TTF: 2082, Chging 1, Conn 1, ChgSt 17
[00:13:34.176,361] : delta: 0.100000, V: 4.233, I: -0.018, T: 25.93, SoC: 98.60, TTE: nan, TTF: 2081, Chging 1, Conn 1, ChgSt 17
[00:13:34.276,428] : delta: 0.100000, V: 4.233, I: -0.018, T: 25.93, SoC: 98.60, TTE: nan, TTF: 2079, Chging 1, Conn 1, ChgSt 17
[00:13:34.376,373] : delta: 0.100000, V: 4.233, I: -0.017, T: 25.93, SoC: 98.60, TTE: nan, TTF: 2065, Chging 1, Conn 1, ChgSt 17
[00:13:34.476,379] : delta: 0.100000, V: 4.233, I: -0.018, T: 25.93, SoC: 98.60, TTE: nan, TTF: 2077, Chging 1, Conn 1, ChgSt 17

Discharging:

[00:14:18.076,660] : delta: 0.100000, V: 3.994, I: 0.011, T: 26.03, SoC: 96.79, TTE: 15040, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.176,727] : delta: 0.100000, V: 3.984, I: 0.023, T: 26.03, SoC: 96.79, TTE: 15039, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.276,794] : delta: 0.100000, V: 3.994, I: 0.023, T: 26.03, SoC: 96.79, TTE: 15039, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.376,678] : delta: 0.100000, V: 3.989, I: 0.067, T: 26.03, SoC: 96.79, TTE: 15039, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.476,745] : delta: 0.100000, V: 3.989, I: 0.019, T: 26.03, SoC: 96.78, TTE: 15039, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.576,812] : delta: 0.100000, V: 3.999, I: 0.021, T: 26.03, SoC: 96.78, TTE: 15038, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.676,696] : delta: 0.100000, V: 3.989, I: 0.023, T: 26.03, SoC: 96.78, TTE: 15038, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.776,763] : delta: 0.100000, V: 3.994, I: 0.019, T: 26.03, SoC: 96.78, TTE: 15038, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.876,922] : delta: 0.100000, V: 3.999, I: 0.039, T: 26.03, SoC: 96.78, TTE: 15038, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:18.976,715] : delta: 0.100000, V: 4.003, I: 0.043, T: 26.03, SoC: 96.78, TTE: 15037, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.076,782] : delta: 0.100000, V: 3.994, I: 0.011, T: 26.03, SoC: 96.78, TTE: 15037, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.176,940] : delta: 0.100000, V: 3.999, I: 0.067, T: 26.03, SoC: 96.78, TTE: 15037, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.276,733] : delta: 0.100000, V: 3.994, I: 0.023, T: 26.03, SoC: 96.78, TTE: 15037, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.376,800] : delta: 0.100000, V: 3.984, I: 0.022, T: 26.03, SoC: 96.78, TTE: 15036, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.476,959] : delta: 0.100000, V: 3.994, I: 0.035, T: 26.03, SoC: 96.78, TTE: 15036, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.576,812] : delta: 0.100000, V: 4.003, I: 0.022, T: 26.03, SoC: 96.78, TTE: 15036, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.676,788] : delta: 0.100000, V: 3.994, I: 0.019, T: 26.03, SoC: 96.78, TTE: 15035, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.776,947] : delta: 0.100000, V: 4.003, I: 0.021, T: 26.03, SoC: 96.78, TTE: 15035, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.876,861] : delta: 0.100000, V: 3.994, I: 0.021, T: 26.03, SoC: 96.78, TTE: 15035, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:19.976,837] : delta: 0.100000, V: 3.994, I: 0.009, T: 26.03, SoC: 96.77, TTE: 15035, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.076,995] : delta: 0.100000, V: 4.003, I: 0.039, T: 26.03, SoC: 96.77, TTE: 15035, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.176,879] : delta: 0.100000, V: 4.003, I: 0.020, T: 26.03, SoC: 96.77, TTE: 15034, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.276,855] : delta: 0.100000, V: 3.994, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15034, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.377,014] : delta: 0.100000, V: 3.994, I: 0.021, T: 26.03, SoC: 96.77, TTE: 15034, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.477,020] : delta: 0.100000, V: 3.989, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15034, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.576,843] : delta: 0.100000, V: 3.999, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15033, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.677,032] : delta: 0.100000, V: 3.994, I: 0.039, T: 26.03, SoC: 96.77, TTE: 15033, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.776,885] : delta: 0.100000, V: 3.994, I: 0.011, T: 26.03, SoC: 96.77, TTE: 15033, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.876,922] : delta: 0.100000, V: 3.999, I: 0.021, T: 26.03, SoC: 96.77, TTE: 15033, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:20.977,050] : delta: 0.100000, V: 4.003, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15032, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.076,934] : delta: 0.100000, V: 3.994, I: 0.039, T: 26.03, SoC: 96.77, TTE: 15032, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.176,940] : delta: 0.100000, V: 3.989, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15032, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.277,069] : delta: 0.100000, V: 3.999, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15032, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.377,075] : delta: 0.100000, V: 3.994, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15032, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.476,959] : delta: 0.100000, V: 3.979, I: 0.043, T: 25.62, SoC: 96.77, TTE: 15031, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.577,087] : delta: 0.100000, V: 4.003, I: 0.019, T: 26.03, SoC: 96.77, TTE: 15031, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.677,062] : delta: 0.100000, V: 3.999, I: 0.022, T: 26.03, SoC: 96.77, TTE: 15031, TTF: nan, Chging 0, Conn 0, ChgSt 0
[00:14:21.776,947] : delta: 0.100000, V: 3.999, I: 0.009, T: 26.03, SoC: 96.76, TTE: 15031, TTF: nan, Chging 0, Conn 0, ChgSt 0

Question: Do you have any suggestions on how I could get more reliable SoC values from the chip?
Question: Is there a maximum interval between nrf_fuel_gauge_process() calls (i.e. a maximum delta) beyond which the update is not reliable (e.g. 500 ms?)
Question: Does the fuel gauge algorithm average its input over time?

Thanks

  • I compared SDK 2.9.2 to SDK 3.1.1, and I noticed that in nrf_fuel_gauge_init_parameters() there is a new addition:

    /** Optional state memory, previously retrieved using @ref nrf_fuel_gauge_state_get.
    * When used, the library resumes from this state and all other parameters are ignored.
    * Set to NULL when not used or when initializing the library for the first time.
    */
    const void *state;

    Is this used to save the SoC?
    If so, this would probably be useful.
    Unfortunately, it is not an option for us, right now, to upgrade out current project to use SDK 3.1.1.

  • Hi

    Based on the logs you have provided I'm not sure what values it is you refer to being different before/after a reboot? As far as I know there is no maximum delta where measurements aren't supported anymore.

    As for why the voltage and current changes that is normal for a running device since it moves between different modes pretty often.

    No, it does not average over time, why would you think that? 

    As for the state memory, that is indeed used for storing the fuel gauge state so that it can resume from the last known state. As the comment says, on older SDKs this was retrieved using nrf_fuel_gauge_state_get() if moving to NCS v3.1.1 is not an option for you.

    Best regards,

    Simon

  • Hi 

    Could you share the battery model file used and the project folder created during the profiling process? I can first have a look whether the battery model is correct.

    During discharge, the default recommended fuel gauge sampling rate is 1 second. The fuel gauge is designed for ultra-low-power operation when supplied from the battery.
    If you can provide the battery capacity and average application currents during discharge, we can suggest an optimized sampling rate.
    During charging, using a 100 ms interval is fine since USB power removes power constraints.

    Also, do you use the Battery Discharge Current Limit feature to limit discharge current and improve current measurement accuracy? Here the Low setting is recommended for better fuel gauge performance and stable current measurement.

    Fuel Gauge Initialization

    Initialize only when the battery is at rest and system activity is low. For example, initializing during charging is not recommended.The ideal moment is immediately after reboot, before enabling downstream peripherals or the charger. This ensures minimal load on the battery.

    The nrf_fuel_gauge_init() function uses the first measurement of voltage, current, and temperature.To ensure an accurate baseline, take this measurement when the battery is chemically stable (not charging and not under significant load).

    Some initialization error may still occur, but the algorithm corrects these gradually as the battery discharges.
    The fuel gauge library automatically reinitializes after a full-charge event, ensuring accurate SoC near 100% and preventing error accumulation.

    More info Fuel Guage initialization chapter in the fuel gauge app note for more info.


    Sleep Mode Considerations

    If the host enters sleep (RAM retained), do not reinitialize the fuel gauge upon wakeup. Instead, use nrf_fuel_gauge_idle_set() before sleep to notify the library of idle periods. Provide the expected average current during idle to improve estimation accuracy. When normal activity resumes, call nrf_fuel_gauge_process() to return to active tracking. This significantly accelerates ffuel gauge convergence after period of long inactivity.
    See Sleep Current Configuration and Fuel gauge RAM retention chapter in the fuel gauge app note for more info. 

    Hope this helps

    Regards 

    Tharaka




  • I upgraded the project to use SDK 3.1.1, so the firmware could take advantage of the nrf_fuel_gauge_state_get() function.

    What the firmware does

    For test purposes, once every minute it calls nrf_fuel_gauge_state_get(), saving the contents to a 256 byte buffer.
    Whenever the device is going to shutdown (nPM1300, ship mode), it first saves the fuel gauge state information to Flash, and restores this on boot up.
    Generally, this setup has been working for a few days for me – I have observed the same SoC being restored on boot, as was saved on the previous shutdown.
    Note: When saving data to Flash before shutdown, there is a 3 second delay after saving, before shutdown (shipmode).


    However, what I have noticed is that sometimes, after flashing the device, the restored SoC goes to zero.

    This has happened while re-flashing the same hex file as was currently running on the device. See step 8 below.
    In this example, the hex file was different (I added a global variable, and incremented it in one function, just to change the memory layout of the code). But I have also observed this phenomenon when re-flashing the same hex file.
    Also, notice that the fuel gauge state buffer contents are the same for step6 and step 8.

    Code

    This is what is saved in Flash. The magic number helps the firmware determine if the contents are valid or not.

    #define FG_MAGIC 12344321u
    #define FG_STATE_BUF_SIZE 256
    typedef struct
    {
        int magic;
        bool fg_valid;
        uint8_t fuel_gauge_state_buf[FG_STATE_BUF_SIZE];
    } imme_fuelgauge_state__t;

    Saving to Flash:

    ret = nrf_fuel_gauge_state_get(fuel_gauge_state.fuel_gauge_state_buf, sizeof(fuel_gauge_state.fuel_gauge_state_buf));

    Restoring from Flash:

    	rc = nvs_read(&fs, FUEL_GAUGE_STATE_ID, &fuel_gauge_state_saved, sizeof(fuel_gauge_state_saved));
    	if (rc > 0) { 		
    		// item was found, show it
            if (fuel_gauge_state_exists()) {
                LOG_INF("FUEL_GAUGE_STATE_ID: Saved data valid (rc = %d, magic %d, valid %d) - restoring", rc, fuel_gauge_state_saved.magic, fuel_gauge_state_saved.fg_valid);
                fuel_gauge_state = fuel_gauge_state_saved;
                log_fuel_gauge_state_buffer(fuel_gauge_state.fuel_gauge_state_buf, sizeof(fuel_gauge_state.fuel_gauge_state_buf));

    Initialising the fuel gauge:

    	ret = read_sensors(charger, &parameters.v0, &parameters.i0, &parameters.t0, &chg_status);
    	if (ret < 0) {
    		return ret;
    	}
    	parameters.i0 = -parameters.i0;
    
        if (parameters.v0 < BATTERY_V_OK_THRESHOLD) {
            LOG_INF("Battery voltage too low on startup: V=%.3fV. Shutting down", parameters.v0);
            battery_init_v_low = true;
        }
        
    	sensor_channel_get(charger, SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT, &value);
    	max_charge_current = (float)value.val1 + ((float)value.val2 / 1000000);
    	term_charge_current = max_charge_current / 10.f;
    
        if (fuel_gauge_state.fg_valid &&
            fuel_gauge_state_exists() &&
            (nrf_fuel_gauge_state_size <= sizeof(fuel_gauge_state.fuel_gauge_state_buf))) {
            parameters.state = fuel_gauge_state.fuel_gauge_state_buf;
            b_used_buf = true;
        } else {
            parameters.state = NULL;
        }
    
    	ret = nrf_fuel_gauge_init(&parameters, NULL);

    The firmware then outputs the contents of fuel_gauge_state.fuel_gauge_state_buf, and I can confirm that the contents are the same, as expected (and the b_used_buf indicates that the fuel gauge state buffer was used in the initialisation).

    Question: Can you explain this behaviour / can you see if I am doing anything wrong?

    Here is an example:

    Step 1

    Before shipmode, Fuel Gauge state is saved, when SoC was approx. 89.03.

    Step 2
    Contents after restore (missed some of the RTT output):

    [00:00:00.288,940] <inf> fuel_gauge: [080-095]: 00 00 A0 40 00 00 48 42 00 00 F0 41 33 33 73 3F
    [00:00:00.306,518] <inf> fuel_gauge: [096-111]: 66 66 A6 3F 00 00 80 3F 00 00 70 42 00 00 C0 3F
    [00:00:00.324,066] <inf> fuel_gauge: [112-127]: 66 66 66 3F 33 33 73 3F 7A 6E 21 BC 00 00 00 00
    [00:00:00.341,674] <inf> fuel_gauge: [128-143]: 2B 87 76 40 00 00 C0 7F 7A 6E 21 BC 00 00 C8 41
    [00:00:00.359,313] <inf> fuel_gauge: [144-159]: 85 E9 63 3F 00 00 00 00 EC 51 18 3F 00 00 C0 7F
    [00:00:00.376,861] <inf> fuel_gauge: [160-175]: 85 E9 63 3F 1B 82 82 46 09 60 A0 B8 00 00 C8 41
    [00:00:00.394,470] <inf> fuel_gauge: [176-191]: 00 00 C8 41 01 00 00 00 00 00 40 40 00 00 80 40
    [00:00:00.412,048] <inf> fuel_gauge: [192-207]: EE 54 36 3C CB 95 40 3C 00 00 00 00 85 E9 63 3F
    [00:00:00.429,656] <inf> fuel_gauge: [208-223]: E9 03 AE 40 E9 03 AE 40 D8 02 AE 40 D8 02 AE 40
    [00:00:00.447,296] <inf> fuel_gauge: [224-239]: 78 D2 05 00 34 12 CD AB 00 00 00 00 00 00 00 00
    [00:00:00.464,904] <inf> fuel_gauge: [240-255]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    SoC restored at 89.03:

    [00:00:04.736,328] <inf> Charger update: dt:2.470 V:3.906 I:0.018 T:23.98 SoC:89.03 TTE:nan TTF:nan chg:0 st:0 vbus=0, full=0

    Step 3
    One minute later, save state when SoC is approx. 88.80:

    [00:00:59.776,428] <inf> fuel_gauge: [000-015]: 00 00 80 3F 00 00 00 40 D9 52 24 37 26 60 47 37
    [00:00:59.794,067] <inf> fuel_gauge: [016-031]: 00 00 00 00 93 7B DE B6 26 60 47 37 50 8A 74 37
    [00:00:59.811,584] <inf> fuel_gauge: [032-047]: 00 00 00 00 97 1F 06 B7 00 00 00 00 00 00 00 00
    [00:00:59.829,071] <inf> fuel_gauge: [048-063]: 77 CC 2B 32 00 00 00 00 88 7B DE B6 97 1F 06 B7
    [00:00:59.846,557] <inf> fuel_gauge: [064-079]: 00 00 00 00 8F 01 7B 37 A6 9B 44 3B 6F 12 83 3A
    [00:00:59.864,044] <inf> fuel_gauge: [080-095]: 00 00 A0 40 00 00 48 42 00 00 F0 41 33 33 73 3F
    [00:00:59.881,530] <inf> fuel_gauge: [096-111]: 66 66 A6 3F 00 00 80 3F 00 00 70 42 00 00 C0 3F
    [00:00:59.899,017] <inf> fuel_gauge: [112-127]: 66 66 66 3F 33 33 73 3F 7A 6E 21 3C 00 00 00 00
    [00:00:59.916,503] <inf> fuel_gauge: [128-143]: 39 B4 78 40 00 00 C0 7F 7A 6E 21 3C 00 00 C8 41
    [00:00:59.933,990] <inf> fuel_gauge: [144-159]: 73 2D 63 3F 00 00 00 00 48 E1 65 42 85 E9 63 3F
    [00:00:59.951,477] <inf> fuel_gauge: [160-175]: 00 00 C0 7F 00 00 C0 7F 48 DF 69 B8 00 00 C8 41
    [00:00:59.968,963] <inf> fuel_gauge: [176-191]: 00 00 C8 41 01 00 00 00 00 00 40 40 00 00 80 40
    [00:00:59.986,663] <inf> fuel_gauge: [192-207]: DD 29 14 3C F0 6D 1B 3C 00 00 00 00 73 2D 63 3F
    [00:01:00.004,150] <inf> fuel_gauge: [208-223]: E9 03 AE 40 E9 03 AE 40 CC 02 AE 40 CC 02 AE 40
    [00:01:00.021,636] <inf> fuel_gauge: [224-239]: 78 D2 05 00 34 12 CD AB 00 00 00 00 00 00 00 00
    [00:01:00.039,154] <inf> fuel_gauge: [240-255]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    Step 4
    15 seconds later (SoC approx. 88.59), flash in SAME hex file, while device still running.

    Step 5
    On boot, after flash restore, contents:

    [00:00:00.209,808] <inf> fuel_gauge: [016-031]: 00 00 00 00 93 7B DE B6 26 60 47 37 50 8A 74 37
    [00:00:00.227,447] <inf> fuel_gauge: [032-047]: 00 00 00 00 97 1F 06 B7 00 00 00 00 00 00 00 00
    [00:00:00.244,995] <inf> fuel_gauge: [048-063]: 77 CC 2B 32 00 00 00 00 88 7B DE B6 97 1F 06 B7
    [00:00:00.262,573] <inf> fuel_gauge: [064-079]: 00 00 00 00 8F 01 7B 37 A6 9B 44 3B 6F 12 83 3A
    [00:00:00.280,212] <inf> fuel_gauge: [080-095]: 00 00 A0 40 00 00 48 42 00 00 F0 41 33 33 73 3F
    [00:00:00.297,821] <inf> fuel_gauge: [096-111]: 66 66 A6 3F 00 00 80 3F 00 00 70 42 00 00 C0 3F
    [00:00:00.315,399] <inf> fuel_gauge: [112-127]: 66 66 66 3F 33 33 73 3F 7A 6E 21 3C 00 00 00 00
    [00:00:00.332,977] <inf> fuel_gauge: [128-143]: 39 B4 78 40 00 00 C0 7F 7A 6E 21 3C 00 00 C8 41
    [00:00:00.350,555] <inf> fuel_gauge: [144-159]: 73 2D 63 3F 00 00 00 00 48 E1 65 42 85 E9 63 3F
    [00:00:00.368,194] <inf> fuel_gauge: [160-175]: 00 00 C0 7F 00 00 C0 7F 48 DF 69 B8 00 00 C8 41
    [00:00:00.385,803] <inf> fuel_gauge: [176-191]: 00 00 C8 41 01 00 00 00 00 00 40 40 00 00 80 40
    [00:00:00.403,350] <inf> fuel_gauge: [192-207]: DD 29 14 3C F0 6D 1B 3C 00 00 00 00 73 2D 63 3F
    [00:00:00.420,928] <inf> fuel_gauge: [208-223]: E9 03 AE 40 E9 03 AE 40 CC 02 AE 40 CC 02 AE 40
    [00:00:00.438,568] <inf> fuel_gauge: [224-239]: 78 D2 05 00 34 12 CD AB 00 00 00 00 00 00 00 00
    [00:00:00.456,176] <inf> fuel_gauge: [240-255]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    SoC restored to 88.68

    [00:00:04.727,203] <inf> iCharger update: dt:2.470 V:3.867 I:0.010 T:24.59 SoC:88.68 TTE:nan TTF:nan chg:0 st:0 vbus=0, full=0
    Step 6

    One minute later, save state when SoC is approx. 88.33:

    [00:00:59.767,608] <inf> fuel_gauge: [000-015]: 00 00 80 3F 00 00 00 40 97 45 25 37 56 A0 48 37
    [00:00:59.785,095] <inf> fuel_gauge: [016-031]: 00 00 00 00 40 1E E7 B6 56 A0 48 37 AA 20 76 37
    [00:00:59.802,612] <inf> fuel_gauge: [032-047]: 00 00 00 00 A7 A3 0A B7 00 00 00 00 00 00 00 00
    [00:00:59.820,068] <inf> fuel_gauge: [048-063]: 77 CC 2B 32 00 00 00 00 34 1E E7 B6 A6 A3 0A B7
    [00:00:59.837,554] <inf> fuel_gauge: [064-079]: 00 00 00 00 BA AF 78 37 A6 9B 44 3B 6F 12 83 3A
    [00:00:59.855,041] <inf> fuel_gauge: [080-095]: 00 00 A0 40 00 00 48 42 00 00 F0 41 33 33 73 3F
    [00:00:59.872,772] <inf> fuel_gauge: [096-111]: 66 66 A6 3F 00 00 80 3F 00 00 70 42 00 00 C0 3F
    [00:00:59.890,258] <inf> fuel_gauge: [112-127]: 66 66 66 3F 33 33 73 3F 5D 16 93 3C 00 00 00 00
    [00:00:59.907,745] <inf> fuel_gauge: [128-143]: EE 7C 77 40 AC 60 64 46 5D 16 93 3C 00 00 C8 41
    [00:00:59.925,231] <inf> fuel_gauge: [144-159]: F9 0F 62 3F 00 00 00 00 48 E1 E5 42 85 E9 63 3F
    [00:00:59.942,718] <inf> fuel_gauge: [160-175]: 00 00 C0 7F AC 60 64 46 FE B6 81 B8 00 00 C8 41
    [00:00:59.960,205] <inf> fuel_gauge: [176-191]: 00 00 C8 41 01 00 00 00 00 00 40 40 00 00 80 40
    [00:00:59.977,905] <inf> fuel_gauge: [192-207]: 5F 16 1B 3C 76 A9 26 3C 00 00 00 00 F9 0F 62 3F
    [00:00:59.995,391] <inf> fuel_gauge: [208-223]: E9 03 AE 40 E9 03 AE 40 C0 02 AE 40 C0 02 AE 40
    [00:01:00.012,878] <inf> fuel_gauge: [224-239]: 78 D2 05 00 34 12 CD AB 00 00 00 00 00 00 00 00
    [00:01:00.030,395] <inf> fuel_gauge: [240-255]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    Step 7

    30 seconds later (SoC approx. 88.11), flash in DIFFERENT hex file, while device still running.

    Step 8
    On boot, after flash restore, contents:

    [00:00:00.176,086] <inf> fuel_gauge: [000-015]: 00 00 80 3F 00 00 00 40 97 45 25 37 56 A0 48 37
    [00:00:00.193,603] <inf> fuel_gauge: [016-031]: 00 00 00 00 40 1E E7 B6 56 A0 48 37 AA 20 76 37
    [00:00:00.211,212] <inf> fuel_gauge: [032-047]: 00 00 00 00 A7 A3 0A B7 00 00 00 00 00 00 00 00
    [00:00:00.228,759] <inf> fuel_gauge: [048-063]: 77 CC 2B 32 00 00 00 00 34 1E E7 B6 A6 A3 0A B7
    [00:00:00.246,307] <inf> fuel_gauge: [064-079]: 00 00 00 00 BA AF 78 37 A6 9B 44 3B 6F 12 83 3A
    [00:00:00.263,885] <inf> fuel_gauge: [080-095]: 00 00 A0 40 00 00 48 42 00 00 F0 41 33 33 73 3F
    [00:00:00.281,433] <inf> fuel_gauge: [096-111]: 66 66 A6 3F 00 00 80 3F 00 00 70 42 00 00 C0 3F
    [00:00:00.299,011] <inf> fuel_gauge: [112-127]: 66 66 66 3F 33 33 73 3F 5D 16 93 3C 00 00 00 00
    [00:00:00.316,558] <inf> fuel_gauge: [128-143]: EE 7C 77 40 AC 60 64 46 5D 16 93 3C 00 00 C8 41
    [00:00:00.334,136] <inf> fuel_gauge: [144-159]: F9 0F 62 3F 00 00 00 00 48 E1 E5 42 85 E9 63 3F
    [00:00:00.351,684] <inf> fuel_gauge: [160-175]: 00 00 C0 7F AC 60 64 46 FE B6 81 B8 00 00 C8 41
    [00:00:00.369,293] <inf> fuel_gauge: [176-191]: 00 00 C8 41 01 00 00 00 00 00 40 40 00 00 80 40
    [00:00:00.386,840] <inf> fuel_gauge: [192-207]: 5F 16 1B 3C 76 A9 26 3C 00 00 00 00 F9 0F 62 3F
    [00:00:00.404,418] <inf> fuel_gauge: [208-223]: E9 03 AE 40 E9 03 AE 40 C0 02 AE 40 C0 02 AE 40
    [00:00:00.422,027] <inf> fuel_gauge: [224-239]: 78 D2 05 00 34 12 CD AB 00 00 00 00 00 00 00 00
    [00:00:00.439,605] <inf> fuel_gauge: [240-255]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    SoC is now zero:

    [00:00:09.708,831] <inf> Charger update: dt:5.000 V:3.847 I:0.029 T:24.79 SoC:0.00 TTE:nan TTF:nan chg:0 st:0 vbus=0, full=0


    Step 9
    Device entered shipmode approx. 1 minute later (firmware logic, because SoC is zero), and FG state buffer contents were:

    [00:00:54.844,238] <inf> fuel_gauge: [000-015]: 00 00 80 3F 00 00 00 40 FF FF FF 7F FF FF FF 7F
    [00:00:54.861,694] <inf> fuel_gauge: [016-031]: FF FF FF 7F FF FF FF 7F FF FF FF 7F FF FF FF 7F
    [00:00:54.879,150] <inf> fuel_gauge: [032-047]: FF FF FF 7F FF FF FF 7F FF FF FF 7F FF FF FF 7F
    [00:00:54.896,728] <inf> fuel_gauge: [048-063]: FF FF FF 7F FF FF FF 7F FF FF FF 7F FF FF FF 7F
    [00:00:54.914,337] <inf> fuel_gauge: [064-079]: FF FF FF 7F FF FF FF 7F 9A 99 99 3E BD 37 86 35
    [00:00:54.931,823] <inf> fuel_gauge: [080-095]: 00 00 A0 40 00 00 48 42 00 00 F0 41 33 33 73 3F
    [00:00:54.949,279] <inf> fuel_gauge: [096-111]: 66 66 A6 3F 00 00 80 3F 00 00 70 42 00 00 C0 3F
    [00:00:54.966,735] <inf> fuel_gauge: [112-127]: 66 66 66 3F 33 33 73 3F 27 BC 84 BC 00 00 00 00
    [00:00:54.984,191] <inf> fuel_gauge: [128-143]: 68 91 75 40 00 00 C0 7F 27 BC 84 BC 00 00 C8 41
    [00:00:55.001,678] <inf> fuel_gauge: [144-159]: 00 00 00 00 00 00 00 00 68 91 ED 3D 00 00 C0 7F
    [00:00:55.019,165] <inf> fuel_gauge: [160-175]: 00 00 00 00 B1 30 59 46 EB 13 9C BB 00 00 C8 41
    [00:00:55.036,621] <inf> fuel_gauge: [176-191]: 00 00 C8 41 01 00 00 00 00 00 40 40 00 00 80 40
    [00:00:55.054,107] <inf> fuel_gauge: [192-207]: FF FF FF FF FF FF FF FF 00 00 80 BF 00 00 00 00
    [00:00:55.071,563] <inf> fuel_gauge: [208-223]: E9 03 AE 40 54 61 D1 3A B4 02 AE 40 B4 02 AE 40
    [00:00:55.089,019] <inf> fuel_gauge: [224-239]: 78 D2 05 00 34 12 CD AB 00 00 00 00 00 00 00 00
    [00:00:55.106,506] <inf> fuel_gauge: [240-255]: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

  • Hi.

    The same thing occurred just now as I tested DFU.

    I flashed my device with an older version of my project (built using SDK 2.9.2).

    With my latest project (SDK 3.1.1), I created two .bin files - the difference being an extra global debug counter which is incremented in one of the functions - just to be different, no other reason.

    I used Nordic's Device Manager to flash the remote device, with the first .bin file. All went well. SoC remained almost the same (90%). I then reset the device, checked everything, and used Device Manager to send the second .bin file. When the upload was complete, the SoC was now zero.

    I then repeated the above test with two new .bin files (SDK 13.1.1). This time, as well as one of the builds using a debug counter, I also changed the Magic Number used for validating the Fuel Gauge state. So the two .bin files had different magic numbers. I flashed the device (using VSCode) with the 2.9.2 project then used Device Manager to send the first .bin file. All good. SoC is about 90%. I then used Device Manager to send the second bin file. Again, all good. Because this time, the device did NOT use the restored state buffer (256 bytes), when initialising the fuel gauge.

    So it seems, for now, until this is solved, I have to change the magic number associated with teh saved fuel gauge state, every time I send a new .bin file out.

Related