New approach to Rotary Encoder


Results 1 to 40 of 91

Threaded View

  1. #33
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    No matter what I do, portb.1 goes high and low .... portb.0 don't change ....
    Code:
    TRISB = 000000
    PORTB = 000000 
    
    oldState VAR BYTE
    newState VAR BYTE
    DIR VAR BIT
    
    UP CON 1
    DN CON 0
    
    oldstate = (porta & 000111)
    
    Main_Loop: 
    
    gosub Encoder
    gosub check
    goto main_loop
    
    Check :
    if dir = up then 
    portb.0 = 1
    pause 1000
    portb.0 = 0
    endif
    if dir = dn then
    portb.1 = 1
    pause 1000
    portb.1 = 0
    endif
    return
    
    encoder:
    portb.5 = 1
        pause 100
        newState = (porta & 000111)
    portb.5 = 0
    If newState <> oldState THEN        ' Changed from last time?
      Select Case oldState
        Case 1
        If NewState = 4 THEN dir=up         
        If NewState = 2 THEN dir=dn
      
        Case 2
        If NewState = 4 THEN dir=up        
        If NewState = 1 THEN dir=dn
      
        Case 4
        If NewState = 1 THEN dir=up        
        If NewState = 2 THEN dir=dn
        
      END SELECT
    
    oldstate=newstate
    endif
    Return
    Attached Files Attached Files

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