Fuel Gauge

The npmx Fuel Gauge sample demonstrates how to calculate the battery State of Charge with the use of the nRF Fuel Gauge library and npmx drivers.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

The sample also requires an nPM1300 EK.

Overview

This sample allows to calculate the State of Charge, Time to Empty and Time to Full levels from a battery connected to the nPM1300 PMIC.

Wiring

  1. Connect the TWI interface between the chosen DK and the nPM1300 EK as in the following table:

    nPM1300 EK connections.

    nPM1300 EK pins

    nRF5340 DK pins

    nRF52840 DK pins

    GPIO0

    P1.10

    P1.10

    SDA

    P1.02

    P0.26

    SCL

    P1.03

    P0.27

    VOUT2 & GND

    External supply (P21)

    External supply (P21)

  2. Make the following connections on the DK:

    • Set the SW9 nRF power source switch to VDD.

    • Set the SW10 VEXT → nRF switch to ON.

  3. Make the following connections on the nPM1300 EK:

    • On the P18 pin header, connect VOUT2 and VDDIO pins with a jumper.

    • On the P2 pin header, connect VBAT and VBATIN pins with a jumper.

    • On the P17 pin header, connect all LEDs with jumpers.

    • On the P13 pin header, connect VSET1 and GND pins with a jumper.

    • On the P14 pin header, connect VSET2 and RSET2 pins with a jumper.

    • Connect a suitable battery to the J2 connector.

    • Connect a USB power supply to the J3 connector.

Configuration

See Application Configuration for information about how to permanently or temporarily change the configuration.

Configuration options

Check and configure the following sample-specific Kconfig options:

CONFIG_CURRENT_LIMIT

This option changes the VBUSIN current limit.

CONFIG_CHARGING_CURRENT

This option changes the battery charging current.

CONFIG_DISCHARGING_CURRENT

This option changes the battery discharge current limit.

CONFIG_TERMINATION_VOLTAGE_NORMAL

This option changes the battery termination voltage in normal temperature.

CONFIG_TERMINATION_VOLTAGE_WARM

This option changes the battery termination voltage in warm temperature.

CONFIG_THERMISTOR_RESISTANCE

This option changes the thermistor nominal resistance.

CONFIG_THERMISTOR_BETA

This option changes the thermistor beta value.

Building and running

This sample can be found under samples/fuel_gauge in the npmx-zephyr repository folder structure.

To build the sample with zephyr, follow the steps listed on the Building an Application page in Zephyr documentation.

Testing

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

If the initialization was successful, the terminal displays the following message with status information:

[00:00:00.000,000] <inf> fuel_gauge_main: PMIC device OK.
[00:00:00.000,000] <inf> fuel_gauge_main: Fuel gauge OK.
[00:00:00.000,000] <inf> fuel_gauge: V: 4.121, I: -0.127, T: 23.26, SoC: 87.63, TTE: nan, TTF: 2373

Symbol

Description

Units

V

Battery voltage

Volts

I

Current

Amperes (negative for charge, positive for discharge)

T

Temperature

Degrees Celsius

SoC

State of Charge

Percent

TTE

Time to Empty

Seconds (may be NaN)

TTF

Time to Full

Seconds (may be NaN)

Dependencies

This sample uses sdk-nrfxlib library and npmx library.