Just though this might save you some work ENCODER_INT_HANDLER CLRWDT ; HIT THE DOG MOVF PORTB, W ; GET THE NEW ENCODER DATA MOVWF NEW_ENCDR ; SAVE IT RRNCF OLD_ENCDR ; ROTATE OLD DATA INTO POSITION XORWF OLD_ENCDR, F ; XOR TO GET DIRECTION BTFSC OLD_ENCDR,4 ; WHICH DIRECTION DID IT GO IN? BRA CLOCKWISE ; CLOCKWISE COUNTERCLOCKWISE ; COUNTER CLOCKWISE ... .... INT_EXIT MOVF NEW_ENCDR, W MOVWF OLD_ENCDR ; SAVE NEW ENCODER DATA TO OLD DATA CPFSEQ PORTB BRA ENCODER_ERROR BCF INTCON,0 ; CLEAR CHANGE ON PORT B INTERRUPT FLAG RETFIE FAST ENCODER_ERROR BSF ERROR BCF INTCON,0 ; CLEAR CHANGE ON PORT B INTERRUPT FLAG RETFIE FAST Ive forgotten were A and B were connected to 4&5 I think. I've not included the counting code which is fairly easy. Set up int as change on PORTB (you have to do this or it will not work) 18series only Tim I was wondering if anyone had experience of using an optical encoder (A and B inputs for quadrature mode) on a PIC microcontroller. I'd like to use the A and B output of the optical encoder and tied into PortB and have each pulse (either on A or B) trigger an interrupt. Any help appreciated. Thanks. -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu