My experience with rotary encoders is that they have two outputs. One click in either direction generates a pulse on both outputs. The timing of those two pulses depends on which direction you are turning the knob. Turn the knob one way and the leading pulse will be on the opposite output from the one where the leading pulse is if you turn the knob in the other direction.
The rotary encoder is on a P24 board meant for PIC processor. This board is connected to another board (P30) on which the ARM processor is attached. I am looking for a code fragment or algorithm to detect rotary encoder turns. I have an infinite while loop which can poll the rotary encoder. Now I am not able to figure out how to detect turns. Do I need to give any patterns to the rotary encoder? Or just monitoring the 2 outputs is sufficient?
The rotary encoder is on a P24 board meant for PIC processor. This board is connected to another board (P30) on which the ARM processor is attached. I am looking for a code fragment or algorithm to detect rotary encoder turns. I have an infinite while loop which can poll the rotary encoder. Now I am not able to figure out how to detect turns. Do I need to give any patterns to the rotary encoder? Or just monitoring the 2 outputs is sufficient?
Monitoring of outputs should be sufficient.
Normally, you would read the phase difference between both square waves – that would be your direction, and then you would count pulses (from any output, X Y or, if available Z) – that would be the rotation.
From the data sheet or the label on the rotary encoder read what is the number of pulses per revolution (100, 360, 1000, ..) and use this number to compare with the pulse-count to calculate the rotation and/or speed ..
:wink:
IanP