请问一下在使用高级定时器TIM1_CH1N作为PWM输出的时候配置和通用定时器TIMx_CHx有什么区别?我按照原子教程里的PWM输出章节里的配置了PWM以后示波器显示没有PWM输出,代码如下,第一次做PWM 请问各位怎么处理
void TIM1_PWM_Init(void)
{
TIM1_Handler.Instance = TIM1;
TIM1_Handler.Init.Prescaler = 80-1;
TIM1_Handler.Init.CounterMode = TIM_COUNTERMODE_UP;
TIM1_Handler.Init.Period = 500-1;
HAL_TIM_PWM_Init(&TIM1_Handler);
TIM1_OC_Init.OCMode = TIM_OCMODE_PWM1;
TIM1_OC_Init.Pulse = 250;
TIM1_OC_Init.OCPolarity = TIM_OCPOLARITY_LOW;
HAL_TIM_PWM_ConfigChannel(&TIM1_Handler,&TIM1_OC_Init,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&TIM1_Handler,TIM_CHANNEL_1);
}
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
{
GPIO_InitTypeDef GPIO_Initure;
if(htim->Instance == TIM1)
{
__HAL_RCC_TIM1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_Initure.Pin=GPIO_PIN_13;
GPIO_Initure.Mode=GPIO_MODE_AF_PP;
GPIO_Initure.Pull=GPIO_PULLUP;
GPIO_Initure.Speed=GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Alternate=GPIO_AF2_TIM1;
HAL_GPIO_Init(GPIOB,&GPIO_Initure);
}
}
一周热门 更多>