This is a multi-part message in MIME format. ------=_NextPart_000_011A_01C11C26.6A586F00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit To all who provided advice on interfacing a rotary encoder: Thanks very much, I got it working OK now! The attached is the code fragment to detect movement and direction of an encoder. The key was the realisation that although these things bounce a lot, you can start processing at the first change of state, and ignore the debounce as long as you take care not to poll that encoder again within the next 5 mS or so. After that time, the bouncing has stopped and it can be polled again. Cheers, Jan Didden ------=_NextPart_000_011A_01C11C26.6A586F00 Content-Type: text/plain; name="encoder.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="encoder.txt" ;--------System design notes------------------------------------- ; ; The encoders output a 2-bit value: ; the A-bit is used to detect rotation, ; the B-bit is used to determine direction of rotation. ; encoder movement is detected by polling PORTB. ; =09 ; --------------------->cw ; channel A ___ ___ ___ [channel A leads channel B] ; ___| |___| |___| ; ; channel B ___ ___ ___ ; |___| |___| |___| ; ; ; CCW<------------------------------ =09 ; ; channel A ___ ___ ___ [channel A trails channel B] ; ___| |___| |___| ;=20 ; channel B ___ ___ ___ ; __| |___| |___| ; ; A-bit B-bit Direction ; 0>1 0 CW ; 1 CCW ; 1>0 0 CCW ; 1 CW ;NewEncCmd holds the latewst polled PORTB inputs ;CurEncCmd holds the previously polled PORTB inputs ;There are 4 encoders, with the A-bits connected to PORTB and the A-bits = to EncDirPort ;ProgA is one of the encoders we decode below ProcEncInput ;decode encoder movfw NewEncCmd ;new setting xorwf CurEncCmd,W ;previous setting, W now has changed bits set movwf EncChanges btfsc EncChanges, ProgA ;prog enc change? goto ProcProg ;yes, process it goto ExEncInput ProcProg btfss NewEncCmd,ProgA ;if 1, was 0>1 goto ProgFall ProgRise =09 btfss EncDirPort,ProgB ;if 0, was CW goto ProgCW goto ProgCCW ProgFall =09 btfss EncDirPort,ProgB ;if 0, was CCW goto ProgCCW goto ProgCW ProgCCW =09 ;do the processing work here goto EncUpdate ProgCW ;do the processing work here =09 EncUpdate movfw NewEncCmd movwf CurEncCmd ;update present enc positions ExEncInput return ------=_NextPart_000_011A_01C11C26.6A586F00-- -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body