ADC and accurate timing

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

ADC and accurate timing

Postby FrankJensen » Tue Mar 26, 2024 11:18 pm

Hi forum.

I would like to sample within a specific window, using continuous mode and the DMA feature. I finally seems to have the ADC and DMA working correctly, but I am facing some problems...

I have an GPIO input, that should start and stop the sampling, with as big accuracy as possible.

- How do I start the sampling accurate when the timer interupt occurs? I can not call the adc_continuous_start from within the ISR, that causes an reboot. I think, that it takes too long, or is blocking - but not sure exactly why it fails. But it does.

- And I also want to stop the sampling the same way.

- And I would like to read the buffer, after I stop the sampling, but it seems like the resources are not available anymore. I get a ADC stopped error.

- And lastly, I would like to clear the buffer and ADC and start from scratch, making a new sampling. The only way I can see, is to adc_continuous_deinit everything. Is there a way just to reset the buffer?

I want to sample 4 channels for 100mS, at 10KHz making that a total of 4.000 samples. And my initial thought, was simply to make the buffer large enough, and read it, to avoid any ISR to handle sample data. I should have plenty of resources available.

But how do I make a precision timed sampling? Any ideas?

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

Re: ADC and accurate timing

Postby FrankJensen » Wed Mar 27, 2024 9:39 am

Hi again.

An alternative would be, if I can somehow log the index of the DMA buffer upon interupt. So I know, where my sample starts and stops. Is that possible?

Any help apreciated :-)

ESP_Sprite
Posts: 9052
Joined: Thu Nov 26, 2015 4:08 am

Re: ADC and accurate timing

Postby ESP_Sprite » Thu Mar 28, 2024 1:59 am

If you use the ESP32-C6, you may be able to use the ETM to do a bunch of those things with a fairly high degree of precision. (Although I'm not sure about the support for this in ESP-IDF, you may want to look that up as well.)

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

Re: ADC and accurate timing

Postby FrankJensen » Thu Mar 28, 2024 8:52 am

I use the ESP32-S3. I have looked into getting the buffer position, but it dont seem straight forward.

I have tried to set the samplesize to 1 sample and trigger the adc_continuous_register_event_callbacks to make my own counter, but then the real benefit of the DMA is less, and it puts more strain on the processor.

So I am still thinking about the best workaround to get the ADC to sample only between 2 GPIO interupts with as little lack as possible.

If only I could use adc_continuous_start from within an GPIO interupt, but when I do that, it crashes.

StanInexeon
Posts: 1
Joined: Thu Mar 28, 2024 9:05 am

Re: ADC and accurate timing

Postby StanInexeon » Mon Apr 22, 2024 9:32 am

Hi Frank,

I'm trying to do the exact same thing.

I found the following issue on the esp-idf github page: https://github.com/espressif/esp-idf/issues/13484

I think the solution might be to: init the driver, start the driver (on the first interrupt), stop the driver (on the second interrupt), deinit the driver and start over again.

For my application this will work because I only need to analyze a single window, but if you need constant window output, this might not work.

I will try to see if this solution will work, I will let you know the result.

~Stan

Who is online

Users browsing this forum: Majestic-12 [Bot] and 223 guests