香主,急救TIM1上升沿,下降沿同时捕获,只用TIM1_CH3这一个IO口,可以做到吗? NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
TIM_ICInitTypeDef TIM_ICInitStructure; TIM_TimeBaseInitTypeDef TIM_BaseInitStructure;
///////////////////////// //FOR RECEIVE /////////////////////////
//启动TIM1 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_BaseInitStructure.TIM_Period = 0; TIM_BaseInitStructure.TIM_Prescaler = 18 * 2 -1; TIM_BaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV4; TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_BaseInitStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_BaseInitStructure);
//启用ARR的影子寄存器(直到产生更新事件才更改设置) //TIM_ARRPreloadConfig(TIM1, ENABLE);
//Init IO Port GPIOA. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
//GPIO Configuration GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure);
//Enable Time4 Global Interrupt NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
//Init Timer1 CC3 TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; //选择通道1 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //输入上升沿捕获 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //通道方向选择 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //每次检测到捕获输入就触发一次捕获 TIM_ICInitStructure.TIM_ICFilter = 0x8; // TIM_ICInit(TIM1, &TIM_ICInitStructure);
//Init Timer1 CC4 TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; //选择通道1 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //输入上升沿捕获 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //通道方向选择 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //每次检测到捕获输入就触发一次捕获 TIM_ICInitStructure.TIM_ICFilter = 0x8; // TIM_ICInit(TIM1, &TIM_ICInitStructure);
//Select the TIM1 Input Trigger: TI1FP2 【输入触发源选择】 //参考TIM结构图选择滤波后的TI1输入作为触发源,触发下面程序的复位 TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1); // <<香主这里怎么写??
//Enable the CC3 Interrupt Request */ TIM_ITConfig(TIM1, TIM_IT_CC3|TIM_IT_CC4, ENABLE);
//Select the slave Mode: Reset Mode //复位模式-选中的触发输入(TRGI)的上升沿初始化计数器,并且产生一个更新线号 TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);
//Enable the Master/Slave Mode //主从模式选择 TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
//OPEN INPUT capture //TIM_CCxCmd(TIM1,TIM_Channel_3, ENABLE);
//TIM enable counter TIM_Cmd(TIM1, ENABLE);
|