• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

src/11-Mar-2024-370236

CMakeLists.txtD11-Mar-2024225 106

README.rstD11-Mar-20242.8 KiB9370

prj.confD11-Mar-202413 21

sample.yamlD11-Mar-2024234 1211

README.rst

1.. _boards_nrf_battery:
2
3Battery Voltage Measurement
4###########################
5
6Overview
7********
8
9This sample demonstrates using Nordic configurations of the Zephyr ADC
10infrastructure to measure the voltage of the device power supply.  Two
11power supply configurations are supported:
12
13* If the board devicetree has a ``/vbatt`` node with compatible
14  ``voltage-divider`` then the voltage is measured using that divider. An
15  example of a devicetree node describing a voltage divider for battery
16  monitoring is:
17
18   .. code-block:: devicetree
19
20      / {
21         vbatt {
22            compatible = "voltage-divider";
23            io-channels = <&adc 4>;
24            output-ohms = <180000>;
25            full-ohms = <(1500000 + 180000)>;
26            power-gpios = <&sx1509b 4 0>;
27         };
28      };
29
30* If the board does not have a voltage divider and so no ``/vbatt`` node
31  present, the ADC configuration (device and channel) needs to be provided via
32  the ``zephyr,user`` node. In this case the power source is assumed to be
33  directly connected to the digital voltage signal, and the internal source for
34  ``Vdd`` is selected. An example of a Devicetree configuration for this case is
35  shown below:
36
37   .. code-block :: devicetree
38
39      / {
40         zephyr,user {
41            io-channels = <&adc 4>;
42         };
43      };
44
45Note that in many cases where there is no voltage divider the digital
46voltage will be fed from a regulator that provides a fixed voltage
47regardless of source voltage, rather than by the source directly. In
48configuration involving a regulator the measured voltage will be
49constant.
50
51The sample provides discharge curves that map from a measured voltage to
52an estimate of remaining capacity.  The correct curve depends on the
53battery source: a standard LiPo cell requires a curve that is different
54from a standard alkaline battery.  Curves can be measured, or estimated
55using the data sheet for the battery.
56
57Application Details
58===================
59
60The application initializes battery measurement on startup, then loops
61displaying the battery status every five seconds.
62
63Requirements
64************
65
66A Nordic-based board, optionally with a voltage divider specified in its
67devicetree configuration as noted above.
68
69Building and Running
70********************
71
72The code can be found in :zephyr_file:`samples/boards/nrf/battery`.
73
74.. zephyr-app-commands::
75   :zephyr-app: samples/boards/nrf/battery
76   :board: thingy52_nrf52832
77   :goals: build flash
78   :compact:
79
80
81Sample Output
82=============
83
84.. code-block:: console
85
86   *** Booting Zephyr OS build zephyr-v2.2.0-318-g84219bdc1ac2  ***
87   [0:00:00.016]: 4078 mV; 10000 pptt
88   [0:00:04.999]: 4078 mV; 10000 pptt
89   [0:00:09.970]: 4078 mV; 10000 pptt
90   [0:00:14.939]: 4069 mV; 10000 pptt
91   [0:00:19.910]: 4078 mV; 10000 pptt
92   [0:00:24.880]: 4069 mV; 10000 pptt
93