I've posted this little routine several times. ÀIs it the one you ask for? ; ; Encoder read clrf auxint ; Clears auxiliar input var. btfsc encx ; Gets bits 'encx' and 'ency' (encoder bits) bsf auxint,0 ; in auxint (bits 0 and 1) btfsc ency bsf auxint,1 ; movf auxint,W ; Xor's actual and previous encoder xorwf encod,F ; states. Results in encod. ; rrf auxint,F ; Save's actual encoder state (and rotates it) rlf encod,F ; in encod, for the next time. rrf auxint,F rlf encod,F ; ; Right now, bits 2 and 3 of encod keep the encoder's rotate direction: btfsc encod,2 ; Rotates in one direction incf posenc,F btfsc encod,3 ; ...or in the other one. decf posenc,F ; This routine runs in a fixed-time interrupt, with many other things. Don't care too much about the interrupt's frequency. You can detect overspeed when both direction bits are set. The last time I posted this little routine, I put with it a little explanation... but my PC dead last month, and with it all my e-mails. If anyone of you have the previous message, please, repost it. Thanks. Bye. -----Original Message----- From: Walter Banks To: Date: martes, 08 de diciembre de 1998 22:23 Subject: Re: Quadrature Encoder >> a couple of months ago there was a thread about Encoding >> a A-B Decoder,Quadrature Encoder, with the PIC. >> There was one idea with just shifting the the input bits and making >> a compare to decide what action to be done next. >> So my questions who posted this, and can this person pls >> repost it again ? > > >I posted one that compared current state with previous state >some months ago either here or on comp.embeded. Essentially it >was a finite state machine that ran asynchronously to the >incoming quadrate data. The main advantages of it (and Bob Blick's >earlier post as well) is that it requires no signal conditioning for >debouncing the incoming lines and is not execution time critical. > >The decoder software self corrects incoming noise. The >application sees the position indication as toggling between two >adjacent positions with no accumulated error. > > >Walter Banks >