TIM4程序配置如下:
GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Period = 0x1;
TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); // Time base configuration
TIM_TIxExternalClockConfig(TIM4, TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Falling, 0x00);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_SetCounter(TIM4, 0);
TIM_Cmd(TIM4, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
|