2019-07-20 11:48发布
正点原子 发表于 2016-10-20 22:15 搞定了么?
arels 发表于 2016-10-19 14:40 void MX_TIM5_Init(uint32_t Prescaler,uint32_t Period) {
最多设置5个标签!
谢谢 已经搞定了
{
TIM_MasterConfigTypeDef sMasterConfig;
TIM_OC_InitTypeDef sConfigOC;
htim5.Instance = TIM5;
htim5.Init.Prescaler = Prescaler;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = Period;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_PWM_DeInit(&htim5);
HAL_TIM_PWM_Init(&htim5);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig);
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 500;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_1);
//HAL_TIM_MspPostInit(&htim5);
HAL_TIM_PWM_Start(&htim5,TIM_CHANNEL_1);//开启PWM通道1
}
//定时器底层驱动,时钟使能,引脚配置
//此函数会被HAL_TIM_PWM_Init()调用
//htim:定时器句柄
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_TIM5_CLK_ENABLE(); //使能定时器5
__HAL_RCC_GPIOA_CLK_ENABLE(); //开启GPIOA时钟
GPIO_Initure.Pin=GPIO_PIN_0; //PA0
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //复用推挽输出
GPIO_Initure.Pull=GPIO_PULLUP; //上拉
GPIO_Initure.Speed=GPIO_SPEED_HIGH; //高速
GPIO_Initure.Alternate= GPIO_AF2_TIM5; //PA0复用为TIM5_CH1
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
}
搞定了么?
一周热门 更多>