频率、占空比设置的相关参数:
(1)TIM_TimeBaseStructure.TIM_Period ====== ARR ------>决定周期
(2)TIM_TimeBaseStructure.TIM_Prescaler ======PSC ------>定时器的分频系数
(3)TIM_OCInitStructure.TIM_Pulse ====== CCR ------>决定占空比
频率F的计算:
F=72M/(ARR+1)*(PSC+1)
占空比D的计算:
D=CCR/(ARR+1)
例如:
u16 ARR = 720-1;//自动重装值
u16 PSC = 0;//时钟预分频系数(始终令PSC=0)
u16 CCR = 360;//待装入捕获比较寄存器的脉冲值
F=100kHz
D=0.5
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
//TIM_CKD_DIV1:设置时钟分频系数,1分频72MHzTdts = 1/72M = 13.89ns
//TIM_