sTM32 使用TIMx_CH1作为 Tx1F_ED 计数器时钟
扫描二维码
随时随地手机看文章
环境:iar arm 5.3
stm32f103vbt6
使用PA.8 外部输入10Mhz的方波。可从systick中断得到数据4.
4×5000(预分频值)×1000(tick中断时间)=20MHz
属于双边沿检测,一个PA.8个脉冲有2个边沿,所以时钟加倍。
由于使用了TI1F_ED它的结构如下:
voidRCC_Configuration(void){/*SetupSTM32system(clock,PLLandFlashconfiguration)*/SystemInit();/*EnableGPIOA,GPIOCandUSART1clock*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA"RCC_APB2Periph_GPIOC|RCC_APB2Periph_TIM1,ENABLE);}GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOA,&GPIO_InitStructure);voidTIM1_Init(void){TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;TIM_TimeBaseStructure.TIM_Period=65535;TIM_TimeBaseStructure.TIM_Prescaler=5000;TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);TIM_TIxExternalClockConfig(TIM1,TIM_TIxExternalCLK1Source_TI1ED,TIM_ICPolarity_Rising,0);TIM_Cmd(TIM1,ENABLE);}intmain(void){RCC_Configuration();GPIO_Config();TIM1_Init();/*SetupSysTickTimerfor1msecinterrupts*/if(SysTick_Config(SystemFrequency/1000)){/*Captureerror*/while(1);}while(1){}}voidSysTick_Handler(void){staticu32i=0;if(i==0){i=1;gusData=0;TIM_SetCounter(TIM1,0);}else{i=0;gusData=TIM_GetCounter(TIM1);}}