New approach to Rotary Encoder


Closed Thread
Results 1 to 40 of 91

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796

    Default New approach to Rotary Encoder

    Here is an experiment on Rotary Encoders and a different approach than the standard XOR way.

    Code:
    loop1:
    if portb.1=0 then                 'here is switch 1 of the rotary encoder
        counter=counter+1
        goto lcd
    endif
    
    if portb.0=0 then                 'here is switch 2 of the rotary encoder
        counter=counter-1
        goto lcd
    endif
    
    goto loop1
    
    lcd:
    lcdout $fe,$c0,dec5 counter
    while (portb.0=0 or portb.1=0):pause 10:wend
    goto loop1
    The key is the last While/Wend command where it checks for the next pulse comming after the first edge of either switch of the encoder.

    Common of the encoder is Low and Pull Up is supposed to be active.

    Ioannis
    Last edited by Ioannis; - 8th December 2010 at 10:44. Reason: loop is reserved in 2.60 and later

  2. #2
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Can you refresh our memory and show us an example of "the standard XOR way"?

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default

    Two examples in the attachments. They use Interrupts though. When I find some spare time I wll try to make the routines work with IOC and DT-INTS too.

    Ioannis
    Attached Files Attached Files

  4. #4
    Join Date
    Aug 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Did you try this code with mechanical encoder, or normal optical encoder?

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    That was with mechanical one.

    Ioannis

  6. #6
    Join Date
    Aug 2011
    Location
    Manaus - Brazil
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    With use 4 mecanic rotary encoder with this code (pic18f4550) ?

  7. #7
    Join Date
    Nov 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    heckler,
    have a look at this:-

    ' Target PIC : 12F, 16F, 18F
    ' Hardware : Non specific
    ' Oscillator : internal or external
    ' Keywords : ON INTERRUPT
    ' Description : PICBASIC PRO program to demonstrate use of On Interrupt
    ' Interrupts in BASIC. Turn LED on. Interrupt on PORTB.0 (INTE) turns LED off.
    ' Program waits .5 seconds and turns LED back on.

    led Var PORTB.7

    OPTION_REG = $7f ' Enable PORTB pullups

    On Interrupt Goto myint ' Define interrupt handler
    INTCON = $90 ' Enable INTE interrupt

    mainloop:
    High led ' Turn LED on
    Goto mainloop ' Do it forever

    ' Interrupt handler
    Disable ' No interrupts past this point
    myint:
    Low led ' If we get here, turn LED off
    Pause 500 ' Wait .5 seconds
    INTCON.1 = 0 ' Clear interrupt flag
    Resume ' Return to main program
    Enable

    End

    ------------------------
    the main loop runs and when an interrupt happens the program jumps to the handler called myint. does what is in myint and then returns to resume where it left off in the main loop.

    just set the config so your interrupt is enabled that you want to use and put the code to read it in the myint routine. the main loop can do whatever it likes.

    what do you think?

  8. #8
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    @ podgycode... Thanks for your example, but what I meant was I would like to implement a rotary encoder via DT's Instant Interupts. I have used "on interrupt" successfully before to detect push buttons, etc. I have yet to use InstantINT's. I am going to try aratti's example in post #18 above.

    @ aratti... could you please clarify a couple of questions regarding your example...
    ground portB.5 and portB.4
    Why is this necessary?


    Q_New = PortB.7 + PortB.7 + PortB.6
    What does this line of code do??


    TrisA = 000000
    TrisB = 110000
    I assume these need % in front of the binary number??

    I hope this is not considered "hijacking" of this thread... as it still regards implementing Rotary Encoders.
    Thanks for your help




    example
    Last edited by Heckler; - 5th November 2011 at 06:10.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  9. #9
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    @ aratti... one more question

    wsave VAR BYTE $70 SYSTEM ' alternate save location for W
    could you help me with this line? Is it correct or did the forum software mess it up??

    thanks

    P.S. Oh yea... disregard this question... I think I see how it works..
    Q_New = PortB.7 + PortB.7 + PortB.6 What does this line of code do??
    Last edited by Heckler; - 5th November 2011 at 06:33.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  10. #10
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Heckler, yes trisA and trisB need "%" (don't know Why have been removed)

    PortB.4 and portB.5 are set as input and never leave an input pin floating.

    Wsave is a variable used by DT INT-14.


    @Mike K8LH

    The PBP manual they give me with PBP ver 2.47. But you can Find it also at page 168 of PBP3 manual.

    Cheers

    Al.
    All progress began with an idea

  11. #11
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: New approach to Rotary Encoder

    Quote Originally Posted by aratti View Post
    @Mike K8LH

    The PBP manual they give me with PBP ver 2.47. But you can Find it also at page 168 of PBP3 manual.
    I wonder if there may be a problem with the PBP3 manual at http://www.pbp3.com/downloads/PBP_Reference_Manual.pdf? It seems to stop downloading at 731 kB (consistently)... Argh!!!

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