2021-08-27 15:09:35 +08:00
Digital To Analog Converter (DAC)
=================================
2017-02-16 13:59:50 +11:00
2019-12-13 11:49:10 +08:00
{IDF_TARGET_DAC_CH_1: default = "GPIO25", esp32 = "GPIO25", esp32s2 = "GPIO17"}
{IDF_TARGET_DAC_CH_2: default = "GPIO26", esp32 = "GPIO26", esp32s2 = "GPIO18"}
2017-02-16 13:59:50 +11:00
Overview
--------
2019-12-13 11:49:10 +08:00
{IDF_TARGET_NAME} has two 8-bit DAC (digital to analog converter) channels, connected to {IDF_TARGET_DAC_CH_1} (Channel 1) and {IDF_TARGET_DAC_CH_2} (Channel 2).
2019-12-09 11:01:09 +08:00
2017-02-16 13:59:50 +11:00
The DAC driver allows these channels to be set to arbitrary voltages.
2020-12-30 09:24:10 +08:00
.. only :: esp32
The DAC channels can also be driven with DMA-style written sample data by the digital controller, via the :doc: `I2S driver <i2s>` when using the "built-in DAC mode".
.. only :: esp32s2
2021-07-19 19:48:15 +08:00
The DAC channels can also be driven with DMA-style written sample data by the digital controller, however the driver does not supported this yet.
2020-12-30 09:24:10 +08:00
2017-02-16 13:59:50 +11:00
2022-06-22 16:29:35 +08:00
For other analog output options, see the :doc: `Sigma-delta Modulation module <sdm>` and the :doc: `LED Control module <ledc>` . Both these modules produce high frequency PDM/PWM output, which can be hardware low-pass filtered in order to generate a lower frequency analog output.
2017-02-16 13:59:50 +11:00
Application Example
-------------------
2022-04-25 13:45:37 +08:00
Setting DAC channel 1 ({IDF_TARGET_DAC_CH_1}) voltage to approx 0.78 of VDD_A voltage (VDD * 200 / 255). For VDD_A 3.3V, this is 2.59V.
2017-02-16 13:59:50 +11:00
2022-04-25 13:45:37 +08:00
.. code :: c
2017-02-16 13:59:50 +11:00
2022-04-25 13:45:37 +08:00
#include <driver/dac.h>
...
dac_output_enable(DAC_CHANNEL_1);
dac_output_voltage(DAC_CHANNEL_1, 200);
2017-02-16 13:59:50 +11:00
API Reference
-------------
2019-11-13 11:46:16 +08:00
.. include-build-file :: inc/dac.inc
2020-04-08 21:56:14 +08:00
.. include-build-file :: inc/dac_common.inc
2017-02-16 13:59:50 +11:00
2017-08-29 15:52:04 +08:00
GPIO Lookup Macros
^^^^^^^^^^^^^^^^^^
Some useful macros can be used to specified the GPIO number of a DAC channel, or vice versa.
e.g.
2019-12-13 11:49:10 +08:00
1. `` DAC_CHANNEL_1_GPIO_NUM `` is the GPIO number of channel 1 ({IDF_TARGET_DAC_CH_1});
2. `` DAC_{IDF_TARGET_DAC_CH_2}_CHANNEL `` is the channel number of GPIO 26 (channel 2).
2017-08-29 15:52:04 +08:00
2019-11-13 11:46:16 +08:00
.. include-build-file :: inc/dac_channel.inc
2020-04-28 10:52:14 +08:00
.. include-build-file :: inc/dac_types.inc