TIM_SelectOnePulseMode(TIM2,TIM_OPMode_Single);//设置TIM2在单脉冲模式,且是单一的脉冲,在下一个更新事件停止
TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_OC1Ref); //OC1REF signal is used as the trigger output (TRGO).单一模式不需要设置
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);//使能定时器2的通道1预装载寄存器
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;//在向上计数时,一旦TIMx_CNT>TIMx_CCR1时通道1为有效电平
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;//OC1输出使能
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;//有效电平为高
TIM_OCInitStruct.TIM_Pulse = 20;//比较捕获1的预装载值,决定单脉冲占空比,这个20就是低电平延续的来源
TIM_OC1Init(TIM2,&TIM_OCInitStruct);
TIM_Cmd(TIM2,DISABLE); //Enable the TIM Counter