Can ESP32 alone can generate 40MHz square wave using LEDC library?
Posted: Sat Sep 14, 2024 11:00 am
Hi,
I happen to surf around this forum and found interesting, but old (currently uncompilable codes under ESP-IDF 5) codes.
Fyi, https://esp32.com/viewtopic.php?t=1037#p14480 provides an example to generate 20MHz square wave at 50% duty on GPIO18 using LEDC library alone.
Being new to the esp32 and C, I tried to make a few changes and made an .ino file from the code:
But it refuses to compile in esp32 dev board with the error that reads:
Just wondering is 40Mhz with mere esp32 possible? Is ther any way to convert the C code above to .ino in v5+ of ESP-IDF?
Thanks in advance, and have a nice weekend.
I happen to surf around this forum and found interesting, but old (currently uncompilable codes under ESP-IDF 5) codes.
Fyi, https://esp32.com/viewtopic.php?t=1037#p14480 provides an example to generate 20MHz square wave at 50% duty on GPIO18 using LEDC library alone.
Being new to the esp32 and C, I tried to make a few changes and made an .ino file from the code:
Code: Select all
include "driver/ledc.h"
void setup() {
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_num = LEDC_TIMER_0,
.bit_num = 2,
.freq_hz = 20000000
};
ledc_channel_config_t ledc_channel = {
.channel = LEDC_CHANNEL_0,
.gpio_num = 18,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_sel = LEDC_TIMER_0,
.duty = 2
};
void loop() {
{
ledc_timer_config(&ledc_timer);
ledc_channel_config(&ledc_channel);
while (1) {
;
}
}
}
Code: Select all
/path/to/esp32-ledc.ino: In function 'void setup()':
esp32-ledc:10:1: error: designator order for field 'ledc_timer_config_t::<unnamed union>::bit_num' does not match declaration order in 'ledc_timer_config_t'
};
^
esp32-ledc:18:1: error: designator order for field 'ledc_channel_config_t::gpio_num' does not match declaration order in 'ledc_channel_config_t'
};
^
/path/to/esp32-ledc.ino: In function 'void loop()':
esp32-ledc:24:24: error: 'ledc_timer' was not declared in this scope
ledc_timer_config(&ledc_timer);
^~~~~~~~~~
/path/to/esp32-ledc.ino:24:24: note: suggested alternative: 'ledc_timer_t'
ledc_timer_config(&ledc_timer);
^~~~~~~~~~
ledc_timer_t
esp32-ledc:25:26: error: 'ledc_channel' was not declared in this scope
ledc_channel_config(&ledc_channel);
^~~~~~~~~~~~
/path/to/esp32-ledc.ino:25:26: note: suggested alternative: 'ledc_channel_t'
ledc_channel_config(&ledc_channel);
^~~~~~~~~~~~
ledc_channel_t
exit status 1
designator order for field 'ledc_timer_config_t::<unnamed union>::bit_num' does not match declaration order in 'ledc_timer_config_t'
Thanks in advance, and have a nice weekend.