初中生
最后登录1970-1-1
在线时间 小时
注册时间2015-5-12
|
本帖最后由 GUANG 于 2015-5-22 09:47 编辑
各位亲们,帮我看看这个程序,我想在定时器更新中断是把两个IO口取反,实现直流电机的翻转,结果电机在颤抖!!!!焦急》》》static void TIM4_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 3800*2;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV2 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM4,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising);
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter=6;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
// Clear all pending interrupts
TIM_ClearFlag(TIM4,TIM_FLAG_Update);
TIM4->CNT = 0;
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
//Reset counter
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
}
一下是中断服务程序:
void TIM4_IRQHandler(void)
{
if(GPIO_ReadOutputDataBit( GPIOC, GPIO_Pin_8))
{
GPIO_ResetBits(GPIOC, GPIO_Pin_8);
GPIO_SetBits(GPIOC, GPIO_Pin_9);
}
else
{
GPIO_ResetBits(GPIOC, GPIO_Pin_9);
GPIO_SetBits(GPIOC, GPIO_Pin_8);
//EXTI_ClearITPendingBit(EXTI_Line0);
}
TIM_ClearITPendingBit(TIM4,TIM_FLAG_Update);
}
|
|