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,624


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Code:
                END SELECT
                oldState = newState
                GOSUB UpOrDn  
                pause 100              ' <--- Have you removed this?
        endif           
        ENDIF

  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

    Mr.Mister_E : Can not put the wiper to GND because of hardware ( http://www.picbasic.co.uk/forum/show...126#post113126 ).
    Mr.Henrik : I remove already this line ; is better but not best.

  3. #3
    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 tried to ad a second check of direction :
    Code:
    loop:
        PortA.1 = 0
        newState = PortA & 011100         ; this is for my hw : 11100 = 28
        pause 50                             ; no matter what I put here : none, @ nop , pause 100 !
            newa = PortA & 011100
        PortA.1 = 1
        If newState <> 28 THEN
            If newState <> oldState THEN
                  
                Select Case oldState
                    Case 12
                    If NewState = 20 THEN 
                            if newa = 24 then dir=up
                    endif        
                    
                    case 12
                    If NewState = 24 THEN 
                            if newa = 20 then dir=dn
                    endif
     
                    
                    Case 20
                    If NewState = 24 THEN 
                            if newa = 12 then dir=up
                    endif  
                    
                    Case 20
                    If NewState = 12  THEN 
                            if newa = 24 then dir=dn
                    endif     
                    
                    Case 24
                    If NewState = 12 THEN
                            if newa = 20 then dir=up
                    endif
                    
                    Case 24
                    If NewState = 20 THEN
                            if newa = 12 then dir=dn
                    endif
    
                END SELECT
                oldState = newstate
                GOSUB UpOrDn 
           endif     
        ENDIF
    But, in this way, any direction I rotate, the command is always "Dir Up" ?! Never goes "down" ...

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    And what does the UpOrDn routine look like?

  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

    This routine should do "Track+" /"Track-" :
    Code:
    UpOrDn:
    if dir=1 then
        PortB.4 = 0
        pauseus 3850
        PortB.4 = 1
        pauseus 3850
        PortB.4 = 0
        pauseus 660
        PortB.4 = 1
    endif
    
    if dir=0 then
        PortB.4 = 0
        pauseus 4450
        PortB.4 = 1
        pauseus 4400
        PortB.4 = 0
        pauseus 660
        PortB.4 = 1
    endif    
    return

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    And what do we have in there, if not delays... They are quite short (8-10ms in total) but it's still possible that that is what's messing with you.
    I don't know what you intended to do with that latest version though, why do you have two cases with the same value, just put the code for both in one.

  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

    This is schematic and code...Maybe I miss something important ...
    Code:
    @ DEVICE pic16F628A, XT_OSC, WDT_OFF, PWRT_ON, BOD_OFF, MCLR_ON, LVP_OFF, PROTECT_ON
    
    include "alldigital.pbp"
       Define   OSC 4           ' 4MHz 
       CMCON = 7                ' Disable on-chip comparator, PORTA in digital mode
    
    
    TrisA = %00011100           ; coloane la RA2, 3, 4 ; randuri la RA1, 0 ,7 
    porta = %00011100
    TRISB = %00000000
    PORTB = %00010000 
    
    oldState VAR BYTE
    newState VAR BYTE
    
    UP CON 1
    DN CON 0
    
    
    loop:
        PortA.1 = 0
        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 = 20 THEN dir=up       
                    If NewState = 24 THEn dir=dn
                    
                    Case 20
                    If NewState = 24 THEN dir=up               
                    If NewState = 12 THEN dir=dn
                   
                    Case 24
                    If NewState = 12 THEN dir=up                       
                    If NewState = 20 THEN dir=dn
                END SELECT
                oldState = newstate
                GOSUB UpOrDn 
           pause 15                    ; time for UpOrDn     
           endif          
        ENDIF
    ;============
    UpOrDn:
    if dir=DN then
        PortB.4 = 0
        pauseus 3850
        PortB.4 = 1
        pauseus 3850
        PortB.4 = 0
        pauseus 660
        PortB.4 = 1
    endif
    
    if dir=UP then
        PortB.4 = 0
        pauseus 4450
        PortB.4 = 1
        pauseus 4400
        PortB.4 = 0
        pauseus 660
        PortB.4 = 1
    endif    
    return
    
    end
    Attached Images Attached Images

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