adc.rst 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Analog to Digital Converter
  2. ===========================
  3. Overview
  4. --------
  5. ESP32 integrates two 12-bit SAR ("Successive Approximation Register") ADCs (Analog to Digital Converters) and supports measurements on 18 channels (analog enabled pins). Some of these pins can be used to build a programmable gain amplifier which is used for the measurement of small
  6. analog signals.
  7. The ADC driver API currently only supports ADC1 (9 channels, attached to GPIOs 32-39).
  8. Taking an ADC reading involves configuring the ADC with the desired precision and attentuation settings, and then calling adc1_get_voltage() to read the channel.
  9. It is also possible to read the internal hall effect sensor via ADC1.
  10. Application Example
  11. -------------------
  12. Reading voltage on ADC1 channel 0 (GPIO 36)::
  13. #include <driver/adc.h>
  14. ...
  15. adc1_config_width(ADC_WIDTH_12Bit);
  16. adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_0db);
  17. int val = adc1_get_voltage(ADC1_CHANNEL_0);
  18. Reading the internal hall effect sensor::
  19. #include <driver/adc.h>
  20. ...
  21. adc1_config_width(ADC_WIDTH_12Bit);
  22. int val = hall_sensor_read();
  23. The value read in both these examples is 12 bits wide (range 0-4095).
  24. API Reference
  25. -------------
  26. .. include:: /_build/inc/adc.inc