That's correct, since the shaft can be in any location on powerup you need to establish the proper encoderstate at bootup and then initialise OldState to the apropriate value depending on the desired direction of rotation - before entering the Main routine. You could do it with something like this but please doublecheck the sequence here, I'm not sure I've got it right.
Code:
'Get index of current encoderstate, Temp will be 0-11
Lookdown EncoderState, [0,1,3,7,15,31,63,62,60,56,48,32],Temp
'Now initialise OldState to correct value depending on desired direction of rotation.
If DesiredDirection = Forward THEN
Lookup Temp, [32,0,1,3,7,15,31,63,62,60,56,48], OldState
ELSE
LookUp Temp, [1,0,7,15,31,63,62,60,56,48,32], OldState
EndIf
Bookmarks