Page 1 of 1

Output a clock signal in the MHz range

Posted: Mon Aug 14, 2017 11:32 am
by stefan
Hi guys!
How does one generate a stable clock signal above what the LED PWM provides?
I need a 2MHz square wave signal with 50:50 duty cycle.

Of cause the ESP32 is fast and I could use a RTOS thread, but there must be a more elegant way.

I see CLKout1, CLKout2, CLKout3 - #1 + #2 are on the USB pins - so what about CLKout3 (GPIO0)?
Or even better - because GPOI0 is connected to the boot sequence - have another pin do it - what about all those PWMs?

Any help would be awesome - I really don't feel like connecting a whole Arduino for the clock at this moment :-)

Re: Output a clock signal in the MHz range

Posted: Tue Aug 15, 2017 3:51 pm
by iot-bits.com
You can use CLK_OUT pins to output any clock frequency (>= peripheral clock and accuracy subject to divisors). Check out the latest ESP32 TRM. It has details on how to output I2S clock on the CLK_OUT pins. It is really accurate.

Re: Output a clock signal in the MHz range

Posted: Tue Aug 15, 2017 10:31 pm
by stefan
Ah OK, thanks for the hint!

To fill in others that have the same problem:
Using nothing but pin up/down in the main loop results in a short burst at about 1MHz on my scope.
Literally just

Code: Select all

setup: pinMode(5, OUTPUT);
loop:
GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, 0b00000000000000000000000000100000);
GPIO_REG_WRITE(GPIO_OUT_W1TC_REG, 0b00000000000000000000000000100000);
So I will now try to activate I2S in Arduino. Haven't found anything Arduino specific till now...
Is there some "tutorial" on how to use those routines in the SDK and the ardu core - I am not the greatest when it comes to this sort of cross-everything-coding…

Re: Output a clock signal in the MHz range

Posted: Wed Aug 16, 2017 1:37 am
by WiFive