问答

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

小迷糊523

TA的家园币:12  

  • MM32F103定时器PWM输入捕获失败

    配置代码如下,有个PWM信号需要输入捕获计算频率,经查询数据手册PB11可以复用为TIM2_CH4,但怎么配置都不能正常进捕获中断,IC和PWM方式都试了不行,想问各位大佬该配置有啥问题,有没有什么解决办法/*功能名称IM4_PWMINPUT_INIT(u16arr,u16psc)描述PWM输入初始化*/voidTIM2_PWMINPUT_INIT(u16arr,u16psc){TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;NVIC_InitTypeDefNVIC_InitStructure;TIM_ICInitTypeDefTIM2_ICInitStructure;GPIO_InitTypeDefGPIO_InitStructure;RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);//OpenTIM4clockRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//opengpioBclockGPIO_PinRemapConfig(GPIO_PartialRemap2_TIM2,ENABLE);GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStructure);/*配置中断优先级*/NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;NVIC_Init(&NVIC_InitStructure);TIM_TimeBaseStructure.TIM_Period=arr;//设置在下一个更新事件装入活动的自动重装载寄存器周期的值TIM_TimeBaseStructure.TIM_Prescaler=psc;//设置用来作为TIMx时钟频率除数的预分频值TIM_TimeBaseStructure.TIM_ClockDivision=0;//设置时钟分割:TDTS=Tck_timTIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//TIM向上计数模式TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);//根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位TIM2_ICInitStructure.TIM_Channel=TIM_Channel_4;TIM2_ICInitStructure.TIM_ICPolarity=TIM_ICPolarity_Rising;TIM2_ICInitStructure.TIM_IC