欢迎来到天天文库
浏览记录
ID:57894352
大小:15.01 KB
页数:5页
时间:2020-09-02
《stm32定时器捕获红外线遥控.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、使用STM32定时器捕获功能获取红外线遥控By四川大学电子信息学院李路长同学Part1:设置定时器3捕获功能#defineTIM3_PRESCALER(72-1)externvolatilefloatTIM3Freq;externvolatileuint32_tTIM3Period;externvolatileuint32_tTIM3Highlen;/*Privatefunctionprototypes-----------------------------------------------*/staticvoidRCC_Configuration(
2、void);staticvoidGPIO_Configuration(void);staticvoidNVIC_Configuration(void);//捕获时特别注意细节,根据不同的算法有不同的捕获方法,uint32_tTimeGap(uint32_ttime1,uint32_ttime2){if(time23、TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;/*SystemClocksConfiguration*/RCC_Configuration();/*NVICconfiguration*/NVIC_Configuration();/*ConfiguretheGPIOports*/GPIO_Configuration();/*TIM3configuration:InputCapturemode---------------------TheexternalsignalisconnectedtoTIM3CH2pin(4、PA.07)TheRisingedgeisusedasactiveedge,TheTIM3CCR2isusedtocomputethefrequencyvalue------------------------------------------------------------*//*TimeBaseconfiguration*/TIM_TimeBaseStructure.TIM_Prescaler=TIM3_PRESCALER;TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;TIM_5、TimeBaseStructure.TIM_Period=0xffff;TIM_TimeBaseStructure.TIM_ClockDivision=0;TIM_TimeBaseStructure.TIM_RepetitionCounter=0;TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);TIM_ICInitStructure.TIM_Channel=TIM_Channel_2;TIM_ICInitStructure.TIM_ICPolarity=TIM_ICPolarity_Falling;TIM_IC6、InitStructure.TIM_ICSelection=TIM_ICSelection_DirectTI;TIM_ICInitStructure.TIM_ICPrescaler=TIM_ICPSC_DIV1;TIM_ICInitStructure.TIM_ICFilter=0x0;TIM_ICInit(TIM3,&TIM_ICInitStructure);/*TIMenablecounter*/TIM_Cmd(TIM3,ENABLE);/*EnabletheCC2InterruptRequest*/TIM_ITConfig(TIM3,TIM_IT_C7、C2,ENABLE);}/***@briefConfiguresthedifferentsystemclocks.*@paramNone*@retvalNone*/staticvoidRCC_Configuration(void){/*TIM3clockenable*/RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);/*GPIOAandGPIOBclockenable*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);}/***@briefCon8、figuretheGPIODPins.*@paramNone*@retvalNo
3、TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;/*SystemClocksConfiguration*/RCC_Configuration();/*NVICconfiguration*/NVIC_Configuration();/*ConfiguretheGPIOports*/GPIO_Configuration();/*TIM3configuration:InputCapturemode---------------------TheexternalsignalisconnectedtoTIM3CH2pin(
4、PA.07)TheRisingedgeisusedasactiveedge,TheTIM3CCR2isusedtocomputethefrequencyvalue------------------------------------------------------------*//*TimeBaseconfiguration*/TIM_TimeBaseStructure.TIM_Prescaler=TIM3_PRESCALER;TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;TIM_
5、TimeBaseStructure.TIM_Period=0xffff;TIM_TimeBaseStructure.TIM_ClockDivision=0;TIM_TimeBaseStructure.TIM_RepetitionCounter=0;TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);TIM_ICInitStructure.TIM_Channel=TIM_Channel_2;TIM_ICInitStructure.TIM_ICPolarity=TIM_ICPolarity_Falling;TIM_IC
6、InitStructure.TIM_ICSelection=TIM_ICSelection_DirectTI;TIM_ICInitStructure.TIM_ICPrescaler=TIM_ICPSC_DIV1;TIM_ICInitStructure.TIM_ICFilter=0x0;TIM_ICInit(TIM3,&TIM_ICInitStructure);/*TIMenablecounter*/TIM_Cmd(TIM3,ENABLE);/*EnabletheCC2InterruptRequest*/TIM_ITConfig(TIM3,TIM_IT_C
7、C2,ENABLE);}/***@briefConfiguresthedifferentsystemclocks.*@paramNone*@retvalNone*/staticvoidRCC_Configuration(void){/*TIM3clockenable*/RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);/*GPIOAandGPIOBclockenable*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);}/***@briefCon
8、figuretheGPIODPins.*@paramNone*@retvalNo
此文档下载收益归作者所有