用TIM3 接 霍尔传感器;3根霍尔信号异或,霍尔信号跳变,将触发TIM_IT_Trigger 中断;但是实际过程中,不管我怎么转动无刷电机,霍尔信号一直在变化,但是 void TIM3_IRQHandler(void) 中断里,就是没有 TIF 中断标记 即 if(TIM3->SR&0x0040)无法调用; (TIM3中断其他类型的中断是有的,譬如TIM3->SR&0x0010)怎么办啊?, void TIM3_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_DeInit(TIM3); TIM_TimeBaseStructure.TIM_Prescaler = 71; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period =65535; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_TRC ; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 10; TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse =1023; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC2Init(TIM3,&TIM_OCInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; TIM_OCInitStructure.TIM_Pulse =65535; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC4Init(TIM3,&TIM_OCInitStructure); TIM_SelectHallSensor(TIM3,ENABLE); TIM_SelectInputTrigger(TIM3, TIM_TS_TI1F_ED); TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable); TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_OC2Ref ); TIM_ITConfig(TIM3, TIM_IT_Trigger|TIM_IT_CC4, ENABLE); //TIM_Cmd(TIM3,ENABLE); } |
你可以这样,先确定问题一定出现在程序还是在硬件,你先用函数发生器给出一定占空比的脉冲,测试你的程序时不时正确的,如果程序正确,再回个帖,霍尔元件用的时候是要上拉的,不清楚你的电路图,所以。。。。。。。。。。 |