void TIM4_Configuration(void)
{
u32 temp;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
temp = SystemCoreClock / 1000000;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
TIM_DeInit(TIM4);
if(SystemCoreClock > 36000000)
{
TIM_TimeBaseInitStruct.TIM_Prescaler = 1;
TIM_TimeBaseInitStruct.TIM_Period = PWM_Period * temp / 2;
TIM_OCInitStruct.TIM_Pulse = PWM_Recharge * temp / 2;
}
else
{
TIM_TimeBaseInitStruct.TIM_Prescaler = 0;
TIM_TimeBaseInitStruct.TIM_Period = PWM_Period * temp;
TIM_OCInitStruct.TIM_Pulse = PWM_Recharge * temp;
}
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStruct);
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Disable;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4, &TIM_OCInitStruct);
TIM_OC2Init(TIM4, &TIM_OCInitStruct);
TIM_OC3Init(TIM4, &TIM_OCInitStruct);
TIM_OC4Init(TIM4, &TIM_OCInitStruct);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_CCxCmd(TIM4, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxCmd(TIM4, TIM_Channel_2, TIM_CCx_Enable);
TIM_CCxCmd(TIM4, TIM_Channel_3, TIM_CCx_Enable);
TIM_CCxCmd(TIM4, TIM_Channel_4, TIM_CCx_Enable);
TIM_ARRPreloadConfig(TIM4, ENABLE);
TIM_ClearFlag(TIM4, TIM_FLAG_Update);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM4, ENABLE);
TIM_CCxCmd(TIM4, TIM_Channel_2, TIM_CCx_Disable); //放在这里面起作用
}
。
。
。
TIM4_Configuration();
//期望随时单独失能某一通道,但这样不起作用:
TIM_CCxCmd(TIM4, TIM_Channel_2, TIM_CCx_Disable);
。
。
。 |