dac.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Digital To Analog Converter
  2. ===========================
  3. {IDF_TARGET_DAC_CH_1: default = "GPIO25", esp32 = "GPIO25", esp32s2 = "GPIO17"}
  4. {IDF_TARGET_DAC_CH_2: default = "GPIO26", esp32 = "GPIO26", esp32s2 = "GPIO18"}
  5. Overview
  6. --------
  7. {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).
  8. The DAC driver allows these channels to be set to arbitrary voltages.
  9. .. only:: esp32
  10. 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".
  11. .. only:: esp32s2
  12. 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.
  13. For other analog output options, see the :doc:`Sigma-delta Modulation module <sigmadelta>` and the :doc:`LED Control module <ledc>`. Both these modules produce high frequency PWM output, which can be hardware low-pass filtered in order to generate a lower frequency analog output.
  14. Application Example
  15. -------------------
  16. 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::
  17. #include <driver/dac.h>
  18. ...
  19. dac_output_enable(DAC_CHANNEL_1);
  20. dac_output_voltage(DAC_CHANNEL_1, 200);
  21. API Reference
  22. -------------
  23. .. include-build-file:: inc/dac.inc
  24. .. include-build-file:: inc/dac_common.inc
  25. GPIO Lookup Macros
  26. ^^^^^^^^^^^^^^^^^^
  27. Some useful macros can be used to specified the GPIO number of a DAC channel, or vice versa.
  28. e.g.
  29. 1. ``DAC_CHANNEL_1_GPIO_NUM`` is the GPIO number of channel 1 ({IDF_TARGET_DAC_CH_1});
  30. 2. ``DAC_{IDF_TARGET_DAC_CH_2}_CHANNEL`` is the channel number of GPIO 26 (channel 2).
  31. .. include-build-file:: inc/dac_channel.inc
  32. .. include-build-file:: inc/dac_types.inc