完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
GPIO_InitTypeDef GPIO_InitStructure;
tiM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; void TIM1_GPIO_TConfig(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_ResetBits(GPIOA,GPIO_Pin_12); } void TIMx_NVIC_TConfig(void) { NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void TIMx_TConfig(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); TIM_DeInit(TIM1); TIM_TimeBaseStructure.TIM_Period = 1; TIM_TimeBaseStructure.TIM_Prescaler =0; TIM_TimeBaseStructure.TIM_ClockDivision =0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_ITRxExternalClockConfig(TIM1,TIM_TS_ETRF); TIM_ETRClockMode2Config(TIM1,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted, 0); ±ÖÓ´¥·¢Ä£Ê TIM_ClearITPendingBit(TIM1, TIM_IT_Update ); TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE); TIM_SetCounter(TIM1,0); TIM_Cmd(TIM1,ENABLE); TIM_DeInit(TIM3); TIM_TimeBaseStructure.TIM_Period =0xFFFF-1; TIM_TimeBaseStructure.TIM_Prescaler =0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); } void MODE_select(void) { if(modeSlect==MODE_T) { TIM_DeInit(TIM1); TIM_TimeBaseStructure.TIM_Period = 1; TIM_TimeBaseStructure.TIM_Prescaler =0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_ITRxExternalClockConfig(TIM1,TIM_TS_ETRF); TIM_ETRClockMode2Config(TIM1,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted, 0); //TIM_SelectInputTrigger(TIM1, TIM_TS_ETRF); TIM_ClearITPendingBit(TIM1, TIM_IT_Update ); TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);//ÔÊÐí¸üÐÂÖÐ¶Ï ,ÔÊÐíCC1IE²¶»ñÖÐ¶Ï TIM_SetCounter(TIM1,0); TIM_Cmd(TIM1,ENABLE); TIM_DeInit(TIM3); TIM_TimeBaseStructure.TIM_Period =0xFFFF-1; TIM_TimeBaseStructure.TIM_Prescaler =0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); } else if(modeSlect==MODE_D) { TIM_DeInit(TIM1); TIM_TimeBaseStructure.TIM_Period=0xFFFF-1; TIM_TimeBaseStructure.TIM_Prescaler =0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_ITRxExternalClockConfig(TIM1,TIM_TS_ETRF); TIM_ETRClockMode2Config(TIM1,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted, 0); //TIM_SelectInputTrigger(TIM1, TIM_TS_ETRF); TIM_ClearITPendingBit(TIM1, TIM_IT_Update ); TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE); TIM_SetCounter(TIM1,0); TIM_Cmd(TIM1,ENABLE); TIM_DeInit(TIM3); TIM_TimeBaseStructure.TIM_Period =2000; TIM_TimeBaseStructure.TIM_Prescaler =36000-1; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); } } void TIM1_UP_IRQHandler(void) { if(TIM_GetITStatus(TIM1, TIM_IT_Update) == SET) { TIM_ClearITPendingBit(TIM1,TIM_IT_Update); if(MODE_T==modeSlect) { TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); TIM_Cmd(TIM3, ENABLE); if(Index==1) { time_1=flowCount*65535+TIM_GetCounter(TIM3); } if(Index==2) { time_2=flowCount*65535+TIM_GetCounter(TIM3); TIM_SetCounter(TIM3,0); Index=0; flowCount=0; freq=(2*72000000.0/(time_2-time_1)); flag=1; } Index++; } if(MODE_D==modeSlect) { TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); TIM_Cmd(TIM3, ENABLE); Index_1++; } } } void TIM3_IRQHandler(void) { if(TIM_GetITStatus(TIM3, TIM_IT_Update) == SET) { TIM_ClearITPendingBit(TIM3, TIM_IT_Update); if(MODE_T==modeSlect) { flowCount++; } if(MODE_D==modeSlect) { nCount=(u32)TIM_GetCounter(TIM1); TIM_SetCounter(TIM1,0); TIM_ITConfig(TIM1,TIM_IT_Update,DISABLE); freq=65535*Index_1+nCount; Index_1=0; flag=1; } } } |
|
相关推荐
1个回答
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
991 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
970 浏览 2 评论
2080 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1177 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1599 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 05:10 , Processed in 0.741838 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号