使能通道1TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable)后,CCER寄存器的CC1E位一直在变,大神们有遇到这种情况吗?
TIM1配置:
void TIM_PWM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_InitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM1, ENABLE);
TIM_DeInit(TIM1);
TIM_InitStruct.TIM_Period = period;
TIM_InitStruct.TIM_Prescaler = 0;
TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_InitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1,&TIM_InitStruct);
TIM_ARRPreloadConfig(TIM1,ENABLE);
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStruct.TIM_Pulse = duty;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStruct.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStruct.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStruct.TIM_OCNIdleState = TIM_OCNIdleState_Set;
TIM_OC1Init(TIM1,&TIM_OCInitStruct);
TIM_OC2Init(TIM1,&TIM_OCInitStruct);
TIM_OC3Init(TIM1,&TIM_OCInitStruct);
// TIM_BDTRInitStructure.TIM_OSSRState=TIM_OSSRState_Enable;
// TIM_BDTRInitStructure.TIM_OSSIState=TIM_OSSIState_Enable;
// TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
// TIM_BDTRInitStructure.TIM_DeadTime=0x00;
// TIM_BDTRInitStructure.TIM_Break=TIM_Break_Disable;
// TIM_BDTRInitStructure.TIM_AutomaticOutput=TIM_AutomaticOutput_Enable;
// TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);
// TIM_ClearITPendingBit(TIM1,TIM_IT_CC1);
TIM_Cmd(TIM1,ENABLE);
TIM_CCPreloadControl(TIM1,DISABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
}
|