定时器如图一样的配置。TIM2为主模式,TIM3为从模式。读取TIM3输出的引脚电平,高电平LED亮,低电平LED灭。这个配置下LED亮一秒灭两秒。是为什么?从模式的定时器计数频率是多少?
void Timer_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period=1999;
TIM_TimeBaseStructure.TIM_Prescaler=35999;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse=1000;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC2Init(TIM2,&TIM_OCInitStructure);
TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_Update);
TIM_Cmd(TIM2,ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period=2;
TIM_TimeBaseStructure.TIM_Prescaler=0;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse=1;
TIM_OC2Init(TIM3,&TIM_OCInitStructure);
TIM_SelectSlaveMode(TIM3,TIM_SlaveMode_Gated);
TIM_SelectInputTrigger(TIM3, TIM_TS_ITR1);
TIM_Cmd(TIM3,ENABLE);
} |