New approach to Rotary Encoder


Closed Thread
Results 1 to 40 of 91

Hybrid View

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

  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

    New code works pretty well ... But, how can I avoid false roller codes ? If I turn up, not always the the code "see" up ; if I turn down, not always the code "see" down ...Sometimes, the commands (Up/Down) are inversed !
    I try to add some "pause" between different commands, but the problem remains.

  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

    No, don't try to slow it down...speed it up. If you have any pauses in there try removing those. If your program is going to do 'other' things as well (which I'm sure it is) then you may need to sample the encoder several times thru out the main loop.

    The reason is because if you are at one state and then turn forward two states but you do it fast enough so that the code doesn't detect the "middle" state, then it looks like you turned one state backwards instead of two forward.

    So, you want to sample the encoder as fast as you can possibly turn it - and then some.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    I try both variants, presented in code, but without major improvements.
    Code:
    ;==============
    ;reading buttons on row 0 (pseudo-encoder)
        PortA.1 = 0
    ;    pause 10
    @   nop
        newState = PortA & %00011100         ; this is for my hw : 11100 = 28
        PortA.1 = 1
        If newState <> 28 THEN
            If newState <> oldState THEN
                  
                Select Case oldState
                    Case 12
                    If NewState = 24 THEN 
                    dir=up         
                    endif
                    If NewState = 20 THEN 
                    dir=dn
                    endif
                    
                    Case 20
                    If NewState = 12 THEN 
                    dir=up         
                    endif      
                    If NewState = 24 THEN 
                    dir=dn
                    endif
                    
                    Case 24
                    If NewState = 20 THEN 
                    dir=up
                    endif        
                    If NewState = 12 THEN 
                    dir=dn
                    endif
                END SELECT
                oldState = newState
                GOSUB UpOrDn  
                pause 100
        endif           
        ENDIF

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


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Which two variants? I only see one in your previous message.
    In that one you have a PAUSE 10 at the beginning, which is commented out, and also a @NOP. Then you have a PAUSE 100 near the end which is NOT commented out.

    /Henrik.

  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

    Sorry...
    "@ nop" ... not good
    and then
    "pause 10" ....idem.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    If you place two 100nF to ground for debouncing false results will be limited.
    Ioannis

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