How to set ADC sampling rate of ESP32?

alexretona
Posts: 3
Joined: Sat Jul 14, 2018 11:50 am

How to set ADC sampling rate of ESP32?

Postby alexretona » Sat Jul 14, 2018 11:54 am

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!

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: How to set ADC sampling rate of ESP32?

Postby ESP_Dazz » Sun Jul 15, 2018 3:51 pm

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.

alexretona
Posts: 3
Joined: Sat Jul 14, 2018 11:50 am

Re: How to set ADC sampling rate of ESP32?

Postby alexretona » Mon Jul 16, 2018 2:11 am

Thank you for this, ESP_Dazz! I will update this post once I am able to do it based on your suggestion. :D

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

Re: How to set ADC sampling rate of ESP32?

Postby ESP_Sprite » Mon Jul 16, 2018 2:34 am

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.

bobolink
Posts: 98
Joined: Mon Feb 26, 2018 4:17 pm

Re: How to set ADC sampling rate of ESP32?

Postby bobolink » Tue Jul 17, 2018 11:37 am

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

alexretona
Posts: 3
Joined: Sat Jul 14, 2018 11:50 am

Re: How to set ADC sampling rate of ESP32?

Postby alexretona » Wed Jul 18, 2018 4:15 pm

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. :D

ShavinduR
Posts: 1
Joined: Fri Oct 30, 2020 4:47 am

Re: How to set ADC sampling rate of ESP32?

Postby ShavinduR » Fri Oct 30, 2020 5:30 am

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 .

scottabraham
Posts: 1
Joined: Tue Nov 03, 2020 7:44 am

Re: How to set ADC sampling rate of ESP32?

Postby scottabraham » Tue Nov 03, 2020 7:51 am

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.

Who is online

Users browsing this forum: No registered users and 87 guests