Shop OBEX P1 Docs P2 Docs Learn Events
0 to 1 detection — Parallax Forums

0 to 1 detection

ArchiverArchiver Posts: 46,084
edited 2001-01-24 02:24 in General Discussion
Hello group,
How can 0 to 1 or 1 to 0 transition of input signal be detected?

Thank You
Mohamed Refky
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-01-23 16:03
    This is a snippet from
    "Stamp Applications no. 8 (October ’95):
    Rotary Encoders Help You Program
    a Friendly Spin-and-Grin Interface
    A Digital Dial plus Header-Post Jumpers, by Scott Edwards"
    that I have modified.
    I have not tested yet but it should work:

    ===================
    old var bit

    start:
    old = inX 'old is the initial state
    loop:
    if inX = old then loop: 'if state do not change go looping
    if inX then risetransition: 'if the last state is 1 then are
    a 'rising edge
    falltransition: 'if the last state is 0 then are falling
    edge
    ...dosomething
    goto start: 'repeat

    risetransition:
    ...dosomething
    goto start: 'repeat
    =====================

    ACJacques


    Mohamed REFKY wrote:
    >
    > Hello group,
    > How can 0 to 1 or 1 to 0 transition of input signal be detected?
    >
    > Thank You
    > Mohamed Refky
    > _________________________________________________________________________
    > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-23 23:01
    Use the COUNT command.

    Sid
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-23 23:05
    if pin 1 = 1 then dosomething

    if pin 1 = 0 then dosomething

    Mohamed REFKY wrote:
    >
    > Hello group,
    > How can 0 to 1 or 1 to 0 transition of input signal be detected?
    >
    > Thank You
    > Mohamed Refky
    > _________________________________________________________________________
    > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-24 02:24
    >Hello group,
    >How can 0 to 1 or 1 to 0 transition of input signal be detected?

    Hi Mohamed,

    How about the bitwise XOR logic operator, ^ on the Stamp:

    old var bit ' old state
    new var bit ' new state
    xxx var bit ' transition state

    xxx = old ^ new & new ' xxx = 1 at 0-->1 transition
    if xxx then goDo01thing

    xxx = old ^ new & old ' xxx = 1 at 1-->0 transition
    if xxx then goDo10thing

    The operator (old ^ new) returns 1 if the two values are different,
    or 0 if they are the same. Then the & (bitwise AND) selects
    whichever "edge" you want to see.

    hope that helps...
    -- Tracy Allen
    http://www.emesystems.com
Sign In or Register to comment.