this is my code to do quadrature encoding but shure no state machine I work wih mac pic so most of us will not be able to see the code is i attach it in e mail Greatings Marcel mabel@xs4all.nl Amsterdam ;**************************************************************** ; quadrature.ASM ; ;**************************************************************** ;EQUATES PIC84 equ 0x00 PortA equ 0x05 PortB equ 0x06 Stepx equ 0x0C Rightx equ 0x00 Countx equ 0x0D Stepy equ 0x0E Righty equ 0x01 County equ 0x0F temp equ 0x10 temp2 equ 0x12 F2Posi equ 0x01 Flags2 equ 0x11 Xbit equ 0x05 ; Switch adconvertor to Xinput PortB Ybit equ 0x07 ; Switch adconvertor to Yinput portB ORG 0x05 Table ; tabel to look up previous or next step addwf PCL,f retlw b'00000000' retlw b'00000010' retlw b'00000011' retlw b'00000001' Start clrf PortA ; movlw B'00000010' ; make pin 2 input others output TRIS PortA ; move to tristate register clrf PortB ; movlw B'00000000' ; all pin's on port B output TRIS PortB ; move to tristate register clrf Stepx ; clear step X register clrf Stepy ; clear step Y register clrf TMR0 ; clear timer register clrf temp ; clear temp register movlw 0xff movwf Countx movwf County main btfsc PortA,F2Posi bsf Flags2,F2Posi btfsc PORTB,Xbit ; test xbit= horizontal | goto RightLabel_Y ; if lo goto y = vertical | bcf PORTB,Ybit ; Switch Yinput off | bsf PORTB,Xbit ; Switch Xinput on | ;btfss TMR0,7 ; this gives delay for 2.048 ms ;goto $-1 ;clrf TMR0 goto RightLabel_X