Some problems encountered when using ESP32S3 ADC1
Posted: Tue Sep 17, 2024 2:34 pm
When using ADC1:
① When I configure reading the raw data of ADC_CHANNEL_3, ADC_CHANNEL_4, ADC_CHANNEL_5, ADC_CHANNEL_6, the readings are normal;
② When I configure reading the raw data of ADC_CHANNEL_2, ADC_CHANNEL_7, ADC_CHANNEL_8, ADC_CHANNEL_9, there is an initial value in the first ADC_CHANNEL of the configured channel array. If I input an analog signal on this channel's pin, the value of the analog signal will be added to this initial value;
③ When I configure all eight ADC channels at the same time, the same thing happens. There is an initial value in the first ADC_CHANNEL of the channel array. If I input an analog signal on this channel's pin, the value of the analog signal will be added to this initial value;
④ Additionally, I don't know why, in my tests, ADC_CHANNEL_8 and ADC_CHANNEL_9 cannot read the analog signal I input. I don't know if these two channels can be directly used as AD resources. The official documentation does not mention anything special.
These are my current questions. Please give reasonable suggestions. Thank you very much🙏
Below is my code.
① When I configure reading the raw data of ADC_CHANNEL_3, ADC_CHANNEL_4, ADC_CHANNEL_5, ADC_CHANNEL_6, the readings are normal;
② When I configure reading the raw data of ADC_CHANNEL_2, ADC_CHANNEL_7, ADC_CHANNEL_8, ADC_CHANNEL_9, there is an initial value in the first ADC_CHANNEL of the configured channel array. If I input an analog signal on this channel's pin, the value of the analog signal will be added to this initial value;
③ When I configure all eight ADC channels at the same time, the same thing happens. There is an initial value in the first ADC_CHANNEL of the channel array. If I input an analog signal on this channel's pin, the value of the analog signal will be added to this initial value;
④ Additionally, I don't know why, in my tests, ADC_CHANNEL_8 and ADC_CHANNEL_9 cannot read the analog signal I input. I don't know if these two channels can be directly used as AD resources. The official documentation does not mention anything special.
These are my current questions. Please give reasonable suggestions. Thank you very much🙏
Below is my code.
Code: Select all
void MacADC_Process(void *arg)
{
esp_err_t ret;
uint32_t ret_num = 0;
int FF = 0;
uint8_t result[EXAMPLE_READ_LEN] = {0};
uint8_t channel_num = sizeof(channel) / sizeof(adc_channel_t);
memset(result, 0xcc, EXAMPLE_READ_LEN);
s_task_handle = xTaskGetCurrentTaskHandle();
adc_continuous_handle_t handle = NULL;
continuous_adc_init(channel, sizeof(channel) / sizeof(adc_channel_t), &handle);
adc_continuous_evt_cbs_t cbs = {
.on_conv_done = s_conv_done_cb,
};
ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(handle, &cbs, NULL));
adc_cali_handle_t adc1_cali_handle = NULL;
bool do_calibration1 = example_adc_calibration_init(ADC_UNIT_1, ADC_ATTEN_DB_2_5, &adc1_cali_handle);
while (1)
{
vTaskDelay(pdMS_TO_TICKS(200));
ESP_ERROR_CHECK(adc_continuous_start(handle));
vTaskDelay(pdMS_TO_TICKS(200));
while (1)
{
ret = adc_continuous_read(handle, result, EXAMPLE_READ_LEN, &ret_num, 0);
if ((ret == ESP_OK) && (EXAMPLE_READ_LEN == ret_num))
{
memset(ADCSum, 0, sizeof(ADCSum));
for (int i = 0; i < ret_num; i += SOC_ADC_DIGI_RESULT_BYTES)
{
adc_digi_output_data_t *p = (void *)&result[i];
uint32_t chan_num = EXAMPLE_ADC_GET_CHANNEL(p);
uint32_t data = EXAMPLE_ADC_GET_DATA(p);
ADCSum[GetChannelIndex(chan_num)] += data;
}
if (do_calibration1)
{
for (int i = 0; i < channel_num; i++)
{
// ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_handle, ADCSum[i] / FILTERNUM, &AIn_V[i]));
ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_handle, ADCSum[i] / FILTERNUM, &AIn_Vv[FF][i]));
}
FF++;
if (FF == MIDNUM)
{
for (int k = 0; k < channel_num; k++)
{
AIn_V[k] = 0;
for (int i = 0; i < MIDNUM && channel[k] != ADC_CHANNEL_0; i++)
{
AIn_V[k] += AIn_Vv[i][k];
}
}
FF = 0;
}
}
}
else if (ret == ESP_ERR_TIMEOUT)
{
ESP_LOGE(TAG, "ADC No Data");
break;
}
vTaskDelay(pdMS_TO_TICKS(20));
}
ESP_ERROR_CHECK(adc_continuous_stop(handle));
ESP_LOGE(TAG, "ADC ReStart");
vTaskDelay(pdMS_TO_TICKS(10000));
}
ESP_ERROR_CHECK(adc_continuous_stop(handle));
ESP_ERROR_CHECK(adc_continuous_deinit(handle));
ESP_LOGE(TAG, "ADC End");
}