[Solved] LEDC Highspeed PWM

BrettG
Posts: 29
Joined: Wed Feb 15, 2017 7:32 pm

[Solved] LEDC Highspeed PWM

Postby BrettG » Thu Mar 23, 2017 6:49 pm

Hi, I am trying to supply a clock signal to a external device at a frequency of at least 10 MHz with the LEDC peripheral. After looking through a lot of the questions and answers on the forum it sounds quite possible, but when I gave it a shot the ESP32 seemed unable to provide a square wave at that high of a frequency. Here is a screen shot of my 10 MHz signal:
10MHZ PWM.PNG
10MHZ PWM.PNG (137.99 KiB) Viewed 13300 times
Here is the setup code I used for the LEDC module with defined values given in comments:

Code: Select all

esp_err_t image_init_clock(void) {
	ledc_timer_bit_t bit_num = (ledc_timer_bit_t) XVCLK_BIT_ACCURACY;		// 3

	// Enable LEDC PWM peripheral
	periph_module_enable(PERIPH_LEDC_MODULE);

	// Set Duty
	int duty = pow(2, (int) bit_num) / 2;

	// setup the timer
	ledc_timer_config_t xvclk_timer;
	xvclk_timer.bit_num = bit_num;						// 3
	xvclk_timer.freq_hz = XVCLK_FREQ;					// 10000000
	xvclk_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
	xvclk_timer.timer_num = LEDC_TIMER_0;
	ledc_timer_config(&xvclk_timer);

	// setup the pwm channel
	ledc_channel_config_t servo_channel;
	servo_channel.channel = LEDC_CHANNEL_0;
	servo_channel.duty = duty;
	servo_channel.gpio_num = IMG_XVCLK;					// GPIO_NUM_4
	servo_channel.intr_type = LEDC_INTR_DISABLE;
	servo_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
	servo_channel.timer_sel = LEDC_TIMER_0;
	ledc_channel_config(&servo_channel);

	// Set the PWM to the duty specified
	ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, duty);
	ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
	
	return ESP_OK;
}
Is there anything wrong in my LEDC config? Is LEDC the correct tool to generate this clock signal, or is there a better option?

Thanks,
- Brett
Last edited by BrettG on Fri Mar 24, 2017 3:31 pm, edited 1 time in total.

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: LEDC Highspeed PWM

Postby Hans Dorn » Thu Mar 23, 2017 6:55 pm

What kind of load was connected to the pin when you took the measurement?

Looks like the output pin is struggling to charge and discharge a capacitive load.

BrettG
Posts: 29
Joined: Wed Feb 15, 2017 7:32 pm

Re: LEDC Highspeed PWM

Postby BrettG » Thu Mar 23, 2017 7:18 pm

When I took that screen shot the only thing that was connected to the pin was a voltage divider (two 1K resistors to step the signal down to ~ 1.8V). Just to check I removed the voltage divider so nothing is on the pin and it still produced the same waveform.

BrettG
Posts: 29
Joined: Wed Feb 15, 2017 7:32 pm

Re: LEDC Highspeed PWM

Postby BrettG » Thu Mar 23, 2017 7:37 pm

I took it a step further, the previous tests were on a new PCB design, so I decided to take that out of the equation and use my ESP_WROOM_32 DevKit. Same result, exact same waveform. Either my setup/config is incorrect, or the device is not capable of this high of a frequency.

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: LEDC Highspeed PWM

Postby Hans Dorn » Thu Mar 23, 2017 7:42 pm

Well, assuming the ESP32 pin will drive @10mA, I'm getting at something in the neighborhood of 150pF to match your waveform.

Are you using a 10:1 probe?


I might be able to borrow a scope over the weekend and have a look at some output waveforms myself...

BrettG
Posts: 29
Joined: Wed Feb 15, 2017 7:32 pm

Re: LEDC Highspeed PWM

Postby BrettG » Thu Mar 23, 2017 8:39 pm

I think I got it. Since you mentioned the 10x option I looked into the probes specs and found:
1x DC-6MHz
10x DC-100MHz

I had it on 1x which was out of spec for the probe.

The new signal with the correct probe settings looks much better:
10MHZ PWM 10x.PNG
10MHZ PWM 10x.PNG (161.34 KiB) Viewed 13283 times
It is still a bit ugly, but a lot of that can be attributed to the sampling rate. The analog discovery is a useful tool but it is no replacement for a real lab oscilloscope.

Anyways this should be more than good enough for my uses.

Thanks a lot for the help.
- Brett

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: LEDC Highspeed PWM

Postby Hans Dorn » Thu Mar 23, 2017 9:17 pm

You're welcome :)

I've been bitten by that one too. An 1x probe is too much of a capacitive load for fast signals.


Cheers

srjasz
Posts: 20
Joined: Wed Apr 03, 2024 4:29 pm

Re: [Solved] LEDC Highspeed PWM

Postby srjasz » Fri Jun 21, 2024 5:32 pm

This will not work on S3 version of esp32. S3 only supports low speed mode. The fastest I have been able to get using low speed mode is 9khz.

ESP_Sprite
Posts: 9288
Joined: Thu Nov 26, 2015 4:08 am

Re: [Solved] LEDC Highspeed PWM

Postby ESP_Sprite » Sun Jun 23, 2024 2:30 am

srjasz wrote:
Fri Jun 21, 2024 5:32 pm
This will not work on S3 version of esp32. S3 only supports low speed mode. The fastest I have been able to get using low speed mode is 9khz.
The S3 doesn't have the distinction between low and high speed anymore; that distinction in general was about having hardware to latch the settings when the PWM ended anyway, it didn't have anything to do with the max speed you can get out of a channel. If you're only getting 9KHz, you're probably doing something wrong.

Who is online

Users browsing this forum: No registered users and 55 guests