Page 1 of 1

ADC continuous conversion driver feature request

Posted: Fri Aug 12, 2022 7:46 am
by Bertls_Bastelstube
Hi together,

in my project, I have this particular use case where I want to get N samples with a fixed sample rate from one channel, then configure some stuff and switch to the next channel. I configured the pattern to consist of just one ADC channel. When the conversion is finished, i change the channel in the pattern and call adc_continuous_config again.

Btw. I use the current master branch of esp-idf where there is the new adc continuous conversion driver.

My measurement routine looks as follows:

Code: Untitled.c Select all

static void adc_measure(adc_continuous_handle_t handle, int idx)
{
static uint32_t act_len;
esp_err_t ret;

adc_configure(handle, idx); // reconfigure the ADC (Change the pattern/channel)
ESP_ERROR_CHECK(adc_continuous_start(handle)); // Start the ADC

ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
ret = adc_continuous_read(handle, adc_buf, FRAME_SIZE, &act_len, 0); // Read out the frame buffer
ESP_ERROR_CHECK(adc_continuous_stop(handle)); // Stop the ADC
if (ret == ESP_OK && act_len == FRAME_SIZE) {
xTaskNotifyGive(eval_adc_task_h); // Notify evaluation task
}
vTaskDelay(pdMS_TO_TICKS(3000)); // To give the evaluation task some time because printing is slow (Just for testing)
}
Like in the ADC continuous conversion example I use a task notification from the on_conv_done callback (My frame size is equal to the max buffer size). The problem is that some time passes between the interrupt and the call to adc_continuous_stop where the ADC goes on with new conversions. The next time adc_measure is executed, I won't receive a full frame size. It is crucial that every measurement has the same number of samples.

For me, I solved it by calling adc_hal_digi_stop(&ctx->hal); right at the beginning of the adc_dma_intr_handler in the adc_continuous.c file.

It would be cool if someone could share a better approach (without changing the driver functions or reinitializing the adc between every measurement). I am sure this is not an uncommon use case.

Other advice or questions are greatly appreciated.

Thanks and best Regards,
Robert