ADC continuous conversion driver feature request

Bertls_Bastelstube
Posts: 1
Joined: Thu Aug 11, 2022 11:06 am

ADC continuous conversion driver feature request

Postby Bertls_Bastelstube » Fri Aug 12, 2022 7:46 am

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:
  1. static void adc_measure(adc_continuous_handle_t handle, int idx)
  2. {
  3.     static uint32_t act_len;
  4.     esp_err_t ret;
  5.    
  6.     adc_configure(handle, idx);   // reconfigure the ADC (Change the pattern/channel)
  7.     ESP_ERROR_CHECK(adc_continuous_start(handle));  // Start the ADC
  8.  
  9.     ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
  10.     ret = adc_continuous_read(handle, adc_buf, FRAME_SIZE, &act_len, 0);  // Read out the frame buffer
  11.     ESP_ERROR_CHECK(adc_continuous_stop(handle));   // Stop the ADC
  12.     if (ret == ESP_OK && act_len == FRAME_SIZE) {
  13.         xTaskNotifyGive(eval_adc_task_h);    // Notify evaluation task
  14.     }
  15.     vTaskDelay(pdMS_TO_TICKS(3000));    // To give the evaluation task some time because printing is slow (Just for testing)
  16. }
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
Attachments
project.zip
(451.42 KiB) Downloaded 306 times
beatz_adc.c
(6.79 KiB) Downloaded 307 times

Who is online

Users browsing this forum: Bing [Bot] and 48 guests