步进电机上用了一个HEDS-5540编码器,400CPR,也就是每圈400个脉冲,现在遇到的问题是每圈只有24个脉冲,主要程序如下:
//TIM3, CH1+CH2 -> PA6+7
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_TimeBaseStructInit(&TIM_Base);
TIM_Base.TIM_Prescaler = 72-1;
TIM_Base.TIM_CounterMode = TIM_CounterMode_Up;
TIM_Base.TIM_Period = 0xffff;
TIM_TimeBaseInit(TIM3, &TIM_Base);
TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Falling, TIM_ICPolarity_Falling);
TIM_SetCounter(TIM3, 0);
TIM_Cmd(TIM3, ENABLE);
在串口里返回(TIM3->CNT),用手把电机转一圈,计数才增加24,反转是-24.求解? |