实现电机的滑行、正转、反转和制动,通过PWM进行转速调制。驱动逻辑如下:
参考代码:
void MotoStart( uint32_t mode, uint32_t duty )
{ if( mode == MOTO_FORWARD ) { MotoWakeup(); Moto_SetIn2GPIO(0);MotoPWM1_Start();Moto_SetDuty(mode,duty);Moto_SetIn1PWM();}else if( mode == MOTO_REVERSE ) { MotoWakeup();Moto_SetIn1GPIO(0);MotoPWM2_Start();Moto_SetDuty(mode,duty);Moto_SetIn2PWM(); }else if( mode == MOTO_COAST ) {Moto_SetIn1GPIO(0);Moto_SetIn2GPIO(0);//MotoPWM1_TriggerKill();MotoPWM_Stop(); MotoSleep();}else if( mode == MOTO_BRAKE ){ Moto_SetIn1GPIO(1);Moto_SetIn2GPIO(1);MotoPWM_Stop();MotoSleep(); }
}