打印

定时器里的门控模式有很大疑问!求解!!

[复制链接]
1773|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wukon|  楼主 | 2013-8-5 14:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
定时器如图一样的配置。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);
}
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

11

帖子

0

粉丝