MCPWM: "Active low duty" cannot be set - bug or feature?

kivanych
Posts: 5
Joined: Mon Jan 25, 2021 5:59 pm

MCPWM: "Active low duty" cannot be set - bug or feature?

Postby kivanych » Tue Mar 15, 2022 12:28 pm

Hi guys

I am trying to set PWM mode in active Low duty mode.
For this purpose I use MCPWM_DUTY_MODE_1 when configuring the PWM.
For some reason oscilloscope shows me the same diagram as it would be for MCPWM_DUTY_MODE_0 - a "Active high duty" mode.

Is it a bug or I missed something?

Here is the code I use for testing:

Code: Select all


#define GPIO_PWM0A_OUT 27   //Set GPIO 26 as PWM0A
#define GPIO_PWM0B_OUT 26   //Set GPIO 27 as PWM0B
...

    //1. mcpwm gpio initialization
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_PWM0A_OUT);
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, GPIO_PWM0B_OUT);

    //2. initial mcpwm configuration
    mcpwm_config_t pwm_config;
    pwm_config.frequency = 20000;    //frequency = 20000Hz,
    pwm_config.cmpr_a = 0;    //duty cycle of PWMxA = 0
    pwm_config.cmpr_b = 0;    //duty cycle of PWMxb = 0
    pwm_config.counter_mode = MCPWM_UP_DOWN_COUNTER;
    pwm_config.duty_mode = MCPWM_DUTY_MODE_1;
    mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);    //Configure PWM0A & PWM0B with above settings

    mcpwm_set_signal_low(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A);
    mcpwm_set_signal_low(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B);

    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, 50.0);
    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, 10.0);

    mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0);
    mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, MCPWM_DUTY_MODE_0);

tinducvo
Posts: 2
Joined: Thu Feb 02, 2023 4:18 pm

Re: MCPWM: "Active low duty" cannot be set - bug or feature?

Postby tinducvo » Thu Feb 02, 2023 4:20 pm

MCPWM_DUTY_MODE_1 does not work for me either.

tinducvo
Posts: 2
Joined: Thu Feb 02, 2023 4:18 pm

Re: MCPWM: "Active low duty" cannot be set - bug or feature?

Postby tinducvo » Thu Feb 02, 2023 5:12 pm

I fixed it!
If you're using V4.1+, you might want to try MCPWM0A/MCPWM0B instead of MCPWM_OPR_A/MCPWM_OPR_B. Also, when you use mcpwm_set_duty_type, the duty type should be MCPWM_DUTY_MODE_1 as well.

Who is online

Users browsing this forum: Baidu [Spider] and 143 guests