Higher Motor PWM Frequency?

Stomper
Posts: 16
Joined: Tue Mar 31, 2020 10:33 pm

Higher Motor PWM Frequency?

Postby Stomper » Tue May 26, 2020 7:29 pm

I need a complementary PWM with dead time generation of 150 kHz.

Here is a quality graph of the PWM Signal I need. Duty Cycle needs to be 50 % and frequency 150 kHz.
PWM.png
PWM.png (9.05 KiB) Viewed 4659 times

So I thought I use the MCPWM module for that, but I recognized that the maximum frequency is about 2 kHz.
When going higher the duty cycle is shrinking smaller and smaller.

At my desired frequency of 150 kHz the duty cycle is only about 10 %.

I guess the timer reaches its end or the bits are not enougth. Can I set up a timer with wider bits or crank up the timer frequency to be able to produce a higher motor pwm frequency?

Here is my code:

Code: Select all

	ESP_LOGI(TAG, "Init MCPWM");

	// Link I/Os to MCPWM module channels
	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, HEAT_HS_1);
	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, HEAT_LS_1);
	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1A, HEAT_HS_2);
	mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1B, HEAT_LS_2);

	//2. initialize mcpwm configuration
	mcpwm_config_t pwm_config;
	pwm_config.frequency = 500;    //frequency = 15 kHz
	pwm_config.cmpr_a = 0.0;
	pwm_config.cmpr_b = 0.0;
	pwm_config.counter_mode = MCPWM_UP_COUNTER;
	pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
	mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);   //Configure PWM0A & PWM0B with above settings

	pwm_config.duty_mode = MCPWM_DUTY_MODE_1;
	mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config);   //Configure PWM1A & PWM1B with other duty mode (negation).

    mcpwm_sync_enable(MCPWM_UNIT_0, MCPWM_TIMER_0, 1, 200);
    mcpwm_sync_enable(MCPWM_UNIT_0, MCPWM_TIMER_1, 1, 200);

    MCPWM0.timer[0].sync.out_sel = 1;
    vTaskDelay(100/portTICK_PERIOD_MS);
    MCPWM0.timer[0].sync.out_sel = 0;

    mcpwm_deadtime_enable(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 200, 200);   //Deadtime of 20us
    mcpwm_deadtime_enable(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 200, 200);   //Deadtime of 20us

    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0,  MCPWM_OPR_A, 50);
    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0,  MCPWM_OPR_B, 50);
    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_1,  MCPWM_OPR_A, 50);
    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_1,  MCPWM_OPR_B, 50);
Is there any other possibility to produce a complementary pwm with dead time?

Best regards
Chris

Stomper
Posts: 16
Joined: Tue Mar 31, 2020 10:33 pm

Re: Higher Motor PWM Frequency?

Postby Stomper » Fri May 29, 2020 10:46 am

My workaround at the moment is to change the prescaler of the mcpwm module directly in the idf driver folder:
MCPWM.png
MCPWM.png (45.09 KiB) Viewed 4431 times

However, this is not the best solution as the IDF should not be changed permanently because of updates etc.
But one suggestion: If the DEVs put in a #ifndef / #define a user could define the prescaler with the compiler or elsewhere to setup the frequency prescaler.

Best regards
Chris

stoumk
Posts: 11
Joined: Tue May 24, 2022 10:54 am

Re: Higher Motor PWM Frequency?

Postby stoumk » Wed May 25, 2022 2:56 pm

Stomper wrote:
Fri May 29, 2020 10:46 am
My workaround at the moment is to change the prescaler of the mcpwm module directly in the idf driver folder:
MCPWM.png


However, this is not the best solution as the IDF should not be changed permanently because of updates etc.
But one suggestion: If the DEVs put in a #ifndef / #define a user could define the prescaler with the compiler or elsewhere to setup the frequency prescaler.

Best regards
Hello Chris
How is your project?
Did you get 150kHz at 50% duty?
Have you tried getting 300 kHz?

Who is online

Users browsing this forum: awegel, Bing [Bot], StanInexeon and 112 guests