-
TMR3输入捕获
配置了TMR3定时器输入捕获,但是全速运行会出错,代码如下:TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; TIM_ICInitTypeDef TIM5_ICInitStructure; NVIC_InitTypeDef NVIC_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_tim TIM_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; //抢占优先级为0 NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; //响应优先级为1 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能 NVIC_Init(&NVIC_InitStructure); TIM_Cmd(TIM3,ENABLE); //使能或者失能TIM5外设 TIM_ITConfig(TIM3, TIM_IT_Update|TIM_IT_CC2, ENABLE ); //使能或者失能指定的TIM中断
1650浏览量 3回复量 关注量