gjj248 发表于 2013-4-19 19:56

stm32占空比的疑惑

stm32中定时器占空比=Pulse/Period,速度与占空比成正比。在Periode不变的情况下,应该Pulse值越大,速度越大;可是我的却是Pulse越小,速度越大,请问是为什么,非常感谢!

TIM_TimeBaseStructure.TIM_Prescaler = 3 - 1;                                  
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned2 ;
TIM_TimeBaseStructure.TIM_Period = 750-1;                                  
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;                
TIM_OCInitStructure.TIM_OutputState= TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;                  
TIM_OCInitStructure.TIM_Pulse = 5;TIM_OCInitStructure.TIM_OCPolarity   = TIM_OCPolarity_High;        
TIM_OCInitStructure.TIM_OCNPolarity= TIM_OCNPolarity_High;         
TIM_OCInitStructure.TIM_OCIdleState= TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;         
TIM_OC1Init(TIM1,&TIM_OCInitStructure);

gjj248 发表于 2013-4-20 17:50

把PWM2改成PWM1就行了

yjhou 发表于 2013-10-16 10:43

请楼主尽快设定最佳答案。
页: [1]
查看完整版本: stm32占空比的疑惑