Shop OBEX P1 Docs P2 Docs Learn Events
Reading of rotary encoders , how to ? — Parallax Forums

Reading of rotary encoders , how to ?

tobon48tobon48 Posts: 22
edited 2006-03-25 23:57 in BASIC Stamp
Hi !

I want to read the output for rotary encoders but I am not sure how.

regards
tobon48

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


Quidquid latine dictum sit, altum sonatur.

Whatever is said in Latin sounds profound.


Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-21 13:33
  • tobon48tobon48 Posts: 22
    edited 2006-03-21 15:04
    Hi !

    Thank you very much, I think it will solve my problem . ( Other good things there !)

    Regards
    tobon48

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Quidquid latine dictum sit, altum sonatur.

    Whatever is said in Latin sounds profound.


  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-22 00:52
    Here's another clip of code which may help you.· This was used to set the temperature on a device.· So the value being affected is called, "setTemp".· A subroutine also displays this information on a display, but that part is not included here.· The MIN 450 and MAX 550 are optional and in this application limited the selectable range to 450 - 550 degrees.· newBits·and oldBits are NIB and setTemp can be whatever size you need.
    Read_Encoder:
      newBits = INA & %0011
      oldBits = newBits
      DO
        newBits = INA & %0011               ' Get State Of I/O Pins 0, 1
        IF newBits <> oldBits THEN          ' Have Bits Changed?
          setTemp = setTemp - 1 + (2 * (newBits.BIT0 ^ oldBits.BIT1)) MIN 450 MAX 550
          GOSUB Show_Temp
          oldBits = newBits                 ' Update oldBits
        ENDIF
      LOOP
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • tobon48tobon48 Posts: 22
    edited 2006-03-22 13:28
    Hi !

    @Chris

    How can I determin which way the encoder goes ? or do you just want to show me the handling of bits ?

    regards
    tobon48

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Quidquid latine dictum sit, altum sonatur.

    Whatever is said in Latin sounds profound.


  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-22 15:59
    The attached code shows a more verbose version which has a variable for direction.· I hope this helps you.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • tobon48tobon48 Posts: 22
    edited 2006-03-22 17:00
    Hi !

    I have tested and it worked fine, but I dont really understand the logic of the math. I have to read more about rotary encoders and PJ Allens exellent link.

    regards
    tobon48

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Quidquid latine dictum sit, altum sonatur.

    Whatever is said in Latin sounds profound.


  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-22 18:16
    The variable direction is a bit variable, so in one direction that will be a 0 and the other it will be a 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cdragoncdragon Posts: 5
    edited 2006-03-25 23:57
    Thanks, I've been looking for this information too.
Sign In or Register to comment.