Using nPM1300 Battery Charger and Power Rails

Using nPM1300 Battery Charger and Power Rails

1.
Overview

This application note describes how to configure nPM1300 PMIC in Zephyr BSP and use it in the user application.

2.
SOM-nRF9151 Power Architecture

The power architecture of the nRF9151 SOM is based on the NORDIC Semiconductor nPM1300 PMIC, which has several power and system management features:

  • System regulator (SYSREG) of the PMIC supplies main power rail VSYS from:

    •  VBUS (VIN from an AC wall adapter or a USB port- if/when they are present);

    • Battery (VBAT_C): when a battery is connected but VIN (VBUS) isn’t present;

  • The VSYS voltage is 4V-5.5V when it is supplied from the VIN (VBUS) (+5V power is present) and 3.2V-4.4V when it is supplied from the Battery/VBAT_C (+5V power isn’t present)

    • Two 200mA BUCK regulators:

      • §  BUCK2 (VOUT2) @ 3.0V is used on the SOM and broken out to the SOM interface connectors;

      • §  BUCK1 is disabled by default, may be enabled and configured by software to a 1.0V-3.0V output voltage. It is available on SOM interface connectors;

    • Two LDO/Load Switches :

      • §  LDO1/LSW1 gets power from the BUCK1 output. LDO1/LSW1 is disabled by default, may be enabled and configured by software to a 1.0V-3.0V output voltage. It is available on the SOM interface connectors;

      • §  LDO2/LSW2 isn’t used in the nRF9151 SOM

  • SYSREG provide the following features:

    • Operating voltage up to 5.5 V

    • Overvoltage protection to 22 V

    • Undervoltage detection

    • USB port detection and a current limiter to comply with the USB specification

    • Provides VBUSOUT voltage

  • In the nRF9151 SOM, the nPM1300 supplies VBUSOUT voltage on the SOM interface connectors when VIN (VBUS) voltage is present. VBUSOUT provides overvoltage and undervoltage protection for safe connection to external devices.

  • The nPM1300 supports the USB PD Configuration Channel functionality.

  • The PMIC VIN (VBUS) input current limiter manages VIN (VBUS) current limitation and charger detection for USB Type-C compatible chargers. The VIN (VBUS) current limit value is configurable by software.

  • The PMIC battery charger is suitable for general purpose applications with lithium-ion (Li-ion), lithium-polymer (Li-poly), and lithium iron phosphate (LiFePO4) batteries.

  • nPM1300 supports charging up to 800 mA and delivers up to 500 mA of adjustable regulated voltage.

For more details about the SOM-NRF9151 hardware and power architecture refer to https://voxelbotics.atlassian.net/wiki/x/GQAcKw.

3.
Configuring nPM1300 PMIC in Zephyr BSP

The nPM1300 PMIC device is declared in nrf9151som_nrf9151_ns.dts as a child node of the i2c1 bus:

&i2c1 { status = "okay"; ... npm1300_pmic: pmic@6b { compatible = "nordic,npm1300"; reg = <0x6b>; status = "okay"; host-int-gpios = <&gpio0 10 0>; pmic-int-pin = <0>; ... }; };

This node configures the following parameters:

Parameter

Value

Description

Parameter

Value

Description

compatible

"nordic,npm1300"

Enables the mfd_npm1300.c driver and associates it with the device.

reg

<0x6b>

nPM1300 slave address on the I2C bus, which will be used by the driver to communicate with the PMIC.

host-int-gpios

<&gpio0 10 0>

Host SoC GPIO, that will be used for PMIC interrupts.

pmic-int-pin

<0>

nPM1300 interrupt pin.

3.1.
Configuring nPM1300 Battery Charger

The nPM1300 Battery Charger device is declared in nrf9151som_nrf9151_ns.dts as a child node of the npm1300_pmic device:

npm1300_pmic: pmic@6b { compatible = "nordic,npm1300"; ... npm1300_charger: charger { compatible = "nordic,npm1300-charger"; term-microvolt = <4200000>; term-current-percent= <10>; current-microamp = <500000>; dischg-limit-microamp = <1340000>; vbus-limit-microamp = <1200000>; dietemp-stop-millidegrees = <95000>; dietemp-resume-millidegrees = <80000>; thermistor-ohms = <10000>; thermistor-beta = <3435>; charging-enable; }; ... };

The devicetree node configures the following parameters:

Parameter

Value

Description

Parameter

Value

Description

compatible

"nordic,npm1300-charger"

Enables the npm1300_charger.c driver and associates it with the device.

term-microvolt

<4200000>

Charge termination voltage in uV. The battery charging mode will switch to constant voltage charge once the battery voltage reaches this value.

term-current-percent

<10>

Termination current, as a percentage of current-microamp. Charge completes when the charge current falls below this value.

current-microamp

<500000>

Charge current in uA.

dischg-limit-microamp

<1340000>

Battery discharge current limit in uA.

vbus-limit-microamp

<1200000>

VBUS current limit in uA.

dietemp-stop-millidegrees

<95000>

Battery charging stops when the nPM1300 chip temperature reaches this threshold (in milli-degrees).

dietemp-resume-millidegrees

<80000>

If stopped, battery charging will resume when the nPM1300 chip temperature drops below this threshold (in milli-degrees).

thermistor-ohms

<10000>

Thermistor nominal resistance type in ohms.

thermistor-beta

<3435>

Beta value of selected thermistor.

charging-enable

 

Enable charging.

The battery parameters are defined for EEMB LP653042 820 mAh battery:

If another battery is used, the parameters should be changed accordingly.

3.2.
Configuring nPM1300 Voltage Regulators

The nPM1300 regulator device is declared in nrf9151som_nrf9151_ns.dts as a child node of the npm1300_pmic device:

npm1300_pmic: pmic@6b { compatible = "nordic,npm1300"; ... npm1300_regulators: regulators { compatible = "nordic,npm1300-regulator"; status = "okay"; /* limits are set to min/max allowed values */ npm1300_buck1: BUCK1 { regulator-min-microvolt = <3000000>; regulator-max-microvolt = <3000000>; }; npm1300_ldsw1: LDO1 { regulator-min-microvolt = <3000000>; regulator-max-microvolt = <3000000>; regulator-initial-mode = <NPM1300_LDSW_MODE_LDSW>; regulator-allowed-modes = <NPM1300_LDSW_MODE_LDSW>; }; }; ... };

The devicetree node configures the following parameters and subnodes:

Parameter

Value

Description

Parameter

Value

Description

compatible

"nordic,npm1300-regulator"

Enables the npm1300_regulator.c driver and associates it with the device.

npm1300_buck1: BUCK1

regulator-min-microvolt

<3000000>

Smallest voltage consumers may set.

regulator-max-microvolt

<3000000>

Largest voltage consumers may set.

npm1300_ldsw1: LDO1

regulator-min-microvolt

<3000000>

Smallest voltage consumers may set.

regulator-max-microvolt

<3000000>

Largest voltage consumers may set.

regulator-initial-mode

<NPM1300_LDSW_MODE_LDSW>

Initial operating mode.

regulator-initial-mode

<NPM1300_LDSW_MODE_LDSW>

List of operating modes that software is allowed to configure for the regulator at run-time.

4.
Controlling nPM1300 PMIC in User Application

4.1.
Using nPM1300 Battery Charger

4.1.1.
nPM1300 Battery Charger C-binding API

The Customized Asset Tracker v2 application implements the following C-binding helper API for nPM1300 battery charger, defined in pmic_charger.* and pmic_soc.* files:

Function

Description

Comments

pmic_charger.*

int pmic_charger_get_voltage(double *voltage, bool do_update);

Get battery voltage from PMIC charger driver.

voltage is a pointer to a variable to store the battery voltage; do_update is a flag signaling the function to fetch new readings from the PMIC.

Returns 0 on success, or a negative error code on failure.

int pmic_charger_get_current(double *current, bool do_update);

Get battery current from PMIC charger driver.

current is a pointer to a variable to store the battery current (Positive value indicates battery charging, negative - discharge); do_update is a flag signaling the function to fetch new readings from the PMIC.

Returns 0 on success, or a negative error code on failure.

int pmic_charger_get_temp(double *temp, bool do_update);

Get battery temperature from PMIC charger driver.

temp is a pointer to a variable to store the battery temperature; do_update is a flag signaling the function to fetch new readings from the PMIC.

Returns 0 on success, or a negative error code on failure.

int pmic_charger_get_status(uint32_t *status, bool do_update);

Read PMIC charger status register.

status is a pointer to a variable to store the status register value; do_update is a flag signaling the function to fetch new readings from the PMIC.

status value can be one of the following:

  • PMIC_CHARGER_STATUS_BATT_DETECTED = 0

  • PMIC_CHARGER_STATUS_CHG_COMPLETED

  • PMIC_CHARGER_STATUS_TRICKLE_CHARGE

  • PMIC_CHARGER_STATUS_CC_CHARGE

  • PMIC_CHARGER_STATUS_CV_CHARGE

  • PMIC_CHARGER_STATUS_RECHARGE

  • PMIC_CHARGER_STATUS_HIGH_TEMP_PAUSE

  • PMIC_CHARGER_STATUS_SUPPLEMENT_MODE

  • PMIC_CHARGER_STATUS_TOTAL

Returns 0 on success, or a negative error code on failure.

int pmic_charger_get_error(uint32_t *error, bool do_update);

Read PMIC charger error register.

error is a pointer to a variable to store the error register value; do_update is a flag signaling the function to fetch new readings from the PMIC.

error value can be one of the following:

  • PMIC_CHARGER_ERROR_NTC_SENSOR = 0

  • PMIC_CHARGER_ERROR_VBAT_SENSOR

  • PMIC_CHARGER_ERROR_VBAT_LOW

  • PMIC_CHARGER_ERROR_TRICKLE

  • PMIC_CHARGER_ERROR_MEAS_TIMEOUT

  • PMIC_CHARGER_ERROR_CHARGE_TIMEOUT

  • PMIC_CHARGER_ERROR_TRICKLE_TIMEOUT

Returns 0 on success, or a negative error code on failure.

int pmic_charger_clear_error(void);

Clear PMIC charger error register.

Returns 0 on success, or a negative error code on failure.

int pmic_charger_is_enabled(bool *charger_enabled);

Check if charging is enabled.

charger_enabled is a pointer to a variable to store the value indicating that the charger is enabled or disabled.

Returns 0 on success, or a negative error code on failure.

pmic_soc.*

int pmic_soc_get(uint8_t *soc, bool do_update);

Calculate battery State of Charge (SoC).

soc is a pointer to a variable to store the battery State of Charge value; do_update is a flag signaling the function to fetch new readings from the PMIC.

Returns 0 on success, or a negative error code on failure.

int pmic_soc_monitor(void);

Monitor battery State of Charge (SoC).

Schedules a system workqueue task that will periodically update the battery State of Charge.

Returns 0 on success, or a negative error code on failure.

void pmic_soc_emulate(int soc);

Emulate battery State of Charge (SoC).

soc Emulated battery SoC in percentage (-1 means stop emulation).

4.1.2.
nPM1300 Battery Charger Threads and Tasks

The Customized Asset Tracker v2 application provides a Zephyr system workqueue task that updates the battery State of Charge with 1 minute period and generates an appropriate event, which is distributed by the Application Event Manager and handled by other modules. Refer to Using nPM1300 Battery Charger and Power Rails | 3.4. PMIC Events for details about PMIC events.

4.1.3.
nPM1300 Battery Charger Shell Commands

The Customized Asset Tracker v2 application provides a set of Zephyr shell commands for nPM1300 battery charger, defined in the pmic_charger.c file:

Command

Parameters

Comments

pmic_charger status

 

Prints out the battery charger parameters to the serial console in the following format:

pmic_charger status Battery charging: <enabled|disabled> Battery voltage: <voltage> V Battery current: <current> mA Battery temp: <temperature> Battery SoC: <SoC> <Charge status> <Errors>

pmic_charger vbus

0 - VBUS disconnected

1 - VBUS connected

Emulate VBUS events.

pmic_charger soc

<percentage> - emulate battery SoC

auto - stop emulation

Emulate battery SoC.

4.2.
Controlling nPM1300 Voltage Regulators

4.2.1.
nPM1300 Voltage Regulators C-binding API

The Customized Asset Tracker v2 application implements the following C-binding helper API for nPM1300 voltage regulator, defined in pmic_regulator.* files:

Function

Description

Comments

void pmic_regulator_deinit(void);

Deinitialize PMIC voltage regulators.

 

int pmic_regulator_enable(pmic_regulator_id_t regulator_id);

Enable a specific regulator.

regulator_id is a PMIC regulator ID, which is either PMIC_REGULATOR_BUCK1 or PMIC_REGULATOR_LDSW1.

Returns zero on success, otherwise a negative error code is returned.

void pmic_regulator_disable(pmic_regulator_id_t regulator_id);

Disable a specific regulator.

regulator_id is a PMIC regulator ID, which is either PMIC_REGULATOR_BUCK1 or PMIC_REGULATOR_LDSW1.

bool pmic_regulator_is_enabled(pmic_regulator_id_t regulator_id);

Check if regulator is enabled.

regulator_id is a PMIC regulator ID, which is either PMIC_REGULATOR_BUCK1 or PMIC_REGULATOR_LDSW1.

Returns true if regulator is enabled, false otherwise..

4.2.2.
nPM1300 Voltage Regulators Shell Commands

The Customized Asset Tracker v2 application provides a set of Zephyr shell commands for nPM1300 voltage regulator, defined in the pmic_regulator.c file:

Command

Parameters

Comments

pmic_regulator status

 

Prints out the BUCK1 and LDSW1 parameters to the serial console in the following format:

uart:~$ pmic_regulator status Regulator: BUCK1 status: <enabled|disabled>, voltage: <voltage> V Regulator: LDSW1 status: <enabled|disabled>, voltage: <voltage> V

pmic_charger enable

BUCK1 or LDSW1

Enable a specific regulator.

pmic_charger disable

BUCK1 or LDSW1

Disable a specific regulator.

4.3.
Enabling and Handling PMIC Interrupts

4.3.1.
nPM1300 Interrupts C-binding API

The Customized Asset Tracker v2 application implements the following C-binding helper API for nPM1300 interrupts, defined in pmic_irq.* files:

Function

Description

Comments

int pmic_irq_enable(void);

Enable PMIC interrupts and configure IRQ handler.

Zero on success, otherwise a negative error code is returned.

int pmic_irq_disable(void);

Disable PMIC interrupts and remove IRQ handler.

void pmic_irq_send_event(enum pmic_module_event_type type);

Send PMIC event.

type Event type.

Refer to Using nPM1300 Battery Charger and Power Rails | 3.4. PMIC Events for details about PMIC events.

4.3.2.
nPM1300 Interrupt Events

The Customized Asset Tracker v2 application configures the following PMIC interrupts through the mfd_npm1300.c driver:

Interrupt

Description

NPM1300_EVENT_CHG_COMPLETED

Charging completed.

NPM1300_EVENT_CHG_ERROR

Charging error.

NPM1300_EVENT_BATTERY_DETECTED

The battery is connected to the SOM-NRF9151 baseboard and VBAT voltage is detected.

NPM1300_EVENT_BATTERY_REMOVED

The battery is diconnected from the SOM-NRF9151 baseboard .

NPM1300_EVENT_BATTERY_RECHARGE

The battery voltage dropped below 95% of the charge termination voltage while the device is connected to a power source with a USB-C cable. Recharge is needed.

NPM1300_EVENT_VBUS_DETECTED

The device has been connected to a power source with a USB-C cable and VBUS voltage is detected.

NPM1300_EVENT_VBUS_REMOVED

The device has been disconnected from a power source.

4.3.3.
nPM1300 Interrupts Configuration and Handling

The Customized Asset Tracker v2 application configures and handles PMIC interrupts the following way:

  • PMIC interrupts are configured at Zephyr boot by calling pmic_irq_enable() in setup() function, defined in util_module.c.

  • pmic_irq.c file defines the PMIC interrupt handler, which generates an appropriate PMIC event when the interrupt is triggered. Refer to for details about PMIC events.