how to read ky40 mechanical encoder ?


Closed Thread
Results 1 to 21 of 21

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: how to read ky40 mechanical encoder ?

    the isr counts edges , an indented re has 4 edges per indent . you would expect to increment counter by 4
    don't forget the display routine and the isr are asynchronous .
    if you are trying to count indents then


    Code:
     cnt_f var bit
    
    Main:
      PAUSE 10
    
      IF cnt_f THEN
    
     gosub get_cnt:
         DEBUG DEC counter,13,10
      
      ENDIF
      
    GOTO Main
    
    
    
    
    
    enc_isr:
        ev=ev<<2              ;shift last reading into position
        ev=ev|((portb&48)>>4)  ;read enc pins 4,5  mask off others then  combine this reading with last reading
        LOOKUP (ev&15),[0,255, 1, 0, 1, 0, 0, 255, 255, 0, 0, 1, 0, 1, 255, 0],tmp;lookup the decision matrix
        if tmp then         ; decide to inc , dec or ignore 
            if tmp.7 then
               cnt=cnt-1
               cnt_f=1
            else
                cnt=cnt+1
                cnt_f=1
            endif
        endif
        intcon.0=0                   ; clean up and exit
    @ INT_RETURN
        
    
    
      
    get_cnt :
    intcon.3=0
        counter=cnt/4          
        cnt_f=0 
      intcon.3=1 
    return

  2. #2
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: how to read ky40 mechanical encoder ?

    Richard:
    for each one click ( or detent ) it prints four numbers.
    Thanks
    Attached Files Attached Files

Similar Threads

  1. Question about mechanical relay
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st October 2012, 11:37
  2. Mechanical question
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 11th October 2011, 06:41
  3. Probe to read quadrature encoder with DT_INT need help
    By phoenix_1 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 31st August 2009, 21:43
  4. Mechanical question
    By selbstdual in forum Off Topic
    Replies: 10
    Last Post: - 8th February 2008, 15:34
  5. Replies: 6
    Last Post: - 14th October 2005, 20:41

Members who have read this thread : 1

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