ESP32 PWM Max frequency output

JKL@122JKL
Posts: 11
Joined: Thu Mar 25, 2021 5:44 am

ESP32 PWM Max frequency output

Postby JKL@122JKL » Thu Mar 25, 2021 5:51 am

Can I know what's the Max ESP32 PWM frequency?
Need to drive 2.7MHz Piezoelectric transducer.

ESP_Minatel
Posts: 361
Joined: Mon Jan 04, 2021 2:06 pm

Re: ESP32 PWM Max frequency output

Postby ESP_Minatel » Thu Mar 25, 2021 11:34 am

Hi,

See the reference documentation in the LED Control section: supported range of frequency and duty resolutions.

Hope this could help you!

JKL@122JKL
Posts: 11
Joined: Thu Mar 25, 2021 5:44 am

Re: ESP32 PWM Max frequency output

Postby JKL@122JKL » Fri Mar 26, 2021 3:18 am

Hi,
Can't MCPWM be used?

ESP_Minatel
Posts: 361
Joined: Mon Jan 04, 2021 2:06 pm

Re: ESP32 PWM Max frequency output

Postby ESP_Minatel » Fri Mar 26, 2021 12:42 pm

Hi,

If you're not going to use for motor control, I recommend you to try the LED Control.

You can try this code to test.

Code: Select all

#include <stdio.h>
#include "driver/ledc.h"
#include "esp_err.h"

#define LEDC_OUTPUT_IO      15 // Output GPIO of a sample 1 Hz pulse generator

static void ledc_init(void)
{
    // Prepare and then apply the LEDC PWM timer configuration
    ledc_timer_config_t ledc_timer;
    ledc_timer.speed_mode       = LEDC_HIGH_SPEED_MODE;
    ledc_timer.timer_num        = LEDC_TIMER_1;
    ledc_timer.duty_resolution  = LEDC_TIMER_4_BIT;
    ledc_timer.freq_hz          = 2700000;  // set output frequency at 2.7 MHz
    ledc_timer.clk_cfg = LEDC_APB_CLK;
    ledc_timer_config(&ledc_timer);

    // Prepare and then apply the LEDC PWM channel configuration
    ledc_channel_config_t ledc_channel;
    ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
    ledc_channel.channel    = LEDC_CHANNEL_1;
    ledc_channel.timer_sel  = LEDC_TIMER_1;
    ledc_channel.intr_type  = LEDC_INTR_DISABLE;
    ledc_channel.gpio_num   = LEDC_OUTPUT_IO;
    ledc_channel.duty       = 8; // set duty at about 50%
    ledc_channel.hpoint     = 0;
    ledc_channel_config(&ledc_channel);
}

void app_main(void)
{
    ledc_init();
}
Attachments
DS1Z_QuickPrint4.png
DS1Z_QuickPrint4.png (39.35 KiB) Viewed 19300 times

JKL@122JKL
Posts: 11
Joined: Thu Mar 25, 2021 5:44 am

Re: ESP32 PWM Max frequency output

Postby JKL@122JKL » Fri Mar 26, 2021 2:19 pm

Thank you.

JKL@122JKL
Posts: 11
Joined: Thu Mar 25, 2021 5:44 am

Re: ESP32 PWM Max frequency output

Postby JKL@122JKL » Tue Apr 20, 2021 2:29 pm

Hi,
I checked with the above code, gives an error: " struct ledc_timer_config_t' has no member clk_cfg

ESP_Minatel
Posts: 361
Joined: Mon Jan 04, 2021 2:06 pm

Re: ESP32 PWM Max frequency output

Postby ESP_Minatel » Tue Apr 20, 2021 5:06 pm

Hi,

Can you confirm the ESP-IDF version that you are using?

JKL@122JKL
Posts: 11
Joined: Thu Mar 25, 2021 5:44 am

Re: ESP32 PWM Max frequency output

Postby JKL@122JKL » Tue Apr 20, 2021 5:57 pm

I was trying with Arduino IDE

ESP_Minatel
Posts: 361
Joined: Mon Jan 04, 2021 2:06 pm

Re: ESP32 PWM Max frequency output

Postby ESP_Minatel » Tue Apr 20, 2021 7:04 pm

For Arduino, you can try this one:

Code: Select all

#define LEDC_CHANNEL_0     0

// use 4 bit precission for LEDC timer
#define LEDC_TIMER_4_BIT  4

// use 2.7MHz Hz as a LEDC base frequency
#define LEDC_BASE_FREQ     2700000
#define LED_PIN            5

void setup() {
  // Setup timer and attach timer to a led pin
  ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_4_BIT);
  ledcAttachPin(LED_PIN, LEDC_CHANNEL_0);
  ledcWrite(LEDC_CHANNEL_0, 7);
}

void loop() {

}

JKL@122JKL
Posts: 11
Joined: Thu Mar 25, 2021 5:44 am

Re: ESP32 PWM Max frequency output

Postby JKL@122JKL » Wed Apr 21, 2021 4:18 am

Thanks,
I've set the duty cycle to 9 for 110KHz(instead of 2.7MHz).
I don't see the transducer turning on.
Circuit of transducer circuit is:
https://www.electroschematics.com/wp-co ... eprint.png
Input Voltage 12V,113KHz Transducer.

Who is online

Users browsing this forum: No registered users and 65 guests