Shop OBEX P1 Docs P2 Docs Learn Events
HP encoder to basic stamp??? — Parallax Forums

HP encoder to basic stamp???

David27David27 Posts: 4
edited 2005-01-25 20:19 in BASIC Stamp
I've got an HP rotary encoder tied to IN1 and IN2 of my homework board.· I read 1's and 0's on the A and B channels·when I rotate the shaft so I think it's working.
Does anyone have a simple code that will allow the count to increase per pulse read when I turn the shaft one direction, then decrease the count when I turn the shaft the other direction?· I'm still new to stamps and am having a tough time figuring it out.
Thanks!

Comments

  • Dave PatonDave Paton Posts: 285
    edited 2004-12-13 15:18
    The encoder you have is called a Quadrature encoder. The direction is derrived from the relationship of the pulses. The way I've usually seen it done is with an XOR and some bitwise math involving the previous state and the current one. Attached is an image of the waveform relationship borrowed from a Grayhill datasheet. When spinning clockwise, A leads B by 90 degrees as noted. Whenever A goes from low to high, if B is low it's clockwise, and if·B is·high it's counterclockwise. If you write that in a nice tight loop, you can increment a counter variable whenever the rotation check statements come up true.

    I've dont it myself a few times, but I don't have the code with me here. I'll see if I can post something tonight. In the meantime, Jon might have something to say too. I vaguely recall he's done some rotary encoder work...

    -dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    This is not a sig. This is a duck. Quack.
    745 x 205 - 15K
    QE.gif 15.4K
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-13 15:23
    I've attached a BS2 program that will read an encoder.· Keep in mind that resolution (turn speed) will be limited by the other things your program has to do, so make sure that the encoder is scanned at the top of the main loop and in between your other tasks.· The demo I wrote is setup to do that.

    Regarding Dave's comment, the other encoder project I did recently was with the SX and the SX/B compiler.· Take a look:

    http://forums.parallax.com/showthread.php?p=519708

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 12/13/2004 3:25:33 PM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-12-13 16:02
    This URL outlines a couple of approaches:
    owlogic.com/BS2fsm.htm#twobit%20encoder

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • David27David27 Posts: 4
    edited 2004-12-13 16:17
    Thanks Jon,
    The program worked although I noticed the encoder has to be turned very slowly or it seems to lose count.
    The encoder I'm using is 512 cpr.
    I may try one that has less resolution.
    Thanks again.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-13 16:26
    Yes, at 512 CPR you will indeed need to turn it very slowly. Mine is 32 CPR and I can actually turn it quite quickly with that BS2 program that is doing nothing but displaying the number.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • lalasonglalasong Posts: 1
    edited 2005-01-25 19:01
    Hello all!

    To join the discussion about the rotary encoders:

    I have a bit of a strange encoder from an SONY minidisc.

    the output is: 0-231-0-231-0-231-0-231-0 This means that it's starting and ending position = 0 (A=0, B=0)

    So I cannot do the XOR trick (or can I???) If I give this encoder 1 click (CW or CCW) it gives '231' to the outputs and then goes to '0' That means that there isn't a position with 1(01) or 2(10) or 3(11) as state, if this encoder is in rest it gives '0'(00)



    Anyone familiar with this kind of encoder?? And know how to handle this??

    I tried several programms even the one with the: lookup old*4+new,[noparse][[/noparse]0,1,-1,0,-1,0,0,1,1,0,0,-1,0,-1,1,0],x··· (This only works when I turn the encoder very slow)



    Best regards,



    Henk Witteveen


  • The Dead BugThe Dead Bug Posts: 73
    edited 2005-01-25 19:29
    I have done a similar thing, only instead of using a rotary encoder, I used two legs of a stepper motor. Running them into op amps I was able to square up the signals and read the phase difference with the stamp to decode direction. Didn't have a particular application, I just wanted to see if I could do it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Name: Bruce Clemens

    Work:· Clemensb@otc.edu
    Bolg: http://theDeadBug.journalspace.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-01-25 19:34
    Bruce,

    ·· I admire that...Trying something out with absolutely no application in mind.· Simply to see if it works...And you never know when that might come in handy.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Buck RogersBuck Rogers Posts: 2,175
    edited 2005-01-25 20:19
    Hello from Buck Rogers
    If it's one of Agilent's RPG. Rotary Pulse Generators, then it outputs serial data in the form of Gray code, not necessarily Quad encoded pulses. I've got three here. Plus the chips that they talk to. However it's an interesting device, you could call it Quadrature, but its really Gray code.

    Gray code was concieved with things like this in mind.·You can state more data with fewer bits. If anyone is really curious, contact me off board, and I'll track down my notes on the subject.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buck Rogers

    www.gregg.levine.name
Sign In or Register to comment.