Page 1 of 2
could I to generate 40Mhz pulse on esp32 GPIO
Posted: Thu Dec 06, 2018 4:27 am
by NewPrasertKitt
I tried from those codes on Google but seem they doesn't work! Is the esp32 can do that?
best regards
NewPrasertKitt
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Fri Dec 07, 2018 12:34 am
by rudi ;-)
Hi
perhabs it helps
best wishes
rudi
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Fri Dec 07, 2018 12:10 pm
by NewPrasertKitt
Rudi, thanks for your kindly help. could you tell me how to code these in arduino.
best regards
NewPrasertKitt
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Fri Dec 14, 2018 6:47 pm
by rudi ;-)
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
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Fri Dec 14, 2018 9:38 pm
by idahowalker
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/
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Sat Dec 15, 2018 6:01 am
by NewPrasertKitt
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
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Sat Dec 15, 2018 8:28 am
by NewPrasertKitt
hello idahowalker,
could you show me how to code in arduino to direct write GPIO of ESP32. thank you.
best regards
NewPrasertKitt
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Sat Dec 15, 2018 10:08 am
by ESP_krzychb
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.
#include "driver/ledc.h"
#define PULSE_OUTPUT_PIN 4
void setup()
{
ledc_timer_config_t ledc_timer;
ledc_channel_config_t ledc_channel;
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_timer.timer_num = LEDC_TIMER_0;
ledc_timer.bit_num = (ledc_timer_bit_t) 1;
ledc_timer.freq_hz = 40000000;
ledc_channel.channel = LEDC_CHANNEL_0;
ledc_channel.gpio_num = PULSE_OUTPUT_PIN;
ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_channel.timer_sel = LEDC_TIMER_0;
ledc_channel.duty = 1;
ledc_timer_config(&ledc_timer);
ledc_channel_config(&ledc_channel);
}
void loop()
{
delay(1000);
}
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Sat Dec 15, 2018 10:53 am
by rudi ;-)
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
Re: could I to generate 40Mhz pulse on esp32 GPIO
Posted: Sat Dec 15, 2018 1:39 pm
by NewPrasertKitt
rudi, krzychb thanks for your help, I use this pulse signal to test osciloscope bandwidth.
best regards
NewPrasertKitt
- krzychb_40Mhz.jpg (148.62 KiB) Viewed 13530 times