Hi,
I’ve developped a Morse decoder program that run perfectly well when compiled with ArduinoIDE.
I migrated under VSCode / PlatformIO, and the ADC is much more slow when compiled with PlatformIO.
My board is a NodeMCU-32S, and i noticed that at boot time, the program compiled with PlatformIO says : mode:DIO, clock div:2
while the same program compiled in ArduinoIDE says :mode:DIO, clock div:1
As a result, the ADC conversion are 2 times slower under PlatformIO.
I’ve tried to force the adc_clock_div from inside my setup() function using this:
esp_err_t errCode = adc_set_clk_div(1);
but it seems that this call has no effect at all. i tried div=1, div=4 run this code in setup()
// Measure sampling_freq
int tStartLoop = millis();
int cpt = 0;
while ( (millis() - tStartLoop) < 4000) { testData[0] = analogRead(A0); cpt++;}
sampling_freq = cpt / 4; // Measured at Startup on NodeMCU-32S
but the results is always the same, around 10118 samples / s, and do not change even if div=4 ???
Furthermore, depending on the code i write in the loop(), the setup() function measure from 10118 downto 7500 samples / s ??? I really don’t understand why different code in the loop() (code that is not related to the ADC), make those changes in ADC speed measured in setup() function!!!
How can i get rid of this boot time div:2 set by PlatformIO and get a normal div:1 and no need to try to set adc clock div in my program ???
Is there something that can be changed somewhere so that under PlatformIO, the ADC clock div stays at 1 like on ArduinoIDE ??
Hi, thanks for your quick reply.
It is a little bit better with this change in platformio.ini file.
I get now 10086 sam/s instead of 9000, but i don’t get the expected 11450 samp/s .
Could you please download my program from github ?
At line 222, I added 2 defines, that show how code, that has nothing to do with ADC, make the number of sample varying from 9000 to 11450, depending on the fact that you compile or not the function clearIfNotChanged.
When the code is not compiled, i get 11496 samp/s, and when it is compiled, i get only 9000 samp/s
And of course, i would like the code in this function de be compiled.
To test it, you just have to compile with one or the other define.
In this program, you can search for “ADC sped problem”. I explain in the setup() function what has changed since i created this topic.
Just for info, i recompiled my program in ArduinoIDE, and whatever the #define you activate (compile code or not compile it), i get the same ADC speed able to give me 11246 sams/s. So, ArduinoIDE do not have the problem that i encounter with PlarformIO.
Great. Then the speed at which code and data is fetched from the flash should be on-par now.
What exact Arduino-ESP32 version are you using in the Arduino IDE? Please go to Tools → Boards → Board Manager → ESP32 and read off the version. Is it maybe 2.0.14 or 3.0.0 Alpha?