could I to generate 40Mhz pulse on esp32 GPIO

NewPrasertKitt
Posts: 5
Joined: Thu Dec 06, 2018 4:20 am

could I to generate 40Mhz pulse on esp32 GPIO

Postby NewPrasertKitt » Thu Dec 06, 2018 4:27 am

I tried from those codes on Google but seem they doesn't work! Is the esp32 can do that?
best regards
NewPrasertKitt

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby rudi ;-) » Fri Dec 07, 2018 12:34 am

Hi

perhabs it helps

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

NewPrasertKitt
Posts: 5
Joined: Thu Dec 06, 2018 4:20 am

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby NewPrasertKitt » Fri Dec 07, 2018 12:10 pm

Rudi, thanks for your kindly help. could you tell me how to code these in arduino.

best regards
NewPrasertKitt

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby rudi ;-) » Fri Dec 14, 2018 6:47 pm

NewPrasertKitt wrote:
Fri Dec 07, 2018 12:10 pm
Rudi, thanks for your kindly help. could you tell me how to code these in arduino.

best regards
NewPrasertKitt
Which Board you want use?
best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

idahowalker
Posts: 19
Joined: Wed Aug 01, 2018 12:06 pm

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby idahowalker » Fri Dec 14, 2018 9:38 pm

1 tick on a hardware timer is at 80Mhz. Divide that by two and send it to a GPIO pin. I'd use direct write to the GPIO pin instead of digitalwrite.
https://techtutorialsx.com/2017/10/07/e ... nterrupts/

NewPrasertKitt
Posts: 5
Joined: Thu Dec 06, 2018 4:20 am

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby NewPrasertKitt » Sat Dec 15, 2018 6:01 am

Hello rudi,
I did try this sample code and reconfig the timer as below

timer = timerBegin(0, 2, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 2, true);
timerAlarmEnable(timer);

I use digitalWrite command to set and reset the GPIO but the pulse output just nothing. How to direct set/reset the GPIO, I think the digitalWrite command is too slow, not fast enough to work at this frequency.


I use Heltec Wifi Kit32 board.

Thanks
best regards
NewPrasertKitt

NewPrasertKitt
Posts: 5
Joined: Thu Dec 06, 2018 4:20 am

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby NewPrasertKitt » Sat Dec 15, 2018 8:28 am

hello idahowalker,
could you show me how to code in arduino to direct write GPIO of ESP32. thank you.

best regards
NewPrasertKitt

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

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby krzychb » Sat Dec 15, 2018 10:08 am

Hi NewPrasertKitt,

The simplest approach is to use on board peripherals to generate the pulse and do not engage the CPUs directly. In this case I propose LED Controller.
  1. #include "driver/ledc.h"
  2.  
  3. #define PULSE_OUTPUT_PIN 4
  4.  
  5. void setup()
  6. {
  7.   ledc_timer_config_t ledc_timer;
  8.   ledc_channel_config_t ledc_channel;
  9.  
  10.   ledc_timer.speed_mode   = LEDC_HIGH_SPEED_MODE;
  11.   ledc_timer.timer_num    = LEDC_TIMER_0;
  12.   ledc_timer.bit_num      = (ledc_timer_bit_t) 1;
  13.   ledc_timer.freq_hz      = 40000000;
  14.  
  15.   ledc_channel.channel    = LEDC_CHANNEL_0;
  16.   ledc_channel.gpio_num   = PULSE_OUTPUT_PIN;
  17.   ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
  18.   ledc_channel.timer_sel  = LEDC_TIMER_0;
  19.   ledc_channel.duty       = 1;
  20.  
  21.   ledc_timer_config(&ledc_timer);
  22.   ledc_channel_config(&ledc_channel);
  23. }
  24.  
  25. void loop()
  26. {
  27.   delay(1000);
  28. }
Last edited by krzychb on Sat Dec 15, 2018 4:03 pm, edited 1 time in total.

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby rudi ;-) » Sat Dec 15, 2018 10:53 am

a small complex arduino example :) taken from esp-idf

Code: Select all


#include "soc/emac_ex_reg.h"
 
 extern void rtc_plla_ena(bool ena, uint32_t sdm0, uint32_t sdm1, uint32_t sdm2, uint32_t o_div);
    // for rev0 chip: f_out = f_xtal * (sdm2 + 4) / (2 * (o_div + 2))
    // so for 40MHz XTAL, sdm2 = 1 and o_div = 1 will give 50MHz output

void setup() {
  // put your setup code here, to run once:

    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO16_U, FUNC_GPIO16_EMAC_CLK_OUT);
    REG_SET_FIELD(EMAC_EX_CLKOUT_CONF_REG, EMAC_EX_CLK_OUT_H_DIV_NUM, 0);
    REG_SET_FIELD(EMAC_EX_CLKOUT_CONF_REG, EMAC_EX_CLK_OUT_DIV_NUM, 0);
    REG_CLR_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_EXT_OSC_EN);
    REG_SET_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_INT_OSC_EN);

    // this did in the past 50Mhz enabled sig on GPIO
    // since the rtc_plla_ena was removed from lib
    // not sure how this can be enabled now
    rtc_plla_ena(1, 0, 0, 1, 0);


}

void loop() {
  // put your main code here, to run repeatedly:

}


note:
ESP_igrr wrote:
Tue Feb 28, 2017 12:51 pm
...
Edit: rtc_plla_ena function signature may change, this function may be removed, you may get eaten by raptors if you use it, etc, etc.

so i think the rtc_plla_ena is now removed from the lib ..

the example by @krzychb is simple and good and do the things you searched for too.
also the timer example. what you want to do ?

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

NewPrasertKitt
Posts: 5
Joined: Thu Dec 06, 2018 4:20 am

Re: could I to generate 40Mhz pulse on esp32 GPIO

Postby NewPrasertKitt » Sat Dec 15, 2018 1:39 pm

rudi, krzychb thanks for your help, I use this pulse signal to test osciloscope bandwidth.


best regards
NewPrasertKitt
krzychb_40Mhz.jpg
krzychb_40Mhz.jpg (148.62 KiB) Viewed 85 times

Who is online

Users browsing this forum: Bing [Bot] and 10 guests