ESP32 continuous ADC sample rate incorrect?

mnentwig
Posts: 4
Joined: Tue Jun 04, 2024 8:10 am

ESP32 continuous ADC sample rate incorrect?

Postby mnentwig » Tue Jun 04, 2024 9:26 am

Greetings,

this question relates to the ADC on ESP32, observed on two different WROOM-modules.
I'm using ESP-IDF 5.2.1, and code is based on "examples\peripherals\adc\continuous_read".

It appears to me that the actual ADC sample rate - that is, the amount of generated data in a given time interval - is off by a factor of 0.8181. This looks suspiciously (conjecture!) like the fraction 9/11.

My experiment configured e.g. a one second acquisition at different sample rates and measured the wallclock time between start of acquisition and arrival of last buffer.. Readings are consistently off by said factor of 0.8181 (note: Using the internal time base means errors in crystal frequency will cancel out, which should be negligible anyway).

Applying a "fudge factor" of 11/9 to the desired rate given to adc_continuous_config() results in the intended rate with error below 0.1% from 20 kSPS up to around 1.6 MSPS (should be 2 MSPS acording to soc_caps.h but apparently the same factor applies here, too)

I thought I'd pass on this observation. Could this be a bug in the driver? Or is my code leaking samples somewhere, two out of eleven?
Here is my raw data for 3 s capture. The 2nd row strongly suggests the abovementioned 11/9 factor (=22/18=22000/18000).

configured|observed (samples per second)
20000 16363.487
22000 17999.805
24200 19799.984
26620 21779.812
29282 23958.301
32210 26353.746
35431 28988.961
38974 31887.855
42872 35076.148
47159 38583.832
51875 42442.387
57062 46686.496
62769 51355.465
69045 56491.203
75950 62140.203
83545 68354.141
91899 75189.969
101089 82708.539
111198 90979.688
122318 100077.641
134550 110084.953
148005 121094.695
162805 133203.812
179086 146522.078
196995 161179.625
216694 177294.203
238364 194804.516
262200 214522.625
288420 236013.375
317262 259574.734
348988 285532.094
383887 314080.312
422276 345488.469
464503 380028.875
510953 418047.812
562049 459866.531
618254 505863.531
680079 556444.625
748087 612023.938
822896 673185.875
905185 740593.500
995704 814637.500
1095274 896101.375
1204801 985758.312
1325282 1084334.375
1457810 1193178.375
1603591 1312174.875
1763950 1443846.375
1940345 1587512.250
ADCrate.png
ADCrate.png (13.49 KiB) Viewed 1219 times

mnentwig
Posts: 4
Joined: Tue Jun 04, 2024 8:10 am

Re: ESP32 continuous ADC sample rate incorrect?

Postby mnentwig » Tue Jun 04, 2024 11:28 am

... and here is a stripped-down test program (idf.py build flash monitor)
https://github.com/mnentwig/ESP32_ADCrate_dbg

Horvat
Posts: 16
Joined: Thu May 02, 2024 8:40 am

Re: ESP32 continuous ADC sample rate incorrect?

Postby Horvat » Tue Jun 04, 2024 6:24 pm

The issue affect seems to apply to ESP32 only. On Esp32-S2 and Esp32-S3 I'm getting ratios very close to 1 with difference less than 0.005

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

Re: ESP32 continuous ADC sample rate incorrect?

Postby ESP_Sprite » Wed Jun 05, 2024 12:41 am

Thanks, that seems like a bug in ESP-IDF, I've filed an internal issue.

Horvat
Posts: 16
Joined: Thu May 02, 2024 8:40 am

Re: ESP32 continuous ADC sample rate incorrect?

Postby Horvat » Tue Jun 11, 2024 5:47 pm

There is year and half old ticket on github regarding this issue. For some strange reason, it's still not fixed.
https://github.com/espressif/esp-idf/issues/10612

Proposed fix.
https://github.com/cazou/esp-idf/commit ... 53696bacfb

Who is online

Users browsing this forum: Michaelboeding, ok-home and 89 guests