how to read ky40 mechanical encoder ?


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    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 ?

    Thanks Richard,
    Your program compiles well.
    I do have the follwing :

    PROGRAM IS STARTING...

    32009
    32005
    32009
    32013
    32017
    32021
    32033
    32042
    32073
    32113
    32153
    32173
    32197
    32209
    32233
    32257
    32221
    32199
    32161
    32129
    32101
    32065
    32061
    32057
    32053
    32045
    32041
    32040
    32037
    32013
    31999
    31997

    I have changed the encoder too but not working...
    Thanks
    Ambro

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,714


    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

  3. #3
    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 : 0

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