void TIM1_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_Time1BaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); /* Time 定时基础设置*/ TIM_Time1BaseStructure.TIM_Prescaler = 0; TIM_Time1BaseStructure.TIM_CounterMode = TIM_CounterMode_Up; /* Time 定时设置为上升沿计算模式*/ TIM_Time1BaseStructure.TIM_Period = (SystemCoreClock / 40000)-1; TIM_Time1BaseStructure.TIM_ClockDivision = 0; TIM_Time1BaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_Time1BaseStructure); /* 频道1,2,3,4的PWM 模式设置 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable ;//TIM_OutputState_Enable; //PWM输出使能位 TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable ;//TIM_OutputNState_Enable; //互补PWM输出使能位 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //PWM 1为有效电平 TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //PWM互补 0为有效电平 TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_Pulse = 600-1; //赋占空比值 TIM_OC2Init(TIM1, &TIM_OCInitStructure);//使能频道2配置 /* TIM1 计算器使能*/ TIM_Cmd(TIM1, DISABLE); /* TIM1 主输出使能 */ TIM_CtrlPWMOutputs(TIM1, DISABLE);