2014-01-09 12:56 AM
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 inputconst GPIOsignal encoderChannelA_port(gpio_mode_GPIO, GPIO_Pin_9, GPIOA, RCC_APB2Periph_GPIOA, GPIO_Mode_AF_OD, GPIO_Speed_10MHz);/// @brief encoder channel B inputconst 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 #stm32f1-encoder-quadrature-timer2014-01-09 03:23 AM
For the F1 series are you sure GPIO_Mode_AF_OD is appropriate for an INPUT? Surely you'd want GPIO_Mode_IN_FLOATING?
2014-01-10 12:57 AM
2014-01-10 03:42 AM
The AF muxing is a bit obtuse on the F1series parts.
Inputs just come from the same schmitt trigger, outputs you have to select if the data source is a GPIO ODR bit, or comes from a peripheral. The USART would be a better example to look at. The SPI is more complicated because the in/out nature of the pin is determined if the SPI is enabled as a Master or Slave, and consequently the control signals to the pin driver are fuller. ie at least 3 signals routed instead of one. You still get to determine OD or PP mode.