Highest clock by GPIO

whoyoume
Posts: 23
Joined: Fri Sep 07, 2018 2:42 am

Highest clock by GPIO

Postby whoyoume » Sat Jun 20, 2020 5:16 am

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 2415 times
clk_constantly.png
clk_constantly.png (8.55 KiB) Viewed 2415 times

ESP_Sprite
Posts: 9769
Joined: Thu Nov 26, 2015 4:08 am

Re: Highest clock by GPIO

Postby ESP_Sprite » Sat Jun 20, 2020 11:09 am

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.

Who is online

Users browsing this forum: hiengee and 124 guests