How to set ADC sampling rate of ESP32?
-
- Posts: 3
- Joined: Sat Jul 14, 2018 11:50 am
How to set ADC sampling rate of ESP32?
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?
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.
-
- Posts: 3
- Joined: Sat Jul 14, 2018 11:50 am
Re: How to set ADC sampling rate of ESP32?
Thank you for this, ESP_Dazz! I will update this post once I am able to do it based on your suggestion.
-
- Posts: 9745
- Joined: Thu Nov 26, 2015 4:08 am
Re: How to set ADC sampling rate of ESP32?
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?
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
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
-
- Posts: 3
- Joined: Sat Jul 14, 2018 11:50 am
Re: How to set ADC sampling rate of ESP32?
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.
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?
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 .
-
- Posts: 1
- Joined: Tue Nov 03, 2020 7:44 am
Re: How to set ADC sampling rate of ESP32?
Is powering esp32 by external supply possible within this project? I am also considering using esp wroom32 module in my custom pcb.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!
Who is online
Users browsing this forum: No registered users and 89 guests