新手入门
- 积分
- 9
- 金钱
- 9
- 注册时间
- 2021-7-13
- 在线时间
- 1 小时
|
求各位大佬帮忙看一下代码,TIM5时钟不输出pwm,把TIM5全改成TIM3就可以输出了,这是为什么呀
TIM5初始化↓
- void TIM5_Init (u16 arr,u16 psc)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
- TIM_OCInitTypeDef TIM_OCInitStruct;
-
- RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM5 , ENABLE);
- RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO , ENABLE);
-
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init (GPIOA , &GPIO_InitStruct);
-
- TIM_TimeBaseInitStruct.TIM_Period = arr;
- TIM_TimeBaseInitStruct.TIM_Prescaler = psc;
- TIM_TimeBaseInitStruct.TIM_ClockDivision = 0;
- TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit (TIM5 , &TIM_TimeBaseInitStruct);
-
- TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;
- TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OC1Init (TIM5, &TIM_OCInitStruct);
- TIM_OC2Init (TIM5 , &TIM_OCInitStruct);
- TIM_OC1PreloadConfig(TIM5 , TIM_OCPreload_Enable); //使能TIM5在CCR1上的预装载寄存器
- TIM_OC2PreloadConfig(TIM5 , TIM_OCPreload_Enable); //使能TIM5在CCR2上的预装载寄存器
- TIM_ARRPreloadConfig(TIM5, ENABLE); //使能 TIM5 自动重装载的预装载寄存器允许位
- TIM_Cmd(TIM5 , ENABLE); //使能 TIM5
- }
复制代码 主函数↓
- int main ()
- {
- TIM5_Init (3599,599);
- while (1)
- {
- TIM_SetCompare1 (TIM5,500);
- TIM_SetCompare2 (TIM5,500);
- }
- }
复制代码
|
|