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

..--

boards/04-Jan-2025-769635

src/04-Jan-2025-11073

CMakeLists.txtD04-Jan-2025186 95

KconfigD04-Jan-2025307 139

README.rstD04-Jan-20252.1 KiB6750

prj.confD04-Jan-202513 21

sample.yamlD04-Jan-2025655 2625

README.rst

1.. zephyr:code-sample:: adc_sequence
2   :name: Analog-to-Digital Converter (ADC) sequence sample
3   :relevant-api: adc_interface
4
5   Read analog inputs from ADC channels, using a sequence.
6
7Overview
8********
9
10This sample demonstrates how to use the :ref:`ADC driver API <adc_api>` using sequences.
11
12Depending on the target board, it reads ADC samples from two channels
13and prints the readings on the console, based on the sequence specifications.
14Notice how for the whole sequence reading, only one call to the :c:func:`adc_read` API is made.
15If voltage of the used reference can be obtained, the raw readings are converted to millivolts.
16
17This example constructs an adc device and setups its channels, according to the
18given devicetree configuration.
19
20Building and Running
21********************
22
23Make sure that the ADC is enabled (``status = "okay";``) and has each channel as a
24child node, with your desired settings like gain, reference, or acquisition time and
25oversampling setting (if used). It is also needed to provide an alias ``adc0`` for the
26desired adc. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay
27<samples/drivers/adc/adc_dt/boards/nrf52840dk_nrf52840.overlay>` for an example of
28such setup.
29
30Building and Running for Nordic nRF52840
31========================================
32
33The sample can be built and executed for the
34:ref:`nrf52840dk_nrf52840` as follows:
35
36.. zephyr-app-commands::
37   :zephyr-app: samples/drivers/adc/adc_sequence
38   :board: nrf52840dk/nrf52840
39   :goals: build flash
40   :compact:
41
42To build for another board, change "nrf52840dk/nrf52840" above to that board's name
43and provide a corresponding devicetree overlay.
44
45Sample output
46=============
47
48You should get a similar output as below, repeated every second:
49
50.. code-block:: console
51
52   ADC sequence reading [1]:
53   - ADC_0, channel 0, 5 sequence samples:
54   - - 36 = 65mV
55   - - 35 = 63mV
56   - - 36 = 65mV
57   - - 35 = 63mV
58   - - 36 = 65mV
59   - ADC_0, channel 1, 5 sequence samples:
60   - - 0 = 0mV
61   - - 0 = 0mV
62   - - 1 = 1mV
63   - - 0 = 0mV
64   - - 1 = 1mV
65
66.. note:: If the ADC is not supported, the output will be an error message.
67