I'm trying to move into the STM world and have been able to get familiar with Cube, PRG, and MX. Also been able to get examples of most peripherals operating. I'm stuck on setting up a timer as a quadrature encoder counter. The micro is a STM32G431CBU6. I have an optical quadrature encoder attached with phase A to IN1 and phase B to IN2 with timer 2 set up as follows:
htim2.Instance = TIM2;
htim2.Init.Prescaler = 1;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 60;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
sConfig.IC1Filter = 10;
sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
sConfig.IC2Filter = 10;
I have it set up to roll over at 60 counts which works. I've tried just about every iteration I can and no matter what I do it will only count in one direction. On line searches for examples have not helped. What's wrong?