Question about ESP32_C3 Speed

Hobby65
Posts: 7
Joined: Mon Oct 16, 2023 4:06 pm

Question about ESP32_C3 Speed

Postby Hobby65 » Tue Sep 10, 2024 7:21 am

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

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: Question about ESP32_C3 Speed

Postby lbernstone » Tue Sep 10, 2024 5:34 pm

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);

Hobby65
Posts: 7
Joined: Mon Oct 16, 2023 4:06 pm

Re: Question about ESP32_C3 Speed

Postby Hobby65 » Wed Sep 11, 2024 10:11 am

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.

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: Question about ESP32_C3 Speed

Postby lbernstone » Wed Sep 11, 2024 6:54 pm

To get fast, accurate signals, you will need to use a peripheral
Ask a vague question, get a vague answer.

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Question about ESP32_C3 Speed

Postby chegewara » Wed Sep 11, 2024 11:08 pm

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)

Who is online

Users browsing this forum: No registered users and 52 guests