-
TMR3输入捕获
配置了TMR3定时器输入捕获,但是全速运行会出错,代码如下:TIM_TimeBaseInitTypeDefTIM_TimeBaseInitStructure;TIM_ICInitTypeDefTIM5_ICInitStructure;NVIC_InitTypeDefNVIC_InitStructure;/*开启定时器5时钟*/RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);//使能TIM5时钟TIM_TimeBaseInitStructure.TIM_Period=0xffff;//设置定时器自动重装载值TIM_TimeBaseInitStructure.TIM_Prescaler=71;//以1MHz的频率计数,一次是1μs(微妙)TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;//设置时钟分割:TDTS=Tck_timTIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;//TIM向上计数模式TIM_TimeBaseInit(TIM5,&TIM_TimeBaseInitStructure);//初始化TIM5的时间基数单位TIM5_ICInitStructure.TIM_Channel=TIM_Channel_2;//选择输入端,IC1映射到TI1上TIM5_ICInitStructure.TIM_ICPolarity=TIM_ICPolarity_Rising;//上升沿捕获TIM5_ICInitStructure.TIM_ICSelection=TIM_ICSelection_DirectTI;//映射到TI1上TIM5_ICInitStructure.TIM_ICPrescaler=TIM_ICPSC_DIV1;//配置输入分频,不分频TIM5_ICInitStructure.TIM_ICFilter=0x00;//IC1F=0000,配置滤波器,不滤波TIM_ICInit(TIM5,&TIM5_ICInitStructure);//初始化TIM5输入捕获通道1//中断分组初始化NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;//打开TIM5的全局中断NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//抢占优先级为0NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;//响应优先级为1NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//使能NVIC_Init(&NVIC_InitStructure);TIM_Cmd(TIM3,ENABLE);//使能或者失能TIM5外设TIM_ITConfig(TIM3,TIM_IT_Update|TIM_IT_CC2,ENABLE);//使能或者失能指定的TIM中断
2024-05-11 3