Page 1 of 1
ESP output pin as clock input for IC
Posted: Fri Jan 20, 2017 10:34 am
by MalteJ
Hey,
I am wondering, is it possible to use an esp32's GPIO pin as a clock source for an external IC?
The IC needs a 4 MHz square signal. Can I use an esp32 hardware timer and do something like PWM for generating this clock signal?
What is the maximum frequency that can be realized?
Thank you!
Malte
Re: ESP output pin as clock input for IC
Posted: Fri Jan 20, 2017 10:44 am
by ESP_Sprite
Sure, take e.g. the LED PWM hardware and generate a PWM signal with a duty cycle of 50% and the desired frequency. I'm halfway sure you can generate signals up to 40MHz using that.
Re: ESP output pin as clock input for IC
Posted: Fri Jan 20, 2017 10:49 am
by kolban
Looking at section 6 of the ESP32 technical reference manual found here:
http://espressif.com/sites/default/file ... ual_en.pdf
It seems that the ESP32 has 16 independent channels of PWM output. The frequency seems to be rated by a complex formula that I'd need to sit down and think about for a long, long while
however it does appear to be able to accommodate 4MHz.
There also appears to be high level drivers for this function so you don't have to "mess" with poking registers ... see:
http://esp-idf.readthedocs.io/en/latest ... /ledc.html
Re: ESP output pin as clock input for IC
Posted: Fri Jan 20, 2017 10:52 am
by MalteJ
Great! Thanks for your assessment!
I will give it a try.
Best,
Malte
Re: ESP output pin as clock input for IC
Posted: Wed Feb 01, 2017 6:43 am
by seopyoon
Hello, I am trying to use PWM functionality from ESP32 to generate frequency of 113kHz with 50% duty cycle.
When I do this, with the minimum precision (10 Bits), I get div_param lower than 256 (yields 176). Even at such frequency, I cannot generate 50% duty cycle.
How were you able to produce clock cycle at 40MHz??
That would only make div_param smaller, which will provide error. (ledc.c line 181-197)
Please help.
Thanks a lot in advance.
Re: ESP output pin as clock input for IC
Posted: Wed Feb 01, 2017 8:03 am
by WiFive
Try with bit_num = 8
Re: ESP output pin as clock input for IC
Posted: Thu Feb 02, 2017 5:08 am
by seopyoon
I know, that with the lower bit number, it should be possible.
But when looking at the driver code
https://github.com/espressif/esp-idf/bl ... ledc.h#L78, it seems that it should be at least 10 bits precise. Can I just alter the driver code and try with 8 or 9 bits?
Why is it then, that the enum is only from 10 to 15?
Re: ESP output pin as clock input for IC
Posted: Thu Feb 02, 2017 5:20 am
by WiFive
Yes just use numeric value. Was able to generate 113.2khz.
Perhaps because those are the recommended range for working with LEDs?
https://github.com/igrr/esp32-cam-demo/ ... era.c#L100
Re: ESP output pin as clock input for IC
Posted: Thu Feb 02, 2017 5:21 am
by seopyoon
To ensure, if I use 8 bits, i would set duty as 128 for having half the period on, and half the period off, right??? I ask this, since I do not have access to oscilloscope to make sure.
Re: ESP output pin as clock input for IC
Posted: Thu Feb 02, 2017 5:25 am
by WiFive
Yes 2^8 / 2 = 128