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:
- 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)
- }
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