zephyr/samples/boards/nrf/battery
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

- it's inconsistent with the rest of the DT_NODE_HAS_FOO names
- DT_NODE_HAS_FOO_BAR_BAZ(node) was agreed upon as a shorthand
  for macros which are equivalent to
  DT_NODE_HAS_FOO(node) && DT_NODE_HAS_BAR(node) &&
- DT_NODE_HAS_BAZ(node), and DT_HAS_NODE_STATUS_OKAY is an odd duck
- DT_NODE_HAS_STATUS(..., okay) was viewed as more readable anyway
- it is seen as a somewhat aesthetically challenged name

Replace all users with DT_NODE_HAS_STATUS(..., okay), which is
semantically equivalent.

This is mostly done with sed, but a few remaining cases were done by
hand, along with whitespace, docs, and comment changes. These special
cases include the Nordic SOC static assert files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00
..
src devicetree: remove DT_HAS_NODE_STATUS_OKAY 2020-05-13 18:24:42 +02:00
CMakeLists.txt cmake: use find_package to locate Zephyr 2020-03-27 16:23:46 +01:00
README.rst samples: nrf: battery: add documentation 2020-04-22 17:46:07 +02:00
prj.conf
sample.yaml boards: nrf52_pca20020: Rename to thingy52_nrf52832 2020-04-06 13:09:07 +02:00

README.rst

.. _boards_nrf_battery:

Battery Voltage Measurement
###########################

Overview
********

This sample demonstrates using Nordic configurations of the Zephyr ADC
infrastructure to measure the voltage of the device power supply.  Two
power supply configurations are supported:

* If the board devicetree has a ``/vbatt`` node with compatible
  ``voltage-divider`` then the voltage is measured using that divider.
* Otherwise the power source is assumed to be directly connected to the
  digital voltage signal, and the internal source for ``Vdd`` is
  selected.

An example of a devicetree node describing a voltage divider for battery
monitoring is:

.. code-block:: none

   / {
   	vbatt {
   		compatible = "voltage-divider";
   		io-channels = <&adc 4>;
   		output-ohms = <180000>;
   		full-ohms = <(1500000 + 180000)>;
   		power-gpios = <&sx1509b 4 0>;
   	};
   };

Note that in many cases where there is no voltage divider the digital
voltage will be fed from a regulator that provides a fixed voltage
regardless of source voltage, rather than by the source directly.  In
configuration involving a regulator the measured voltage will be
constant.

The sample provides discharge curves that map from a measured voltage to
an estimate of remaining capacity.  The correct curve depends on the
battery source: a standard LiPo cell requires a curve that is different
from a standard alkaline battery.  Curves can be measured, or estimated
using the data sheet for the battery.

Application Details
===================

The application initializes battery measurement on startup, then loops
displaying the battery status every five seconds.

Requirements
************

A Nordic-based board, optionally with a voltage divider specified in its
devicetree configuration as noted above.

Building and Running
********************

The code can be found in :zephyr_file:`samples/boards/nrf/battery`.

.. zephyr-app-commands::
   :zephyr-app: samples/boards/nrf/battery
   :board: nrf52_pca20020
   :goals: build flash
   :compact:


Sample Output
=============

.. code-block:: console

   *** Booting Zephyr OS build zephyr-v2.2.0-318-g84219bdc1ac2  ***
   [0:00:00.016]: 4078 mV; 10000 pptt
   [0:00:04.999]: 4078 mV; 10000 pptt
   [0:00:09.970]: 4078 mV; 10000 pptt
   [0:00:14.939]: 4069 mV; 10000 pptt
   [0:00:19.910]: 4078 mV; 10000 pptt
   [0:00:24.880]: 4069 mV; 10000 pptt