(3)定时器的捕获功用装备流程如下:
流程精简:1、IC装备(设置捕获形式,通道、使能捕获中止)
2、中止向量的嵌套,以及对应的PIO口装备
3、中止服务函数的装备
1、IC装备(设置捕获形式,通道、使能捕获中止)
voidTIM3_Configuration(void) //定时器3初始化;输入捕获设置
{TIM_ICInitTypeDefTIM_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//通道挑选
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//上升沿触发
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//管束与寄存器的对应联系
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //分频器
TIM_ICInitStructure.TIM_ICFilter = 0x0;//滤波设置
TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);//PWM输入形式初始化
//TIM_ICInit(TIM3, &TIM_ICInitStructure);
TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);//挑选时钟触发源
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);//触发方法
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);//发动定时器的被迫触发
TIM_Cmd(TIM3, ENABLE);//发动tim2
TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);//翻开中止
}
2、中止向量的嵌套,以及对应的PIO口装备
void NVIC_Configuration(void)
{NVIC_InitTypeDef NVIC_InitStructure;
//为EXTI_Line9使能并装备中止向量
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置优先级分组:先占优先级2位,从优先级2位
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;//抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;//呼应优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//答应中止
NVIC_Init(&NVIC_InitStructure); //写入设置}
3、中止服务函数的装备
void TIM3_IRQHandler(void)
{
LCD12864_Put_Num(4,0,132454);
TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);//中止的要点,进入后要铲除相应的标志位以跳出中止
i++;
IC2Value=TIM_GetCapture2(TIM3);//捕获的是周期
IC1Value=TIM_GetCapture1(TIM3);//捕获的是高电平
if(i==500)
{i=0;
LCD12864_Put_Num(1,0,72000000/IC2Value);
LCD12864_Put_Num(2,0,72000000/IC1Value);
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/ruanjian/257913.html