Open klaus-liebler opened 1 year ago
This callback is an Interrupt generated by DMA (I am not sure how that works). what I would do to get an idea of the sample rate is to generate an interrupt on APB_SARADC_ADC1_DONE_INT_ENA which indicates a conversion DONE event on the ADC. (check TRM Register 39.72. APB_SARADC_INT_ENA_REG (0x005C) ).
I added this peace of code to make a level 1 interrupt with Interrupt source 65 (to generate an interrupt on APB_SARADC_ADC1_DONE_INT_ENA)
/*Setting up the Interrupt*/
/*APB_SARADC_ADC1_DONE_INT: Triggered when SAR ADC1 completes one data conversion.*/
REG_SET_BIT(APB_SARADC_INT_ENA_REG, APB_SARADC_ADC1_DONE_INT_ENA);
xt_ints_off(1<<13);
intr_matrix_set(0, 65, 13);
xt_ints_on(1<<13);
xt_set_interrupt_handler(13, my_int, NULL);
-I am using both ADC units (two channels from two different units). -I toggle a GPIO inside the interrupt handler.
No matter what sampling frequency I set, the GPIO is toggled at the same frequency. the frequency of the interrupt is so high that no other task can run.
this might indicate some issue with ADC itself (if my code is correct ofc haha). I will open a separate issue on this.
Answers checklist.
IDF version.
v5.0.2
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
Standard Dev. Board
Power Supply used.
USB
What is the expected behavior?
I need to sample a signal in constant intervals and react immediately, if a condition occurs. I have written a small test program to check the timing capabilities of the ESP32 architecture. As you can see in the code below, the ADC is setup in continuous mode with a single channel and a sampling rate of 20kHz. The callback shoud be invoked after each sample. That means, the callback shoud occur every 50us and there should be roughly 200k callbacks in a 10 seconds test interval.
What is the actual behavior?
Instead, there are 176545 callbacks and after four correctly timed samples (50us time interval) there is an outlier (86...89us time interval).
Steps to reproduce.
Compile and run my test program
Debug Logs.
More Information.
The error rate changes depending on the callback frequency and the sample rate, see https://github.com/espressif/esp-idf/issues/10612#issuecomment-1572787379