Driving motor with MCPWM
Posted: Sun Jan 02, 2022 6:08 pm
Hi, I am trying to learn MCPWM but i cant seem to drive multiple motors at once with a DRV8833
Only 1 motor (MCPWM_UNIT_0 , MCPWM_TIMER_0) runs..
Is there anything wrong with the code?
Only 1 motor (MCPWM_UNIT_0 , MCPWM_TIMER_0) runs..
Is there anything wrong with the code?
Code: Select all
void setup()
{
mcpwm_config_t pwm_config;
pwm_config.frequency = 1000;
pwm_config.cmpr_a = 0;
pwm_config.cmpr_b = 0;
pwm_config.counter_mode = MCPWM_UP_COUNTER;
pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, fl1);
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, fl2);
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1A, fr1);
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1B, fr2);
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config);
}
void loop()
{
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);
mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0);
mcpwm_set_signal_low(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_B);
mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_A, 60);
mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_A, MCPWM_DUTY_MODE_0);
}