Hi

Very simple actually. I do this in the ISR routine.
- Interupts on PORTB changes
- encoder A on RB7  (chages here trigger the ISR)
- encoder B on RB1
- weak pullups
- 100n c over the encoder A and B connections for debouncing

flags is a file register, I set corrsponding bits (rotate_right and
rotate_left) in the ISR
The main code looks at these values when appropriate

the trick is to monitor for a hi-lo transition on A. if, at the same moment,
B = 0 the encoder is rotated left (or right, depending on your definition of
'A' and 'B'). if at the same moment B = 1 the encoder is rotated in the
other direction.


Regards,
Minto Witteveen.

:
;============================= PORTB Changes
=======================================
;
test_RBIF
    btfss INTCON, RBIF  ; test PORTB changes
    goto exit_intr             ; goto next test (now: exit)

    movf PORTB,W         ; reset latch
    movwf b_latch
    xorwf old_b_latch,w   ; check for changed bits
    movwf check_b
    movf b_latch,w
    movwf old_b_latch
;
; check for status change
;
    btfss check_b,7                             ; if set, RB7 has changed -
now check RB1
    goto exit_portb_changed               ; RB7 Not changed, so not
triggered by rotary encoder
    btfsc b_latch, 7                             ; only action on hi-lo
transfer
    goto exit_portb_changed              ; go away!

    btfss b_latch, 1                             ; this is the value of RB1
    goto left
    bsf flags, rotate_right
    goto exit_portb_changed
left
    bsf flags, rotate_left

exit_portb_changed
    bcf INTCON, RBIF                          ; clear the flag
... rest of ISR


----- Original Message -----
From: "Simon-Thijs de Feber" <stdf23173@YAHOO.CO.UK>
To: <PICLIST@MITVMA.MIT.EDU>
Sent: Thursday, January 04, 2001 2:43 PM
Subject: [EE]: Rotary Encoder


> Hello All,
>
>
> i'd like to connect a rotary encoder to a 16F84.
> I know i can use the RB4-7 inputs (interrupt on
> change), but my bournce rotary encoder has different
> behaviour than expected.
>
> Between 2 dents (clicks) it goes through the following
> bit pattern :
>
> Output A 0 1 1 0 0
> Output B 0 0 1 1 0
>
> where in the A= 0 and B= 0 are the in rest positions.
>
> Is my pic at 10MHZ hast enough to capture this
> pattern, count and put some I2C on other pins ???
>
> How do i capture the pattern anyway (without
> disturbance/bounce and etc) ????
>
>
> best regards,
>
> Simon
>
> ____________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
> or your free @yahoo.ie address at http://mail.yahoo.ie
>
> --
> http://www.piclist.com hint: The PICList is archived three different
> ways.  See http://www.piclist.com/#archives for details.
>
>
>

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.