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);
Thanks