本帖最后由 tanmilaoshu 于 2013-4-15 09:28 编辑
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2|RCC_APB1Periph_TIM3|RCC_APB1Periph_TIM4, ENABLE);
/* Time base configuration */
//这个就是自动装载的计数值
TIM_TimeBaseStructure.TIM_Period = 65535;
// 这个就是预分频系数,当由于为0时表示不分频所以要减1
TIM_TimeBaseStructure.TIM_Prescaler = 0;
// 高级应用本次不涉及。定义在定时器时钟(CK_INT)频率与数字滤波器(ETR,TIx)
// 使用的采样频率之间的分频比例
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
//向上计数
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
//初始化定时器3
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM3,7199,TIM_PSCReloadMode_Immediate);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
//TIM_OCInitTypedef.TIM_Channel=TIM_Channel3;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse=10239;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC3Init(TIM3,&TIM_OCInitStructure);
TIM_Cmd(TIM3, ENABLE);
|