ESP output pin as clock input for IC

MalteJ
Posts: 62
Joined: Wed Sep 21, 2016 10:26 pm

ESP output pin as clock input for IC

Postby MalteJ » Fri Jan 20, 2017 10:34 am

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

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

Re: ESP output pin as clock input for IC

Postby ESP_Sprite » Fri Jan 20, 2017 10:44 am

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP output pin as clock input for IC

Postby kolban » Fri Jan 20, 2017 10:49 am

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
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

MalteJ
Posts: 62
Joined: Wed Sep 21, 2016 10:26 pm

Re: ESP output pin as clock input for IC

Postby MalteJ » Fri Jan 20, 2017 10:52 am

Great! Thanks for your assessment!

I will give it a try.

Best,
Malte

seopyoon
Posts: 23
Joined: Thu Dec 08, 2016 8:25 am

Re: ESP output pin as clock input for IC

Postby seopyoon » Wed Feb 01, 2017 6:43 am

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP output pin as clock input for IC

Postby WiFive » Wed Feb 01, 2017 8:03 am

Try with bit_num = 8

seopyoon
Posts: 23
Joined: Thu Dec 08, 2016 8:25 am

Re: ESP output pin as clock input for IC

Postby seopyoon » Thu Feb 02, 2017 5:08 am

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?
Last edited by seopyoon on Thu Feb 02, 2017 5:21 am, edited 2 times in total.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP output pin as clock input for IC

Postby WiFive » Thu Feb 02, 2017 5:20 am

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
Last edited by WiFive on Thu Feb 02, 2017 5:23 am, edited 1 time in total.

seopyoon
Posts: 23
Joined: Thu Dec 08, 2016 8:25 am

Re: ESP output pin as clock input for IC

Postby seopyoon » Thu Feb 02, 2017 5:21 am

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP output pin as clock input for IC

Postby WiFive » Thu Feb 02, 2017 5:25 am

Yes 2^8 / 2 = 128

Who is online

Users browsing this forum: Bing [Bot], egionet and 344 guests