New approach to Rotary Encoder


Closed Thread
Results 1 to 40 of 91

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Hi,
    Since you have the inputs pulled high and the wiper "grounding" each input as it cycles thru them you can't use 1, 2 and 4 as the states since that "looks for" a '1' on the individual pins. You need to use 3, 5 and 6 instead.

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


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Twillight zone ....
    Code:
      Select Case oldState
        Case 3
        If NewState = 6 THEN dir=up         
        If NewState = 5 THEN dir=dn
      
        Case 5
        If NewState = 3 THEN dir=up        
        If NewState = 6 THEN dir=dn
      
        Case 6
        If NewState = 5 THEN dir=up        
        If NewState = 3 THEN dir=dn
      END SELECT
    No matter what I do, portb.1 goes high and low .... portb.0 don't change ....

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Don't know what to tell you but the code works just fine here.
    Code:
    HSEROUT ["Program start",13]
    
    Main:
        PortB.5 = 0
        newState = PortA & %00000111
        PortB.5 = 1
        
        If newState <> 7 THEN
            If newState <> oldState THEN
                  
                Select Case oldState
                    Case 3
                    If NewState = 6 THEN dir=up         
                    If NewState = 5 THEN dir=dn
      
                    Case 5
                    If NewState = 3 THEN dir=up        
                    If NewState = 6 THEN dir=dn
      
                    Case 6
                    If NewState = 5 THEN dir=up        
                    If NewState = 3 THEN dir=dn
                END SELECT
    
                HSEROUT["oldState: ", DEC oldState, "   newState: ", DEC newState, "   DIR: ", DEC DIR, 13]        
            
            oldState = newState
            Pause 1000
            ENDIF
        ENDIF
        
    Goto Main
    This was executed on an AMICUS18 board with a PIC18F25K20. A wire from RB5 to the pulled up inputs was used to simulate the "encoder", the results are here:

    Name:  Fratello_encoder.jpg
Views: 8814
Size:  69.7 KB

    As you can see, it works.

    Have you verified that PortB.5 does go LOW?
    Have you verified that you DO get a LOW on RA0,1 and 2 as you rotate the encoder?
    Have you checked the datasheet to see if any other peripherals are multiplexed onto the pins you're trying to use? ADC? Comparator?

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Been said before and I will say it again.

    NEVER TRUST A SIM!
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    ... ok, so work, despite the "non-working" of simulator !
    Next step is to try to make the two coexist (keypad.bas & encoder.bas) .
    First I will build the schematic and making some tests. Thanks again for the huge support !

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


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    It's this a viable options of reading encoder AND the others buttons ?
    Code:
    Main:
    ;==============
    ;reading buttons on line 0 (pseudo-encoder)
        PortB.5 = 0
        newState = PortA & %00000111
        PortB.5 = 1
        If newState <> 7 THEN
            If newState <> oldState THEN
                  
                Select Case oldState
                    Case 3
                    If NewState = 6 THEN 
                    dir=up         
                    portb.0 = 1
                    endif
                    If NewState = 5 THEN 
                    dir=dn
                    portb.1 = 1
                    endif
                    
                    Case 5
                    If NewState = 3 THEN 
                    dir=up         
                    portb.0 = 1
                    endif      
                    If NewState = 6 THEN 
                    dir=dn
                    portb.1 = 1
                    endif
                    
                    Case 6
                    If NewState = 5 THEN 
                    dir=up
                    portb.0 = 1
                    endif        
                    If NewState = 3 THEN 
                    dir=dn
                    portb.1 = 1
                    endif
                END SELECT      
                oldState = newState
              Pause 100
            ENDIF
        ENDIF
    ;==============
    ;reading buttons on line 1
        Porta.4 = 0
        status_2 = PortA & %00000111
        Porta.4 = 1
        select case status_2
                    case 3
                    gosub trackDn
                    case 5
                    gosub mute
                    case 6
                    gosub trackUp
        end select
    ;==============
    ;reading buttons on line 2    
        Porta.3 = 0
        status_3 = PortA & %00000111
        Porta.3 = 1
        select case status_3
                    case 3
                    gosub volDn
                    case 5
                    gosub volUp
                    case 6
                    gosub Sursa
        end select                           
    Goto Main

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


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    So far, so god ... Now another problem : how can I separates signals?
    If rotary switch is Up, can't read if TK- or V- are pressed ..
    If rotary switch is in middle position, can't read if MUTE or V+ are pressed ...
    If rotary switch is down, can't read if TK+ or S are pressed...


    LE - I think this work :
    Code:
    ;reading buttons on line 1
        Porta.4 = 0
        trisb.5 = 1
        pause 50
        status_2 = PortA & %00000111
        Porta.4 = 1
        trisb.5 = 0
    Attached Images Attached Images  
    Last edited by fratello; - 14th April 2012 at 21:38.

Members who have read this thread : 3

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