TIM_TimeBaseStructure.TIM_Period=199; //计数器初值
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse=150;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse=150;
则计数0-150为高,151-199为低
----------------------------------------------------
void TIM3_IRQHandler(void)
{
/* TIM3_CH1 toggling with frequency = 183.1 Hz */
if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET) //捕获比较1中断源
{
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1 );
capture = TIM_GetCapture1(TIM3); //获得TIM3输入捕获1的值
TIM_SetCompare1(TIM3, capture + CCR1_Val ); //设置捕获比较寄存器1的值
}
}
===================================================================
用pwm模式输出的频率和占空比是固定的,不可调,要想输出频率可调,占空比可调,必须得使用比较输出模式。这点资料是在STM32全国巡回研讨会上看到的