问答

汇集网友智慧,解决技术难题

21ic问答首页 - TAG - 输入捕获
  • MM32SPIN系统高级定时器输入捕获 没办法进入TIM_CC_IRQH中断

    MM32SPIN系统单片机高级定时器输入捕获 没办法进入TIM_CC_IRQH中断void Remote_1(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);//使能GPIOB时钟 GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_7);//GPIOB4复用为TIM1 //GPIO GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//下拉输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); } void Remote_Init(uint16_t period, uint8_t prescaler) { TIM_TimeBaseInitTypeDef TIM_StructInit; TIM_ICInitTypeDef TIM_ICInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); TIM_TimeBaseStructInit(&TIM_StructInit); TIM_StructInit.TIM_Period = period; TIM_StructInit.TIM_Prescaler = prescaler; TIM_StructInit.TIM_ClockDivision = TIM_CKD_DIV1; TIM_StructInit.TIM_CounterMode = TIM_CounterMode_Up; TIM_StructInit.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_StructInit); //TIM1输入捕获参数设置 TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//CC2S=01 选择输入端 IC2映射到TI1上 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//上升沿捕获 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//映射到TI1上 TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//配置输入分频,不分频 TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_ARRPreloadConfig(TIM1, ENABLE); TIM_ITConfig(TIM1,TIM_IT_CC2 | TIM_IT_Update, ENABLE); TIM_CtrlPWMOutputs(TIM1, ENABLE); TIM_Cmd(TIM1, ENABLE); } void Remote_2(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;//定时中断3 NVIC_InitStructure.NVIC_IRQChannelPriority = 1;//中断优先级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断 NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;//定时中断3 NVIC_InitStructure.NVIC_IRQChannelPriority = 0;//中断优先级 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能中断 NVIC_Init(&NVIC_InitStructure); } void TIM1_BRK_UP_TRG_COM_IRQHandler(void) { if(TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)//溢出中断 { LED3_TOGGLE(); TIM_ClearITPendingBit(TIM1, TIM_IT_Update); //清除TIMx更新中断标志 } } void TIM1_CC_IRQHandler(void) { if(TIM_GetITStatus(TIM1, TIM_IT_CC2) != RESET)//捕获中断 { LED2_TOGGLE(); TIM_ClearITPendingBit(TIM1, TIM_IT_CC2); //清除TIMx更新中断标志 } }

    ni MM32 TI 高级定时器 SPIN 输入捕获

    13680浏览量 8回复量 关注量
  • 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中断

    ni ic TI MR 输入捕获 3输入

    1679浏览量 3回复量 关注量
  • GD32F305VG timer0输入捕获无反应

    各位大佬好! 我按照GD32F30x的标准库配置了GD32F305VG 的timer0定时器并开启了输入捕获功能,配置代码如下: void timer_config(void) { /* ----------------------------------------------------------------------- timer_parameter_struct timer_initpara; timer_ic_parameter_struct timer_icinitpara; rcu_periph_clock_enable(RCU_TIMER0); timer_deinit(TIMER0); /*NVIC config*/ nvic_irq_enable(TIMER0_UP_TIMER9_IRQn, 1, 1); nvic_irq_enable(TIMER0_Channel_IRQn, 1, 0); /* TIMER0 configuration */ timer_initpara.prescaler = 119; timer_initpara.alignedmode = TIMER_COUNTER_EDGE; timer_initpara.counterdirection = TIMER_COUNTER_UP; timer_initpara.period = 999; timer_initpara.clockdivision = TIMER_CKDIV_DIV1; timer_initpara.repetitioncounter = 0; timer_init(TIMER0, &timer_initpara); timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING; timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI; timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1; timer_icinitpara.icfilter = 0x0; timer_input_capture_config(TIMER0, TIMER_CH_0, &timer_icinitpara); timer_input_capture_config(TIMER0, TIMER_CH_3, &timer_icinitpara); /* auto-reload preload enable */ timer_auto_reload_shadow_enable(TIMER0); timer_interrupt_flag_clear(TIMER0,TIMER_INT_FLAG_CH0); timer_interrupt_flag_clear(TIMER0,TIMER_INT_FLAG_CH3); timer_interrupt_enable(TIMER0,TIMER_INT_CH0); timer_interrupt_enable(TIMER0,TIMER_INT_CH3); timer_interrupt_enable(TIMER0,TIMER_INT_UP); timer_enable(TIMER0); } /*中断服务程序*/ void TIMER0_UP_TIMER9_IRQHandler(void) { if ( timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_UP) != RESET ) { timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_UP); timer0tick++; } } void TIMER0_Channel_IRQHandler() { if ( timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH0) != RESET) { timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0); } else if (timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH3) != RESET){ timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH3); rcvcnt++; } } TIMER0 CH0和CH3的GPIO口确定可以正常检测到高低电平,然而软件在运行中,只有更新中断是正常的,输入捕获中断一直触发不了,不知道各位大佬们是否有遇到过此类问题,恳请指点一二,感谢!

    输入捕获 GD32 高级定时器 GD32F305 TIMER0 ic

    3841浏览量 15回复量 关注量