ESP32 DAC


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM