配置通用定时器Tim2 . 使用复用功能(PWM输出),查知要控制我板子的一个LED。其为PA3针脚。查看数据手册得知应该使用Tim2 的CH4/PA3 ,部分重映像1
void PWM_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap1_TIM2,ENABLE); //部分重映像使能。
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //使用系统时钟
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseStructure.TIM_Prescaler = 0; //不预分频
TIM_TimeBaseStructure.TIM_Period = 999; //
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; // 输出模式 PWM1和PWM2两种模式灯的效果不同
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse =700; //占空比参数
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC4Init(TIM2,&TIM_OCInitStructure);
TIM_ARRPreloadConfig(TIM2,ENABLE);
TIM_Cmd(TIM2,ENABLE);
}
改变TIM_Pulse占空比参数,感觉灯光亮度并没变化,请问那里少配置了还是配错了???? |