I couldn’t find any usable info about the sampling speed of Espressif’s ESP32 onboard ADC.
The benchmark was performed on the following Hardware:
Platform: Espressif 32 -> NodeMCU-32S
System: ESP32 240MHz 320KB RAM (4MB Flash)
The firmware for the benchmark was build using PlatformIO with the Arduino framework. To get a fast access to the hardware, the Espressif IoT Development Framework was used for all ADC specific function calls.
#include <chrono> #include <Arduino.h> #include <driver/adc.h> void setup() { Serial.begin(115200); adc1_config_width(ADC_WIDTH_BIT_12); adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11); } void loop() { const uint16_t samples = 10000; auto t1 = std::chrono::system_clock::now(); for (uint32_t i=0; i<samples; i++) { adc1_get_raw(ADC1_CHANNEL_4); // GPIO32 } auto t2 = std::chrono::system_clock::now(); std::chrono::duration<double> diff = t2 - t1; auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count(); Serial.printf("Samples: %u\n", samples); Serial.printf("Duration: %llums\n", ms); Serial.printf("KSPS: %0.4f", static_cast<double>(samples) / ms); }
The results are showing that the ADC is capable of doing 27.2 ksps (27173 samples per second). This does not change when reducing the resolution to 10 or even 9 bits.
Resolution (bit) | Speed (ksps) |
ADC_WIDTH_BIT_9 | 27.1739 |
ADC_WIDTH_BIT_10 | 27.1739 |
ADC_WIDTH_BIT_11 | 27.1739 |
ADC_WIDTH_BIT_12 | 27.1739 |
For me this results were unexpected, since a lower resolution should decrease the sample time.
Update
In the Espressif datasheet (topic 4.1.2), the ADC characteristics shows the following maximum sampling rates.
Description | Sampling rate (max) |
RTC controller | 200 ksps |
DIG controller | 2 Msps |
First question: what is a DIG controller and why has the RTC/DIG controller impact on the sampling speed? Assuming the numbers in the datasheet are valid, the measured speed differ massively from this rates. The implementation of adc1_get_raw is quite complex and does a lot of hardware initialization/locking around adc_convert().
int adc1_get_raw(adc1_channel_t channel) { uint16_t adc_value; RTC_MODULE_CHECK(channel < ADC1_CHANNEL_MAX, "ADC Channel Err", ESP_ERR_INVALID_ARG); adc1_adc_mode_acquire(); adc_power_on(); portENTER_CRITICAL(&rtc_spinlock); //disable other peripherals adc1_hall_enable(false); adc1_fsm_disable(); //currently the LNA is not open, close it by default //set controller adc_set_controller( ADC_UNIT_1, ADC_CTRL_RTC ); //start conversion adc_value = adc_convert( ADC_UNIT_1, channel ); portEXIT_CRITICAL(&rtc_spinlock); adc1_lock_release(); return adc_value; }
So, the hardware might be capable to provide the claimed speeds but definitely not when using Espressif’s IDF as described in their documentation.
quite low speed. I.E with stm32f0 you can reach 1Msps with 12bit and even higher with 10/8/6 bit options.
Hi,
I am trying to use your awesome library about the MCP3208. https://github.com/labfruits/mcp320x
Everything is fine if I set the SPI around 1,6MHz. But, if I set the SPI at 25MHz (on an ESP32) I can’t read the raw values properly. I think that I need to use adc.calibrate() before, but I can’t use this function, it doesn’t work.
Can you help me?
Many thanks!
Enry
Hi Enry,
thanks for using this library.
The problem is the SPI frequency. The MCP320x family is rated for a maximum SPI clock of 2MHz at 5V. If you increase the SPI clock that much, the chip can’t sample the voltage. Please have a look at https://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf Page 3, Timing Parameters/fCLK.
Dear all,
With regards to the dig controller adc, i dont know how it works, but on this site there is some interesting looking source code for achieving Msps:
https://www.esp32.com/viewtopic.php?t=2346
At the bottom you can download a file.
Let me know if you succeed in making it work.
You need to use dma/i2s to reach that speed.
Try high speed adc example in esp32 Arduino core. tweak sampling freq in the code you can get high sample rate up to 1.3msps with i2s sampling freq of 650ksps.
It appears that you know a lot about this topic. I expect to learn more from your upcoming updates. Of course, you are very much welcomed to my website Article Star about Blogging.
Superb posts! Have a look at my page YW9 where I also put in extra effort to create quality information about Airport Transfer.
My site Article Home covers a lot of topics about SEO and I thought we could greatly benefit from each other. Awesome posts by the way!
I’m eager to read more from you. Keep it up!If anyone wants to read the topic in more detail then visit mom porn
Do you love sex, you are looking for girls , we have best service related to prostitution. If you are interested then check out my website just fucking girls
This is quality work regarding the topic! I guess I’ll have to bookmark this page. See my website 57N for content about Airport Transfer and I hope it gets your seal of approval, too!
Your posts in this blog really shine! Glad to gain some new insights, which I happen to also cover on my page. Feel free to visit my webpage 46N about Airport Transfer and any tip from you will be much apreciated.
Great site with quality based content. You’ve done a remarkable job in discussing. Check out my website UQ6 about Cosmetic Treatment and I look forward to seeing more of your great posts.
You’ve done an impressive work on your website in covering the topic. I am working on content about Airport Transfer and thought you might like to check out ZH5 and let me what you think.
Impressive posts! My blog QH3 about Thai-Massage also has a lot of exclusive content I created myself, I am sure you won’t leave empty-handed if you drop by my page.