初级会员
- 积分
- 62
- 金钱
- 62
- 注册时间
- 2016-12-18
- 在线时间
- 6 小时
|
1金钱
void TIM3_PWM_Init(u16 arr,u16 psc)
{
TIM3_Handler.Instance=TIM3;
TIM3_Handler.Init.Prescaler=psc;
TIM3_Handler.Init.CounterMode=TIM_COUNTERMODE_UP;
TIM3_Handler.Init.Period=arr;
TIM3_Handler.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
HAL_TIM_PWM_Init(&TIM3_Handler);
TIM3_CH4Handler.OCMode=TIM_OCMODE_PWM1;
TIM3_CH4Handler.Pulse=arr/2;
TIM3_CH4Handler.OCPolarity=TIM_OCPOLARITY_LOW;
HAL_TIM_PWM_ConfigChannel(&TIM3_Handler,&TIM3_CH4Handler,TIM_CHANNEL_4);
HAL_TIM_PWM_Start(&TIM3_Handler,TIM_CHANNEL_4);
}
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_TIM3_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_Initure.Pin=GPIO_PIN_1;
GPIO_Initure.Mode=GPIO_MODE_AF_PP;
GPIO_Initure.Pull=GPIO_PULLUP;
GPIO_Initure.Speed=GPIO_SPEED_HIGH;
GPIO_Initure.Alternate=GPIO_AF2_TIM3;
HAL_GPIO_Init(GPIOB,&GPIO_Initure);
}
TIM3_PWM_Init(20000-1,108-1);
产生一个50hz的PWM,用来控制舵机的,但是舵机不动
|
|