The two signals are 90 degrees out of phase in relation to each other. This is what it looks like:

When the encoder is rotating "forward" (ie you're going left to right in the above picture) channel B is low at the rising edge of channel A. When the encoder is rotating "backwards" (ie you're going right to left in the above picture) channel B is high at the rising edge of channel A. So, you need to detect when channel A goes from low to high and then read channel B.
Code:
WHILE ChannelA_Input = 1 : WEND ' Wait for channel A to go low if it happens to be high
WHILE ChannelA_Input = 0 : WEND ' Now wait for the rising edge of channel A
Direction = ChannelB_Input ' If channel B is high we're moving in one direction, if it's low we're moving in the other
The above code obviosuly presents a risk of hanging if the velocity happens to be 0 or very low but you get the idea.
/Henrik.
Bookmarks