AnsweredAssumed Answered

STM32F1 encoder problem

Question asked by taylor.michael on Jan 9, 2014
Latest reply on Jan 10, 2014 by Clive One
I have a board with an STM32F100 and a quadrature encoder connected to TIM1 channels 1 and 2 PA8 and PA9, the index output is connected to GPIO pin. I have checked the input from the encoder and it is generating the correct pulses. I have set the gpio pins to GPIO_Mode_AF_OD. Unfortunately the timer is not shifting from 0. The index pulse interrupt is working perfectly.

The pins are intitalised thus:




/// @brief encoder channel A input


const GPIOsignal encoderChannelA_port(gpio_mode_GPIO, GPIO_Pin_9, GPIOA, RCC_APB2Periph_GPIOA, GPIO_Mode_AF_OD, GPIO_Speed_10MHz);


/// @brief encoder channel B input


const GPIOsignal encoderChannelB_port(gpio_mode_GPIO, GPIO_Pin_8, GPIOA, RCC_APB2Periph_GPIOA, GPIO_Mode_AF_OD, GPIO_Speed_10MHz);

The actual initialisation code is elsewhere, but it is thoroughly tested.

The timer is intialised thus:


void setupTimer1()
{
  TIM_DeInit(TIM1);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
  TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
  TIM_TimeBaseStructInit(&TIM_TimeBaseInitStruct);


  TIM_TimeBaseInitStruct.TIM_Period = uint16_t(encoderStepsPerRevolution - 1);
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStruct);
  TIM_Cmd(TIM1, DISABLE);


  TIM_EncoderInterfaceConfig(TIM1, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
}

 The encoder object is intialised thus:


void encoderClass::initialise(void)
{
  zeroPosition = 0;
  lastZeroCorrection = 0;
  active = false;
  setupTimer1();
  TIM_Cmd(TIM1, ENABLE);
  TIM_ClearFlag(TIM1, TIM_FLAG_Update);


// Check to see if moving changes the encoder position. If not, we assume the encoder is inactive


  if (motor != 0)
  {
    float encoderPos = getPosition();
    float motorPos = motor->currentPosition;
    motor->moveToPosition(motorPos + 3 * encoderStepSize);
    if (getPosition() != encoderPos)
    {
      active = true;
    }
  }
}

Any help would be much appreciated.

Michael Taylor

Outcomes