Encoder problems STM32H743ZI2
Hello,
I have a problem using the LL_TIM_ENCODERMODE_X4_TI12 on a nucleo_H743ZI2 development board. I directly read the counter register (TIM2->CNT for example ) to obtain the encoder value. I do however notice that even though the encoder is not rotating the count value in the register fluctuates as for example:
Sensor value: 1
Sensor value: 0
Sensor value: 0
Sensor value: 1
Sensor value: 1
Sensor value: 1
Sensor value: 0
Sensor value: 0
Sensor value: 65535
Sensor value: 1
Sensor value: 0
Sensor value: 65535
This does also happen at the moment that no encoder is connected to the pins and nothing should happen at all.
Besides that I also notice that counts are missed sometimes when I rotate the encoder and therefore the timer decoder is not as accurate as expected.
I use the same settings as suggested in the Cube IDE:
TIM_InitStruct.Prescaler = 0;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 65535;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM2, &TIM_InitStruct);
LL_TIM_DisableARRPreload(TIM2);
LL_TIM_SetEncoderMode(TIM2, LL_TIM_ENCODERMODE_X4_TI12);
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_DIRECTTI);
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1);
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1);
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_RISING);
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_DIRECTTI);
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1);
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1);
LL_TIM_IC_SetPolarity(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM2);
Help would be very much appreciated to solve this problem!
