Andreas Pockberger wrote: > The trick is that there are two sensors for each wheel so you will get > 2 impulsstreams out of one wheel the phases are 90 degrees shifted | Reading point V ___ ___ ___ ___ ___ ___ ___ _ Stream A|___| |___| |___| |___| |___| |___| |___| |___| ___ ___ ___ ___ ___ ___ ___ ___ Stream B__| |___| |___| |___| |___| |___| |___| |___| Anti-clockwise <--|--> Clockwise > to make an encoding you have to look which edge comes first and then > you read the second egde depending on the direction one of the egdes > comes before the other one The precise logic expression eludes me at present, but a truth table relating current to previous state goes something like: (A;B) Current: Previous ||(0;0) (0;1) (1;0) (1;1) |+---------------------- (0;0) | NC CW ACW Err NC=No change (0;1) | ACW NC Err CW CW=Clockwise (1;0) | CW Err NC ACW ACW=Anti-clockwise (1;1) | Err ACW CW NC Err=Error (ignored) The error condition where both appear to change at once is a vexed problem. If you presume that it will occur due to slow processing, then you must allow that you have missed the actual direction of that move. In this case it is best to update the "previous" state with the current one, and wait for the next move. This would most likely happen when the encoder is moving rapidly and the next move will at least be registered as the correct direction. For a mouse, this is perfectly reasonable as absolute accuracy is not required in comparison to smooth movement. If OTOH, you presume that a simultaneous change in state on both is a noise (debounce) phenomenon, than it is handled by *not* updating the previous state; when a reasonable "new" state is eventually detected, the movement direction is determined accordingly. This means however that if the encoder really *did* move two steps between polling, the next step will be indicated in the *wrong* direction. Oh well. -- Cheers, Paul B.