diff --git a/Code/bsp/inc/bsp_motor.h b/Code/bsp/inc/bsp_motor.h index 8ba7620..9adf93d 100644 --- a/Code/bsp/inc/bsp_motor.h +++ b/Code/bsp/inc/bsp_motor.h @@ -17,6 +17,6 @@ void bsp_BIN1_OFF(void); void bsp_BIN2_ON(void); void bsp_BIN2_OFF(void); -void PWM_SetCompare3(uint16_t Compare); +void bsp_changeMotorSpeed(uint16_t Compare); #endif diff --git a/Code/bsp/src/bsp_motor.c b/Code/bsp/src/bsp_motor.c index 5f66547..1b01189 100644 --- a/Code/bsp/src/bsp_motor.c +++ b/Code/bsp/src/bsp_motor.c @@ -25,7 +25,7 @@ #define TIM_MOTOR_PERIPH_RCC RCC_APB1Periph_TIM2 #define TIM_MOTOR_PWN_GPIO_RCC RCC_APB2Periph_GPIOA #define TIM_MOTOR_PWN_GPIO_PORT GPIOA -#define TIM_MOTOR_PWN_GPIO_PIN GPIO_Pin_2 +#define TIM_MOTOR_PWN_GPIO_PIN GPIO_Pin_1 /************************************************************************************* * @brief 对外输出至电机驱动板IN接口的GPIO初始化 @@ -79,7 +79,7 @@ void bsp_InitGPIO_MotorOut(void) /* 1. 使能TIM时钟 */ RCC_APB1PeriphClockCmd(TIM_MOTOR_PERIPH_RCC, ENABLE); /* 2. 使能对应的GPIO引脚 */ - GPIO_Init(TIM_MOTOR_PWN_GPIO_PORT, &GPIO_InitStructure); //初始化 GPIOA.2 + GPIO_Init(TIM_MOTOR_PWN_GPIO_PORT, &GPIO_InitStructure); //初始化 RCC_APB2PeriphClockCmd(TIM_MOTOR_PWN_GPIO_RCC, ENABLE); //使能 PA 端口时钟 GPIO_InitStructure.GPIO_Pin = TIM_MOTOR_PWN_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; @@ -96,11 +96,12 @@ void bsp_InitGPIO_MotorOut(void) TIM_TimeBaseInit(TIM_MOTOR, &TIM_TimeBaseStructure); /* 5. 输出比较 */ TIM_OCStructInit(&TIM_OCInitStructure); - TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; - TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; - TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; - TIM_OCInitStructure.TIM_Pulse = 0; //CCR - TIM_OC3Init(TIM_MOTOR, &TIM_OCInitStructure); + TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; // PWM模式1(CNT