08-12-2008 09:07 AM
08-12-2008 09:11 AM
08-12-2008 09:14 AM
08-12-2008 09:32 AM
08-12-2008 10:40 AM
08-12-2008 11:48 AM
A state machine might be a good approach here since you have so few positions in your encoder. Let each state read the encoder, and from the encoder value set it to the new state corresponding to the new position. This also allows the rotation to be counterclockwise as well as clockwise.
Example would be with a 2 bit encoder for instance. Assume that each bit change indicates a 30 degree angle change, it might read something like 00=0, 01=30, 11=60, 10=90, 00=120, 01=150, 11 = 180.....
You would have a set of states {0,30,60,90,120,150,180....} and in my example state 90 would read the encoder and if it saw 11 it would know to go to state 60, and if it saw 00 go to state 120. Each state would also update the display correspondingly.
Note that this works only if you can be certain not to miss encoder readings, and if can handle spurius data. (a 01 read in the state 90 example for instance.)