STM32F446 how to use rotary encoder with timer?
I have an application I am converting from another processor to a STM32F446 board. The application uses a rotary encoder to detect counts and direction.
I have looked at several videos online on how to use a timer for rotary encoder purposes. I'm beginning to think the timer approach is the wrong way to go.
I am using an optical encoder so contact bounce is not an issue. I started by using a new encoder on the 446 board. However I was getting strange results. So I pulled one of the original encoders from the one of the other processor boards. I see the same results with the encoder that has worked perfectly for years. I get strange counts like 1,4,5,9,13,16,17,20. Also, when I turn the encoder counter clockwise and go past the starting point, I see negative numbers. The encoder is a 32 count PR unit.
In the old application, I had the A and B outputs connected to two pins on the CPU. I used a lookup table that is widely available to determine direction and count. The lookup table is foolproof and looks like this: {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0}. I'm sure users here have seen this solution also.
I need to count each state change as one pulse and determine the direction of the encoder movement. Should I just forget about using the timer for encoder purposes and use two GPIOs with my original code? The timers may be useful for some applications but apparently are not suitable for what I need. If they would work for what I need, could someone point me to a link that shows how to use them?
