问题:使用TIM4输入捕获时,配置了输入捕获引脚为PB8,通道为IC3,为什么PB9引脚电平变化时能 进入捕获中断? 代码如下,请问什么地方搞错了。 int main(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE); // 使能TIM模块 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //Pb8 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); //TIM通道的捕捉初始化 TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;//通道选择 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;//下降沿 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//管脚与寄存器对应关系 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//分频器 TIM_ICInitStructure.TIM_ICFilter = 0x0; //滤波设置,经历几个周期跳变认定波形稳定0x0~0xF TIM_ICInit(TIM4, &TIM_ICInitStructure); //初始化 TIM_Cmd(TIM4, ENABLE); //启动TIM4 TIM_ITConfig(TIM4, TIM_IT_CC3, ENABLE); //打开中断 NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); while (1) { } } //TIM4捕获中断服务函数 void TIM4_IRQHandler( void ) { if(TIM_GetITStatus(TIM4, TIM_IT_CC3) == SET) { TIM_ClearITPendingBit(TIM4, TIM_IT_CC3); if(CaptureNumber == 0) { //Get the Input Capture value IC4ReadValue1 = TIM_GetCapture3(TIM4); CaptureNumber = 1; } else if(CaptureNumber == 1) { //Get the Input Capture value IC4ReadValue2 = TIM_GetCapture3(TIM4); //Capture computation if (IC4ReadValue2 > IC4ReadValue1) { Capture = (IC4ReadValue2 - IC4ReadValue1); } else { Capture = ((0xFFFF - IC4ReadValue1) + IC4ReadValue2); } //Frequency computation TIM4Freq = (uint32_t) SystemCoreClock / Capture; CaptureNumber = 0; } } |
RE:STM32f103VE,TIM4输入捕获问题
回复:STM32f103VE,TIM4输入捕获问题
回复:STM32f103VE,TIM4输入捕获问题
引脚我已经查过了,没有接错。同样的方法配置TIM3,CH3 CH4就没有这个问题,不解?
我用普通输入捕获功能。