My rotary encoder adventures


Results 1 to 17 of 17

Threaded View

  1. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,159


    Did you find this post helpful? Yes | No

    Default Re: My rotary encoder adventures

    Henrik, inspired by your code. I got down to 6.4 - 8.6us:

    Goes in initialization section:

    Code:
        Enc1_previous = %11111111
        Enc1_Current = %00000000
        Enc1_counter = 0
    MainLoop:

    Code:
    MyLogic:
    
        Enc1_Current = (Enc1_WiperA << 1) + Enc1_WiperB
    
        IF Enc1_Current != Enc1_Previous THEN
            IF Enc1_Current = %00000011 THEN
                IF Enc1_Previous = %00000010 THEN
                    Enc1_counter = Enc1_counter + 1
                ELSE
                    IF Enc1_Previous = %00000001 THEN
                        Enc1_counter = Enc1_counter - 1
                    ENDIF
                ENDIF
            ELSE
                IF Enc1_Current = %00000000 THEN
                    IF Enc1_Previous = %00000001 THEN
                        Enc1_counter = Enc1_counter + 1
                    ELSE
                        IF Enc1_Previous = %00000010 THEN
                            Enc1_counter = Enc1_counter - 1
                        ENDIF
                    ENDIF
                ENDIF
            ENDIF
        ENDIF
        
        Enc1_Previous = Enc1_Current
    
        BlinkLED1 = 0                       ' Bottom of IFs on Logic 2 probe
    
        GOSUB LCDoutput
        
        goto mainloop

    Since my encoder doesn't stop on 01 or 10, I only need to check 11 and 00. Already 3 times faster than my original.


    EDIT: Updated times

    Name:  Encoder probe f.png
Views: 1825
Size:  104.6 KB
    Last edited by Demon; - 20th August 2024 at 01:36.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. Rotary encoder with DT interrupts
    By louislouis in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 21st March 2021, 15:45
  2. Rotary encoder subroutine
    By Fanias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th October 2018, 13:13
  3. Using an incremental rotary encoder?
    By keithv in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2016, 22:23
  4. New approach to Rotary Encoder
    By Ioannis in forum Code Examples
    Replies: 90
    Last Post: - 11th July 2013, 21:05

Members who have read this thread : 11

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