MCPWM - newbie Q

kuchbhi
Posts: 3
Joined: Tue Sep 12, 2017 12:05 pm

MCPWM - newbie Q

Postby kuchbhi » Wed Nov 08, 2017 11:22 am

I am a bit confused with MCPWM api, is Timer 0 associated with MCPWM0A/MCPWM0B and Timer 1 with MCPWM1A/MCPWM1B? I want to control 2 DC motors independently and only able to see output on the pins configured with MCPWM0A/MCPWM0B. Here is my approx code, ripped out from different places but hopefully shows what I am doing wrong....

Code: Select all

    int MOTOR_LEFT_FWD_PIN = 19;
    int MOTOR_LEFT_REV_PIN = 21;
    int MOTOR_RIGHT_FWD_PIN = 22;
    int MOTOR_RIGHT_REV_PIN = 23;

    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, MOTOR_LEFT_FWD_PIN);
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, MOTOR_LEFT_REV_PIN);
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1A, MOTOR_RIGHT_FWD_PIN);
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1B, MOTOR_RIGHT_REV_PIN);

    //2. initial mcpwm configuration
    printf("Configuring Initial Parameters of mcpwm...\n");
    mcpwm_config_t pwm_config;
    pwm_config.frequency = MOTOR_BASE_FREQ;    //frequency = 500Hz,
    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_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
    mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config);    //Configure PWM1A & PWM1B with above settings

    mcpwm_set_signal_low(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A);
    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, duty_cycle);
    mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, MCPWM_DUTY_MODE_0);  

    mcpwm_set_signal_low(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_A);
    mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_B, duty_cycle);
    mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_B, MCPWM_DUTY_MODE_0);  
I see output on pins configured on Timer 0 or MCPWM0A/MCPWM0B but not on MCPWM1A/MCPWM1B.

Thanks

kuchbhi
Posts: 3
Joined: Tue Sep 12, 2017 12:05 pm

Re: MCPWM - newbie Q

Postby kuchbhi » Thu Nov 09, 2017 2:42 pm

Anyone that has been able to get MCPWM1A/MCPWM1B working or should I just stick to LEDC?

pstoaks
Posts: 1
Joined: Tue Jan 02, 2018 4:25 am

Re: MCPWM - newbie Q

Postby pstoaks » Tue Jan 02, 2018 4:44 am

I'm a newbie here too. Just wrote my first ESP32 code a few days ago, so this is the blind leading the blind.

I have not yet tried two different timers yet. In my simple app (https://github.com/pstoaks/esp_projects ... 32_pwm.ino) I have two different duty cycles off of OPRA and OPRB on Timer0. I will try to get some time to try two timers and another set of outputs in my sketch.

Unfortunately, as I'm replying, I can't see your code, but you might try calling mcpwm_start() for timer 1. Also, you could try more completely setting up the OPRA for both timers, which you don't appear to be using.

If you get it working, let me know what you find. As I said, I'll try to make some time to try the 2nd set of outputs.

salocinx
Posts: 8
Joined: Sat Dec 22, 2018 12:54 am

Re: MCPWM - newbie Q

Postby salocinx » Thu Feb 27, 2020 11:04 am

This is still not working. Seems to be a bug in MCPWM/ESP-IDF.

I just filed a bug report on Github
.

Who is online

Users browsing this forum: No registered users and 379 guests