nPM2100: Fuel gauge
The Fuel gauge sample demonstrates how to calculate the state of charge of a supported primary cell battery using the nPM2100 and the nRF Fuel Gauge library.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
|
|---|---|---|---|
nRF54LS05 DK |
PCA10214 |
nrf54ls05dk |
|
PCA10156 |
|
||
PCA10095 |
|
||
PCA10056 |
|
The sample also requires an nPM2100 evaluation kit that you need to connect to the development kit as described in Wiring.
Overview
This sample allows the calculation of state of charge from a battery connected to the nPM2100 PMIC.
Battery models for Alkaline AA (1S and 2S configuration), AAA (1S and 2S configuration), LR44, and Lithium-manganese dioxide coin cell CR2032 batteries are included. You can change the active battery model using a shell command, as illustrated in Testing. You can also change the battery model at compile time by selecting the type of battery using the following Kconfig options:
|
Alkaline AA battery model |
|
Alkaline AAA battery model |
|
2x alkaline AA battery (in series) model |
|
2x alkaline AAA battery (in series) model |
|
Alkaline LR44 coin cell model |
|
Lithium CR2032 coin cell |
When the Zephyr Settings subsystem is enabled, the sample also demonstrates how to store the fuel gauge state in non-volatile memory and restore it on boot. You can store the fuel gauge state using the shell command described in Testing.
Wiring
With this configuration, the nPM2100 EK is wired to supply power to the DK. This ensures that the TWI communication is at compatible voltage levels, and represents a realistic use case for the nPM2100 PMIC.
Note
To prevent leakage currents and program the DK, do not remove the USB connection.
Unplug the battery from the nPM2100 EK and set the DK power switch to “OFF” while applying the wiring described below. If you have issues communicating with the DK or programming it after applying the wiring, try to power cycle the DK and EK.
To connect your DK to the nPM2100 EK, complete the following steps:
Prepare the DK for being powered by the nPM2100 EK:
Set switch SW9 (“nRF power source”) to position “VDD”.
Set switch SW10 (“VEXT -> VnRF”) to position “ON”.
Remove jumper from P6 (“VDDM CURRENT MEASURE”).
Connect the TWI interface and power supply between the chosen DK and the nPM2100 EK as described in the following table:
nPM2100 EK connections. nPM2100 EK pins
nRF52840 DK pins
nRF5340 DK pins
nRF54L Series DK pins
SDA
P0.26
P1.02
P1.11
SCL
P0.27
P1.03
P1.12
VOUT
P21 External supply
P21 External supply
P6 VDDM current measure, VDD:nRF pin
GND
GND
GND
GND
Make the following connections on the nPM2100 EK:
Remove the USB power supply from the J4 connector.
On the P6 pin header, connect pins 1 and 2 with a jumper.
On the BOOTMON pin header, select OFF with a jumper.
On the VSET pin header, select 3.0V with a jumper.
On the VBAT SEL switch, select VBAT position.
Connect a battery board to the BATTERY INPUT connector.
Building and running
This sample can be found under samples/pmic/native/npm2100_fuel_gauge in the nRF Connect SDK folder structure.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.
Testing
After programming the sample to your development kit, complete the following steps to test it:
Connect the kit to the computer using a USB cable. The kit is assigned a serial port. Serial ports are referred to as COM ports on Windows, /dev/ttyACM devices on Linux, and /dev/tty devices on macOS. To list Nordic Semiconductor devices connected to your computer together with their serial ports, open a terminal and run the
nrfutil device listcommand. Alternatively, check your operating system’s device manager or its equivalent.Connect to the kit with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.
If the initialization was successful, the terminal displays the following message with status information:
PMIC device ok
nRF Fuel Gauge version: 1.0.0
Fuel gauge initialised for Alkaline AA battery.
V: 1.188, T: 20.62, SoC: 25.00
Symbol
Description
Units
V
Battery voltage
Volts
T
Temperature
Degrees C
SoC
State of Charge
Percent
Determine the active battery type using the following shell command:
$ battery_model
Battery model: Alkaline AA
Use the same shell command to change the active battery type:
$ battery_model Lithium_CR2032
Fuel gauge initialised for Lithium CR2032 battery.
To store the fuel gauge state in non-volatile memory, use the following shell command:
$ fuel_gauge_state_store
Storing state after next update
The fuel gauge state will be stored in non-volatile memory after the next measurement has been performed, and restored on the next boot.
The state is stored for each battery type, so changing the battery type with the battery_model command will not affect the stored state of other battery types.
Use the following shell commands to view the stored state and clear it, using Alkaline AA as an example:
$ settings list
fuel_gauge_state/Alkaline AAA
fuel_gauge_state/Alkaline AA
$ settings delete fuel_gauge_state/Alkaline\ AA
$ settings list
fuel_gauge_state/Alkaline AAA
Dependencies
The sample uses the following sdk-nrfxlib library:
In addition, it uses the following Zephyr libraries: