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

..--

boards/11-Mar-2024-2,0451,752

src/11-Mar-2024-9970

CMakeLists.txtD11-Mar-2024186 95

README.rstD11-Mar-20242 KiB6243

prj.confD11-Mar-202413 21

sample.yamlD11-Mar-2024790 3635

README.rst

1.. _adc-sample:
2
3Analog-to-Digital Converter (ADC)
4#################################
5
6Overview
7********
8
9This sample demonstrates how to use the ADC driver API.
10
11Depending on the target board, it reads ADC samples from one or more channels
12and prints the readings on the console. If voltage of the used reference can
13be obtained, the raw readings are converted to millivolts.
14
15The pins of the ADC channels are board-specific. Please refer to the board
16or MCU datasheet for further details.
17
18Building and Running
19********************
20
21The ADC peripheral and pinmux is configured in the board's ``.dts`` file. Make
22sure that the ADC is enabled (``status = "okay";``).
23
24In addition to that, this sample requires an ADC channel specified in the
25``io-channels`` property of the ``zephyr,user`` node. This is usually done with
26a devicetree overlay. The example overlay in the ``boards`` subdirectory for
27the ``nucleo_l073rz`` board can be easily adjusted for other boards.
28
29Configuration of channels (settings like gain, reference, or acquisition time)
30also needs to be specified in devicetree, in ADC controller child nodes. Also
31the ADC resolution and oversampling setting (if used) need to be specified
32there. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay
33<samples/drivers/adc/boards/nrf52840dk_nrf52840.overlay>` for an example of
34such setup.
35
36Building and Running for ST Nucleo L073RZ
37=========================================
38
39The sample can be built and executed for the
40:ref:`nucleo_l073rz_board` as follows:
41
42.. zephyr-app-commands::
43   :zephyr-app: samples/drivers/adc
44   :board: nucleo_l073rz
45   :goals: build flash
46   :compact:
47
48To build for another board, change "nucleo_l073rz" above to that board's name
49and provide a corresponding devicetree overlay.
50
51Sample output
52=============
53
54You should get a similar output as below, repeated every second:
55
56.. code-block:: console
57
58   ADC reading:
59   - ADC_0, channel 7: 36 = 65mV
60
61.. note:: If the ADC is not supported, the output will be an error message.
62