这样配置为什么进不了中断呢?PWM输出正常,求解救啊,纠结好几天了。
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_ICInitTypeDef TIM_ICInitStruct;
TIM_TimeBaseInitStruct.TIM_ClockDivision=0;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period=65535;
TIM_TimeBaseInitStruct.TIM_Prescaler=8400-1;
TIM_TimeBaseInitStruct.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStruct);
TIM_ICInitStruct.TIM_Channel=TIM_Channel_1;
TIM_ICInitStruct.TIM_ICFilter=0;
TIM_ICInitStruct.TIM_ICPolarity=TIM_ICPolarity_Rising;
TIM_ICInitStruct.TIM_ICPrescaler=0;
TIM_ICInitStruct.TIM_ICSelection=TIM_ICSelection_DirectTI;
TIM_ICInit(TIM1,&TIM_ICInitStruct);
TIM_ClearFlag(TIM1,TIM_IT_CC1);
TIM_ITConfig(TIM1,TIM_IT_CC1,ENABLE);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_PWMIConfig(TIM1,&TIM_ICInitStruct);
TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1);
TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM1,TIM_MasterSlaveMode_Enable);
TIM_Cmd(TIM1,ENABLE);
}
中断函数
void TIM1_IRQn(void)
{
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_SetBits(GPIOA,GPIO_Pin_5);
if(TIM_GetITStatus(TIM1, TIM_IT_CC1) == SET)
{
TIM_ClearITPendingBit(TIM1,TIM_IT_CC1);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8)==SET)//当前为上升沿 改下次触发为下降沿
{
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
TIM_ICInit(TIM1, &TIM_ICInitStructure);
TIM1CH1_U_CAPTURE_VAL= TIM1->CCR1;
}
else
{
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInit(TIM1, &TIM_ICInitStructure);
TIM1CH1_D_CAPTURE_VAL= TIM1->CCR1;
}
if(TIM1CH1_D_CAPTURE_VAL>TIM1CH1_U_CAPTURE_VAL)
{
TIM1CH1_CAPTURE_VAL=TIM1CH1_D_CAPTURE_VAL-TIM1CH1_U_CAPTURE_VAL;
}
else
{
TIM1CH1_CAPTURE_VAL=0XFFFF-TIM1CH1_U_CAPTURE_VAL+TIM1CH1_D_CAPTURE_VAL;
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
我试过开启TIM1_CC_IRQHandler,但是错误提示重定义了!不知道怎么回事,我没有用过TIM1_CC_IRQHandler啊!还有你能看看我配置的正确吗?谢谢啦!
---------------------------------
说明这个函数在其他某个地方被调用了
一周热门 更多>