ESP32-S3-DEVKITC ADC引脚行为不稳定
我正在使用一些ESP32-S3-DEVKITC-1-N8板,并具有一个简单的程序,该程序使用两个SAR ADC(下面的程序)将模拟数据读取到串行显示器。我遇到一个问题,当ADC频道连接到没有连接时,ADC频道读取50mV至930mv之间的值。就像在没有外部电路中一样,销子应读取0伏。我认为这可能是董事会的问题,所以我尝试了其他一些问题,并得到了相同的结果。我唯一的想法是,这是我的程序的问题。我使用ESP -IDF 4.4 CMD在VSCODE中编码以下命令:
IDF.PY SET -TARGET ESP32S3
IDF.PY -P COM4 -B 480600 FLASH MONORY
#include <stdio.h>
#include <driver/adc.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_adc_cal.h"
void app_main(void)
{
printf("Hello world!\n");
/* ADC Configuration and Callibration Documentation: |
------------------------------------------------------
VRef of the ESP32-S3 is 1100 mV |
Right Channel: GPIO 4 ADC1 Channel 3 |
Left Channel: GPIO 11 ADC2 Channel 0 |
ADC Attenuation Options: |
ADC_ATTEN_DB_0 : 0 - 950 mV |
ADC_ATTEN_DB_2_5 : 0 - 1250 mV |
ADC_ATTEN_DB_6 : 0 - 1750 mV |
ADC_ATTEN_DB_11 : 0 - 3100 mV |
ADC Accuracy Options: |
ADC_WIDTH_9Bit |
ADC_WIDTH_10Bit |
ADC_WIDTH_11Bit |
ADC_WIDTH_12Bit |
ADC_WIDTH_BIT_DEFAULT (Max Bit Width) |
-----------------------------------------------------*/
// Configure desired precision and attenuation for ADC pins
adc1_config_width(ADC_WIDTH_BIT_DEFAULT);
adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_DB_0);
adc2_config_channel_atten(ADC2_CHANNEL_3,ADC_ATTEN_DB_0);
// Create ADC channel characteristics structs for use in calibration functions
esp_adc_cal_characteristics_t adc1_chars;
esp_adc_cal_characteristics_t adc2_chars;
esp_adc_cal_characterize(ADC_UNIT_1,ADC_ATTEN_DB_0,ADC_WIDTH_BIT_DEFAULT,1100,&adc1_chars);
esp_adc_cal_characterize(ADC_UNIT_2,ADC_ATTEN_DB_0,ADC_WIDTH_BIT_DEFAULT,1100,&adc2_chars);
int val1;
int val2;
int counter = 0;
while(true){
val1 = adc1_get_raw(ADC1_CHANNEL_0);
adc2_get_raw(ADC2_CHANNEL_3,ADC_WIDTH_BIT_DEFAULT,&val2);
// printf("%d, %d\n",val1,val2);
int adc1_voltage = esp_adc_cal_raw_to_voltage(val1,&adc1_chars);
int adc2_voltage = esp_adc_cal_raw_to_voltage(val2,&adc2_chars);
printf("\n%d, %d",adc1_voltage,adc2_voltage);
vTaskDelay(10);
counter++;
}
}
I am working with a few ESP32-S3-DevKitC-1-N8 boards and have a simple program that reads analog data to the serial monitor using the two SAR ADCs (Program below). I am having a problem where the ADC channels are reading values between 50mV and 930mV when connected to nothing. As in no external circuit so the pins should be reading 0 volts. I thought it might be an issue with the board so I tried it with a few others and got the same outcome. My only other thought is that it is a problem with my program. I am coding in VSCode using the ESP-IDF 4.4 CMD to flash my code using the following commands:
idf.py set-target esp32s3
idf.py -p COM4 -b 480600 flash monitor
#include <stdio.h>
#include <driver/adc.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_adc_cal.h"
void app_main(void)
{
printf("Hello world!\n");
/* ADC Configuration and Callibration Documentation: |
------------------------------------------------------
VRef of the ESP32-S3 is 1100 mV |
Right Channel: GPIO 4 ADC1 Channel 3 |
Left Channel: GPIO 11 ADC2 Channel 0 |
ADC Attenuation Options: |
ADC_ATTEN_DB_0 : 0 - 950 mV |
ADC_ATTEN_DB_2_5 : 0 - 1250 mV |
ADC_ATTEN_DB_6 : 0 - 1750 mV |
ADC_ATTEN_DB_11 : 0 - 3100 mV |
ADC Accuracy Options: |
ADC_WIDTH_9Bit |
ADC_WIDTH_10Bit |
ADC_WIDTH_11Bit |
ADC_WIDTH_12Bit |
ADC_WIDTH_BIT_DEFAULT (Max Bit Width) |
-----------------------------------------------------*/
// Configure desired precision and attenuation for ADC pins
adc1_config_width(ADC_WIDTH_BIT_DEFAULT);
adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_DB_0);
adc2_config_channel_atten(ADC2_CHANNEL_3,ADC_ATTEN_DB_0);
// Create ADC channel characteristics structs for use in calibration functions
esp_adc_cal_characteristics_t adc1_chars;
esp_adc_cal_characteristics_t adc2_chars;
esp_adc_cal_characterize(ADC_UNIT_1,ADC_ATTEN_DB_0,ADC_WIDTH_BIT_DEFAULT,1100,&adc1_chars);
esp_adc_cal_characterize(ADC_UNIT_2,ADC_ATTEN_DB_0,ADC_WIDTH_BIT_DEFAULT,1100,&adc2_chars);
int val1;
int val2;
int counter = 0;
while(true){
val1 = adc1_get_raw(ADC1_CHANNEL_0);
adc2_get_raw(ADC2_CHANNEL_3,ADC_WIDTH_BIT_DEFAULT,&val2);
// printf("%d, %d\n",val1,val2);
int adc1_voltage = esp_adc_cal_raw_to_voltage(val1,&adc1_chars);
int adc2_voltage = esp_adc_cal_raw_to_voltage(val2,&adc2_chars);
printf("\n%d, %d",adc1_voltage,adc2_voltage);
vTaskDelay(10);
counter++;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前,您的ADC引脚的作用像天线。这是预期的行为,因为您没有与引脚相关的强信号。您正在收到噪音。
Currently, your ADC pins are acting like antennae. This is expected behavior, as you don't have strong signal connected to pins; you are receiving just noise.
未连接的引脚没有明确的电压。这是高阻抗,因此任何噪声都可以改变该引脚上的电压。话虽如此,您的阅读似乎很合理。只需将模拟输出连接到您的ADC输入,就可以了。如果您想校准或仅测试ADC,请连接一个电位器,例如此答案:

然后,您可以在ESP32中进行读数,并将其与校准的万用表进行比较。
请记住使用ADC_ATTEN_DB_0,您只能测量高达950mv。因此,也许将当前的限制电阻从VCC添加到电位器。如果使用ADC_ATTEN_DB_11,则可以测量高达3.1V。但是,仍然需要额外的电阻以确保其不会超过电压或限制电流。
另外,ESP32的模拟输入不是很好。因此,您需要校准它。有硬件和软件选项可以这样做。查看他们的文档:
ESP32-S3对数字转换器(ADC)类似物
The unconnected pin has no definitive voltage. It's high impedance, so any noise can change the voltage on this pin. This being said, your reading seems reasonable. Just connect the analogue output to your ADC input, and it should be fine. If you want to calibrate or just test the ADC, connect a potentiometer like this answer:

Then, you can have a reading in the ESP32 and compare it with a calibrated multimeter.
Bear in mind with ADC_ATTEN_DB_0, you can only measure up to 950mV. So, maybe add a current limiting resistor from Vcc to the potentiometer. If you use the ADC_ATTEN_DB_11, you can measure up to 3.1V. But still need that extra resistor to make sure it does not exceed the voltage or limit the current.
Also, the analogue input of the ESP32 is not very good. So you will need to calibrate it. There are hardware and software options to do so. Have a look through their documentation:
ESP32-S3 Analog to Digital Converter (ADC)