Shop OBEX P1 Docs P2 Docs Learn Events
Edge Detection — Parallax Forums

Edge Detection

JTayJTay Posts: 3
edited 2005-12-30 09:15 in BASIC Stamp
Hi, how·to detect leading/falling edge of a pulse using basic stamp?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-12-30 06:45
    JTay -

    There is no easy or automatic way to do it, as far as I know, except that you can realize a 1-0-1 or 0-1-0 transition with PULSIN. If you only want to detect 0-1 or 1-0 then you must do it manually. Here is the basic untested process, although there may be simpler ways of doing it:

    /code

    pulsed_pin pin p0 ' arbitrarily check pin port 0

    First_Status: 'Very first excursion ONLY otherwise use Check_Pin: entry

    curr_status = pulsed_pin 'Save current pin state
    last_status = curr_status 'Dummy last pin state

    Check_Pin: 'Normal entry point

    curr_status = pulsed_pin 'Fetch current pin state
    · IF curr_status <> last_status GOTO pin_change 'Has there been an edge transition?

    GOTO Check_Pin 'No edge transition occured

    Pin_Change: 'Edge transition occured, check which way
    · IF curr_status < last_status GOTO Low_Trans: 'Did it go high to low

    High_Trans: 'Transition was low to high


    trans_state = 1 ' set direction of transition
    GOTO Trans_Occurred 'Prepare to exit

    Low_Trans:


    trans_state = 0 ' set direction of transition

    Trans_Occured: 'Prepare to exit

    last_status = curr_status

    code/

    That should get you started.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 12/30/2005 6:52:16 AM GMT
  • JTayJTay Posts: 3
    edited 2005-12-30 09:15
    thanks a lot Bruce! u have given me a good starting point.

    I was hoping there might be a simple way by using probably polling or interrupts to detect edges, but i think this shd be able to do the job. thks!!
Sign In or Register to comment.