decoding quadrature encoders


Results 1 to 40 of 94

Threaded View

  1. #15
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: decoding quadrature encoders

    you have some isr issues
    1.
    ; Not Necessary for Chips with >2k of Codespace
    ; movwf wsave
    ; swapf STATUS, W
    ; clrf STATUS
    ; movwf ssave
    ; movf PCLATH, W
    ; movwf psave
    ; Not Necessary for Chips with >2k of Codespace what ?
    yet at the end of your isr pclath and status are restored
    all isrs need to save and restore mcu status

    2.
    the chip you are using has more than 1 code pages ,your isr is located in page 0 ,
    pclath should be set accordingly
    USUAL
    ISR BEGIN
    movwf wsave
    swapf STATUS, W
    clrf STATUS
    movwf ssave
    movf PCLATH, W
    movwf psave
    CLRF PCLATH
    YOUR CODE
    .............
    3.
    a RE stream moving clockwise goes phase 1 - 2 - 3 - 4 -1 -2 .......
    where phase 1=00
    2=10
    3=11
    4=01
    your code
    ;check to see if encoder has moved
    movf _enc_old,W ;move enc_old to W
    movwf _enc_tmp ;put W to enc_tmp
    movf _enc_new,W ;move enc_new to W for XOR
    xorwf _enc_tmp,F ;XOR enc_tmp to detect encoder movement
    btfsc _enc_tmp,7 ;if bit is clear, encoder moved.
    goto Continue ;no movement exit isr


    say enc_old=01 ,enc_new=00 ; ie clockwise move
    your xor would yield 0b01000000
    and bit 7 is clear so no move is recorded , wrong it did move .it may also cause the 0 point to creep as direction
    changes occur
    the test should be is the result 0 not is bit7 0

    4. bank sel ?
    your isr forces bank0 the chip has more than one bank available
    all vars used in isr need to be assigned to bank 0
    ie enc_old VAR BYTE bank0 .
    etc
    5. enc_counter a word a non atomic entity
    any non atomic entity that can be changed in an isr and is used outside the isr needs to be handled
    correctly to prevent glitches caused by rollover/under of the low byte.
    best way is to use a buffered copy or that entity
    eg

    enc_counter VAR WORD bank0
    buffered_enc_counter VAR WORD
    gosub get_enc_count


    get_enc_count:
    intcon.3=0 ; rbc_int off
    buffered_enc_counter=enc_counter
    intcon.3=1 ; rbc_int on
    return
    Last edited by richard; - 8th February 2017 at 03:44.
    Warning I'm not a teacher

Similar Threads

  1. Quick thoughts: DT Ints with encoders
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 7th January 2010, 02:01
  2. PMDC SERVO MOTOR WITH quadrature encoder DRIVE ?
    By phoenix_1 in forum Schematics
    Replies: 37
    Last Post: - 22nd November 2009, 20:45
  3. 32-bit Quadrature Counter With Serial Interface
    By precision in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th June 2008, 03:49
  4. quad encoders
    By cpayne in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2007, 18:49
  5. "momentary" IR decoding
    By sporker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 02:53

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts