Page 1 of 1
How to set ADC sampling rate of ESP32?
Posted: Sat Jul 14, 2018 11:54 am
by alexretona
Hello! I'm currently using the ADC analog input of the ESP32 to get sensor readings. However, I'm confused in setting up the sampling rate of the ADC reading. Can I ask for some guide or tips to set the sampling frequency? My goal is to get 6000 samples per second from the ADC input. Thanks!
Re: How to set ADC sampling rate of ESP32?
Posted: Sun Jul 15, 2018 3:51 pm
by ESP_Dazz
There isn't a hardware mechanism to automatically read N samples per second from the ADC so you'll need to do it by software. I suggest using one of the hardware timer groups to drive an interrupt at 6KHz, then read the ADC in an ISR and put the results into some form of buffer.
Re: How to set ADC sampling rate of ESP32?
Posted: Mon Jul 16, 2018 2:11 am
by alexretona
Thank you for this, ESP_Dazz! I will update this post once I am able to do it based on your suggestion.
Re: How to set ADC sampling rate of ESP32?
Posted: Mon Jul 16, 2018 2:34 am
by ESP_Sprite
Actually, that's not entirely true. In the current master, the I2S peripheral can be configured to automatically take samples from the ADC and DMA these to memory. See e.g. the i2s_adc_enable function in the i2s driver.
Re: How to set ADC sampling rate of ESP32?
Posted: Tue Jul 17, 2018 11:37 am
by bobolink
I wanted to keep costs low by using no external peripherals to the ESP32. Just external analog conditioning components in front of GPIO 34.
I sample at 8ksps, use a software interrupt and two cores. Ping-Pong buffers.
Mostly DAC examples but one mic talk-through using ADC.
The software sampling technique causes some phase noise; the batch processing causes some latency.
These are just proof of concept examples and I haven’t developed them beyond that they seem to work.
https://github.com/bobh/ESP32AudioFramework
Re: How to set ADC sampling rate of ESP32?
Posted: Wed Jul 18, 2018 4:15 pm
by alexretona
Thank you everyone for all the suggestions. I used the hardware timer group function similar to this tutorial to implement the specific sampling rate that I need:
https://techtutorialsx.com/2017/10/07/e ... nterrupts/
I also found and tried a sample code based on the comment of ESP_igrr here:
viewtopic.php?t=1735
ESP_Sprite, I may try the I2S as an alternate method of setting my sampling rate. I will study on it first. Thank you for this!
Bobolink, thank you very much for the great project that you shared! It's great that the method that I used is similar to yours. I may further edit my code based on your project's configurations.
I will continue working with this project for the next few months. I will try my best to keep this updated.
Re: How to set ADC sampling rate of ESP32?
Posted: Fri Oct 30, 2020 5:30 am
by ShavinduR
hello , your post was very helpful me to understand about the sampling and timers on the esp32 , currently i am trying to sample the current readings from a current transformer based circuitry by utilizing an adc port of esp32, can i now how to set specific sampling rate and get the readings .
Re: How to set ADC sampling rate of ESP32?
Posted: Tue Nov 03, 2020 7:51 am
by scottabraham
Thank you everyone for all the suggestions. I used the hardware timer group function similar to this tutorial to implement the specific sampling rate that I need:
https://techtutorialsx.com/2017/10/07/etheessayservice.org
I also found and tried a sample code based on the comment of ESP_igrr here:
viewtopic.php?t=1735
ESP_Sprite, I may try the I2S as an alternate method of setting my sampling rate. I will study on it first. Thank you for this!
Is powering esp32 by external supply possible within this project? I am also considering using esp wroom32 module in my custom pcb.