我们引用ST官方给出的F10xStd3.5的库中的TIM>PWM_Output中的例程来举例
可以看出配置pwm参数主要是俩个函数
PrescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 665;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
你的频率f=(SystemCoreClock/(PrescalerValue+1))/Period
f*Period=SystemCoreClock/(Prescaler+1)
当SystemCoreClock取72M时 不妨取Prescaler为71 这样
f=1M/Period
而CRR1_Val是基于Period的占空比