Page 1 of 1

Highest clock by GPIO

Posted: Sat Jun 20, 2020 5:16 am
by whoyoume
Hello,

Using ESP32, I generate a clock of 9.9MHz by a code as below.

Could anyone please show me if it would be the highest clock?
and, if it would be constantly.

I afraid there would be jitter or deficiency, but I could not check it because I have not logger for so that long period.

Thank you.

// ESP32
//
#define PORT (*((volatile uint32_t*)GPIO_OUT_REG))
#define PIN_OUT 23
//#define PIN_H PORT |= (1 << PIN_OUT)
//#define PIN_L PORT &= ~(1 << PIN_OUT)
#define PIN_H PORT = (1 << PIN_OUT)
#define PIN_L PORT = 0

void setup()
{
pinMode(PIN_OUT, OUTPUT);

noInterrupts();

tag_loop:
PIN_H;
PIN_L;
goto tag_loop;
}

void loop()
{
}

clk.png
clk.png (2.85 KiB) Viewed 2326 times
clk_constantly.png
clk_constantly.png (8.55 KiB) Viewed 2326 times

Re: Highest clock by GPIO

Posted: Sat Jun 20, 2020 11:09 am
by ESP_Sprite
Don't try to bitbang things like this and expect a good result. There's other cores on the system accessing hardware, so even if you disable interrupts (which you should not do for long in the first place, by the way, as it can break when things like NVS access or some hardware workarounds hapen) you won't get timing that's guaranteed consistent. Instead, use one of the many, may peripherals to generate signals: in your case, the LEDC PWM generator would work beautifully, for instance.