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
Question about ESP32_C3 Speed
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Question about ESP32_C3 Speed
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.:
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
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.
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.
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Question about ESP32_C3 Speed
To get fast, accurate signals, you will need to use a peripheral
Ask a vague question, get a vague answer.
Ask a vague question, get a vague answer.
Re: Question about ESP32_C3 Speed
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)
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 58 guests