Page 1 of 1

Question about ESP32_C3 Speed

Posted: Tue Sep 10, 2024 7:21 am
by Hobby65
Hello,
I am a newby with the esp32 and to make at first a speedtest. I write with the arduino ide:
digitalWrite(0, HIGH);
digitalWrite(0, LOW);
I look the sqaresignal on an oscilloscopescreen and see that the lowcycle is three times longer as the highcycle and
the freqency is 300kHz.
Can someone tell why the cycles are diffrent and why the frequency is so slow?
Many thanks foe every answer
Hans

Re: Question about ESP32_C3 Speed

Posted: Tue Sep 10, 2024 5:34 pm
by lbernstone
Your code is asking the CPU to bit bang each flip of the switch. This means it has to process all the hardware abstraction code, poke the register, and then wait for confirmation that it succeeded before moving to the next process. There's also an OS running that needs some cycles to process.
The esp32 (and most mcu's) has hardware functions to speed up the gpio activities by offloading from the cpu. The esp32 series have a wide range of peripherals to allow square, sinusoidal, or much more complicated programmed cycles up to 40MHz. The following code will generate a nice regular 20MHz square wave on pin 2 using the ledc peripheral.:

Code: Select all

ledcAttach(2, 20000000, 1);
ledcWrite(2,1);

Re: Question about ESP32_C3 Speed

Posted: Wed Sep 11, 2024 10:11 am
by Hobby65
Hello,
my goal is not to generate a waveform. I'm just looking for a way to make setting and reading I/Os faster so that a program runs faster.

Re: Question about ESP32_C3 Speed

Posted: Wed Sep 11, 2024 6:54 pm
by lbernstone
To get fast, accurate signals, you will need to use a peripheral
Ask a vague question, get a vague answer.

Re: Question about ESP32_C3 Speed

Posted: Wed Sep 11, 2024 11:08 pm
by chegewara
I know this does not answer your question, but i hope this may help you a bit.
You asked about C3 chip, but new chips H2, C5 and C6 have new peripheral, which is parallel IO.
https://docs.espressif.com/projects/esp ... arlio.html
https://github.com/espressif/esp-idf/tr ... als/parlio

This new peripheral looks pretty cool, because allows to fast read/write up to 8 pins with additional clock line. (P4 can have 16 lines)