Searching \ for 'Quadrature Encoder' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/sensors.htm?key=quadrature
Search entire site for: 'Quadrature Encoder'.

Truncated match.
PICList Thread
'Quadrature Encoder'
1998\10\02@031628 by Ing. Andreas Pockberger

flavicon
face
Hi Friends !

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 ?

thanks for all your help
Andreas

1998\10\02@113234 by Bob Blick

face
flavicon
face
Here's what I did:

;16 bit encoder count kept in enc_lo and enc_hi.
;Overspeed error sets bit 0 of variable "errflags"

Gray_code       movf    PORTB, w        ;assuming encoder is on port B
               andlw   b'00000011'     ;pins 0 and 1. mask off others
               movwf   gray_new
               xorwf   gray_old,w      ;compare with old value
               btfsc   STATUS,Z        ;keep going if there's a change
               goto    Gray_out        ;no change, get out

               comf    gray_new,w      ;test for both bits changing
               andlw   b'00000011'     ;that would be an overspeed
problem
               xorwf   gray_old,w      ;and need to be noted
               btfsc   STATUS,Z        ;
               bsf     errflags,0      ;set first bit if error

               bcf     STATUS,C        ;clear carry flag
               rlf     gray_old        ;shift left
               movf    gray_new,w
               xorwf   gray_old,f      ;compare new with shifted old
               btfsc   gray_old,1      ;if second bit is set
               goto    Gray_inc        ;increment counter
Gray_dec        movlw   1
               subwf   enc_lo,f
               btfss   STATUS,C        ;clear flag means borrow
               decf    enc_hi          ;we borrow
               goto    Gray_out
Gray_inc        movlw   1
               addwf   enc_lo,f        ;increment lo byte
               btfsc   STATUS,C        ;test carry flag
               incf    enc_hi          ;carry to hi byte
Gray_out        movf    gray_new,w
               movwf   gray_old        ;prepare for next time

Note that it can be simplified a lot if you don't need the overspeed flag.
I use this routine in a timer-based interrupt running frequently.

Cheers,
Bob

1998\10\05@063905 by Alvaro Deibe Diaz

flavicon
face
I've posted this little routine some time ago. I suppose this is not the
one you write about in your mail. Anyway, here it is. Sorry for the Spanish
comments, but this is a part of a finished project... (I can try to
translate it to a kind of 'english', if you want)

The main idea is to 'cross-xor' both bits of the encoder with the previous
state. This lends to a byte (encod) where you have:
       the previous encoder state (bits 0 and 1) 'rotated'
       two bits that indicate the direction of movement (bits 2 and 3):
               bit 2=1 -> rotate left
               bit 3=1 -> rotate right
               bits 2,3=0 -> no change
               bits 2,3=1 -> overspeed
       previous states of the encoder (bits 4& 5, and bits 6&7). I dont
use this ones, but can be used
               to make some kind of filtering (??)

This routine is in a timer-based interrupt.

Hope this helps.

#define encx    PORTA,1     ; Encoder is in PORTA,
#define ency    PORTA,2     ; pins 1 and 2, i.e.
;
; Rutina para la lectura del encoder.
       clrf    auxint     ;  Borra la variable auxiliar
       btfsc   encx       ; para recoger en ella los dos
       bsf     auxint,0   ; bits del estado actual del
       btfsc   ency       ; encoder ('X' e 'Y')
       bsf     auxint,1
;
       movf    auxint,W   ;  Se hace XOR del estado actu-
       xorwf   encod,F    ; al y el anterior del encoder
;
       rrf     auxint,F   ;  Se guarda el estado actual
       rlf     encod,F    ; en encod, para la proxima vez
       rrf     auxint,F
       rlf     encod,F
;
       btfsc   encod,2    ; Se avanza en la direccion 'X'
       incf    posenc,F
       btfsc   encod,3    ; ...o en la 'Y'
       decf    posenc,F

-----Mensaje original-----
De:     Ing. Andreas Pockberger [SMTP:spam_OUTapockTakeThisOuTspamVIA.AT]
Enviado el:     viernes 2 de octubre de 1998 10:21
Para:   .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU
Asunto: Re: Quadrature Encoder

Hi Friends !

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 ?

thanks for all your help
Andreas


'Quadrature Encoder'
1998\12\08@161910 by Walter Banks
picon face
> 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

1998\12\08@165311 by marbel
picon face
this is mij 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
mabelspamKILLspamxs4all.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

1998\12\09@042151 by Alvaro Deibe

flavicon
face
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 removed}

1998\12\09@181415 by marbel

picon face
      Delivery Failure Report

       Your       Re: Quadrature Encoder
       document:

       was not    MCHP PicList
       delivered
       to:

       because:   Router: Unable to open mailbox file
                  KILAUEA/MICROCHIP TECHNOLOGY INC. mail.box: Unable
                  to find path to server








         Reba/Microchip Technology Inc., Reba/Microchip Technology
         Inc., Reba/Microchip Technology Inc.



                         ________________________


      To:       .....PICLISTKILLspamspam.....MITVMA.MIT.EDU AT
                Internet_Exchange@CCMTA-Chandler
      cc:
      From:     EraseMEmarbelspam_OUTspamTakeThisOuTXS4ALL.NL (M van der Bilt) AT
                Internet_Exchange@CCMTA-Chandler
      Date:     12/08/98 02:54:00 PM
      Subject:  Re: Quadrature Encoder


      this is mij 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
      mabelspamspam_OUTxs4all.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

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...