How to make ESP32 output 20MHZ's clock

roctwo
Posts: 95
Joined: Mon Nov 28, 2016 3:12 am

How to make ESP32 output 20MHZ's clock

Postby roctwo » Tue Jan 24, 2017 12:58 am

Hi!
How to make ESP32 output 20MHZ's clock? And can you provide code?

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

Re: How to make ESP32 output 20MHZ's clock

Postby kolban » Tue Jan 24, 2017 1:17 am

Do you mean you want a square wave output on a GPIO pin that has a frequency of 20MHz? If so, you can likely use the PWM functions.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

roctwo
Posts: 95
Joined: Mon Nov 28, 2016 3:12 am

Re: How to make ESP32 output 20MHZ's clock

Postby roctwo » Tue Jan 24, 2017 3:27 am

OK ,Thank you,sorry for my bad English.I will check it

ppisljar
Posts: 18
Joined: Wed Feb 22, 2017 4:36 pm

Re: How to make ESP32 output 20MHZ's clock

Postby ppisljar » Thu Sep 21, 2017 6:41 pm

seems pwm can only be used to generate 333k clock ... what about higher frequencies ?

User avatar
krzychb
Posts: 232
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: How to make ESP32 output 20MHZ's clock

Postby krzychb » Thu Sep 21, 2017 9:53 pm

roctwo wrote:How to make ESP32 output 20MHZ's clock? And can you provide code?

Below is an example how to generate 20MHz square wave at 50% duty on GPIO18.

  1. #include "driver/ledc.h"
  2.  
  3. ledc_timer_config_t ledc_timer = {
  4.     .speed_mode = LEDC_HIGH_SPEED_MODE,
  5.     .timer_num  = LEDC_TIMER_0,
  6.     .bit_num    = 2,
  7.     .freq_hz    = 20000000
  8. };
  9.  
  10. ledc_channel_config_t ledc_channel = {
  11.     .channel    = LEDC_CHANNEL_0,
  12.     .gpio_num   = 18,
  13.     .speed_mode = LEDC_HIGH_SPEED_MODE,
  14.     .timer_sel  = LEDC_TIMER_0,
  15.     .duty       = 2
  16. };
  17.  
  18. void app_main()
  19. {
  20.     ledc_timer_config(&ledc_timer);
  21.     ledc_channel_config(&ledc_channel);
  22.     while (1) {
  23.         ;
  24.     }
  25. }
The LED PWM Controller can generate up to 40MHz square wave.

Who is online

Users browsing this forum: No registered users and 17 guests