ESP32 DAC

时间:2023-03-08 21:48:55

ESP32有两个DAC通道,通道1链接GPIO25, 通道2链接GPIO26;

当DAC设置为 “built-in DAC mode”的时候,I2S可以通过DAC发送数据;

使用示例:

dac_output_enable(DAC_CHANNEL_1);
dac_output_voltage(DAC_CHANNEL_1, 200);

dac一共有8位,将3.3V电压按照255均分之后,就是dac的精度的最小单位;

API函数如下:

esp_err_tdac_pad_get_io_num(dac_channel_tchannelgpio_num_t *gpio_num)

获取指定的DAC通道的GPIO口;

esp_err_tdac_output_voltage(dac_channel_tchannel, uint8_t dac_value)

设置DAC的输出电压;

esp_err_tdac_output_enable(dac_channel_tchannel)

DAC的输出使能;

esp_err_tdac_output_disable(dac_channel_tchannel)

DAC的输出失能;

esp_err_tdac_i2s_enable()

DAC 的I2S使能;

esp_err_tdac_i2s_disable()

DAC的I2S失能;

下面是关于量程的理解:

esp_err_tadc1_config_channel_atten(adc1_channel_tchanneladc_atten_tatten)

该函数设定制定通道的量程范围atten;

默认量程是1.1伏特,如果想测量更高的范围的话,更改atten来更改测量量程,最高测量3.3伏特;

Note
在adc1_get_raw()读值之前,确定atten的函数必须执行完毕;
Note
This function can be called multiple times to configure multiple ADC channels simultaneously. adc1_get_raw() can then be called for any configured channel.
如果想更改量程,这个函数可以多次被调用来更改量程范围;

When VDD_A is 3.3V:

  0dB attenuaton (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V

  • 2.5dB attenuation (ADC_ATTEN_DB_2_5) gives full-scale voltage 1.5V
  • 6dB attenuation (ADC_ATTEN_DB_6) gives full-scale voltage 2.2V
  • 11dB attenuation (ADC_ATTEN_DB_11) gives full-scale voltage 3.9V (see note below)

Due to ADC characteristics, most accurate results are obtained within the following approximate voltage ranges:

Note
最大电压对应着最大数值, (depending on ADC1 configured bit width, this value is: 4095 for 12-bits, 2047 for 11-bits, 1023 for 10-bits, 511 for 9 bits.)
Note
At 11dB attenuation the maximum voltage is limited by VDD_A, not the full scale voltage.

  0dB attenuaton (ADC_ATTEN_DB_0) between 100 and 950mV

  • 2.5dB attenuation (ADC_ATTEN_DB_2_5) between 100 and 1250mV
  • 6dB attenuation (ADC_ATTEN_DB_6) between 150 to 1750mV
  • 11dB attenuation (ADC_ATTEN_DB_11) between 150 to 2450mV

For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges.

Return

  • ESP_OK success
  • ESP_ERR_INVALID_ARG Parameter error
Parameters
  • channel: ADC1 channel to configure
  • atten: Attenuation level