Shop OBEX P1 Docs P2 Docs Learn Events
Graycode — Parallax Forums

Graycode

ErikErik Posts: 31
edited 2008-07-23 22:59 in BASIC Stamp
When an input is high and·then an·other input·two times high then i like to start with count up·in a gray code.
Start on "000" then two times i/o 0 high then "001"·and so on.also count down but first count up
so is it easy to make a gray code counter?????

Best regards erik

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-07-23 20:46
    I have no idea what you mean by "input two times high".

    "Gray Code" was created so that when you 'counted' in it, only a single bit would change at a time.
    0 -- 000
    1 -- 001
    2 -- 011
    3 -- 010
    4 -- 110
    5 -- 100
    6 -- 101
    7 -- 111

    For example (which is probably wrong -- 111 goes to 000, but you get the idea). You could google "gray code" or "grey code" to get more detail.
    It turns out this is nice for position encoders.

    Usually, these days, people "count" in binary:
    0 -- 000
    1 -- 001
    2 -- 010
    3 -- 011
    4 -- 100
    5 -- 101
    6 -- 110
    7 -- 111
    So I don't usually see much call for "gray code".
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-07-23 21:01
    Gray code is still very useful, finding application in nearly all absolute encoders. The reason is that, with only one bit changing per step, the transistions between steps are glitch-free. In straight binary, a step from 111 to 000 involves three bit changes. Since it would be impossible to build a mechanical system with enough precision that all three bits changed exactly simultaneously, you could get erroneous states during the transistion. With gray code, you don't have that problem.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • ErikErik Posts: 31
    edited 2008-07-23 21:04
    Hello,

    we like to use the graycode because our monitor software counts in graycode. we use the graycode a lot in the elevator world because he counts right when we change one bit.
    it's to measusre the position off an elevator in the shaft.

    we like to count when he see two times a input because· when the elevator is driving from floor to floor he see two times a switch.

    best regards Erik
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-07-23 22:17
    It is easy to convert a binary count to a Gray code:

    gc=(bn>>1)^ bn ' to convert binary bn to Gray code gc

    The conversion the other direction is little harder, if needed, but there is a description here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ErikErik Posts: 31
    edited 2008-07-23 22:59
    Hello Tracy,



    thanks I will look to it



    best regards Erik
Sign In or Register to comment.