用于捕获高电平的时间。
定时器1用于定时,用T2作为捕获功能。初始化如下,用PD4作为捕获输入通道
GPIO_Init(GPIOD, GPIO_PIN_4, GPIO_MODE_IN_PU_NO_IT);//PD4-CH1,PD3-CH2
TIM2_DeInit();
/* 通道1,上升沿,映射在T2通道CH1,8分频,无滤波 */
TIM2_ICInit(TIM2_CHANNEL_1, TIM2_ICPOLARITY_RISING, TIM2_ICSELECTION_DIRECTTI, TIM2_ICPSC_DIV8, 0x00);
TIM2_ITConfig(TIM2_IT_CC1, ENABLE);
TIM2_ClearFlag(TIM2_FLAG_CC1);
//TIM2_CCxCmd(TIM2_CHANNEL_1, ENABLE);
TIM2_Cmd(ENABLE);
中断中
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
//TIM2_ClearITPendingBit(TIM2_IT_CC1);
Sys.Capture = TIM2_GetCapture1();
TIM2_ClearFlag(TIM2_FLAG_CC1);
然后发现Sys.Capture一直在变化。是不是读取数据后要清掉?没清会 一直在原先捕获的数据上增加 |