zephyr/samples/drivers/adc/adc_sequence
Pierrick Curt 051a2b6cd0 samples: drivers: adc: example to use AD4114 on stm32f3_disco
This examples shows how to use the AD4114 ADC on a
stm32f3_disco board.
As the AD4114 is a 24bits ADC resolution we need to be able
to pass 32bits buffer to get the samples.
CONFIG_SEQUENCE_RESOLUTION is set to 12 instead of 24, and the
gain zephyr,vref-mv is adapted to avoid overflows using the
exisiting adc_raw_to_millivolts function.

Signed-off-by: Pierrick Curt <pierrickcurt@gmail.com>
2025-01-15 19:04:20 +01:00
..
boards samples: drivers: adc: example to use AD4114 on stm32f3_disco 2025-01-15 19:04:20 +01:00
src samples: drivers: adc: example to use AD4114 on stm32f3_disco 2025-01-15 19:04:20 +01:00
CMakeLists.txt
Kconfig samples: drivers: adc: example to use AD4114 on stm32f3_disco 2025-01-15 19:04:20 +01:00
prj.conf
README.rst
sample.yaml samples: drivers: adc: example to use AD4114 on stm32f3_disco 2025-01-15 19:04:20 +01:00

.. zephyr:code-sample:: adc_sequence
   :name: Analog-to-Digital Converter (ADC) sequence sample
   :relevant-api: adc_interface

   Read analog inputs from ADC channels, using a sequence.

Overview
********

This sample demonstrates how to use the :ref:`ADC driver API <adc_api>` using sequences.

Depending on the target board, it reads ADC samples from two channels
and prints the readings on the console, based on the sequence specifications.
Notice how for the whole sequence reading, only one call to the :c:func:`adc_read` API is made.
If voltage of the used reference can be obtained, the raw readings are converted to millivolts.

This example constructs an adc device and setups its channels, according to the
given devicetree configuration.

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

Make sure that the ADC is enabled (``status = "okay";``) and has each channel as a
child node, with your desired settings like gain, reference, or acquisition time and
oversampling setting (if used). It is also needed to provide an alias ``adc0`` for the
desired adc. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay
<samples/drivers/adc/adc_dt/boards/nrf52840dk_nrf52840.overlay>` for an example of
such setup.

Building and Running for Nordic nRF52840
========================================

The sample can be built and executed for the
:ref:`nrf52840dk_nrf52840` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/adc/adc_sequence
   :board: nrf52840dk/nrf52840
   :goals: build flash
   :compact:

To build for another board, change "nrf52840dk/nrf52840" above to that board's name
and provide a corresponding devicetree overlay.

Sample output
=============

You should get a similar output as below, repeated every second:

.. code-block:: console

   ADC sequence reading [1]:
   - ADC_0, channel 0, 5 sequence samples:
   - - 36 = 65mV
   - - 35 = 63mV
   - - 36 = 65mV
   - - 35 = 63mV
   - - 36 = 65mV
   - ADC_0, channel 1, 5 sequence samples:
   - - 0 = 0mV
   - - 0 = 0mV
   - - 1 = 1mV
   - - 0 = 0mV
   - - 1 = 1mV

.. note:: If the ADC is not supported, the output will be an error message.