BasicStampClockInput

Discussion in 'Embedded Systems and Microcontrollers' started by mpuvdd, Mar 13, 2007.

  1. mpuvdd

    Thread Starter Active Member

    Feb 11, 2007
    50
    0
    Hello all,
    I've looked extensively hard into figuring out how to make a BS2 sense a clock signal (1 to 0 or 0 to 1)on one of its I/O pins rather than the pin's individual logic state. I can't figure it out, so could anyone help?
    Thanks a lot,
    mpuvdd
     
  2. Dave

    Retired Moderator

    Nov 17, 2003
    6,960
    144
    Is this the same question as the one asked here.

    If so please refrain from posting multiple threads asking the same question for reasons of manageability. If need be, give your existing thread a bump.

    If this is a repeat question please let me know and I can lock one of them (tell me which one to lock).

    Thanks.

    Dave
     
  3. mpuvdd

    Thread Starter Active Member

    Feb 11, 2007
    50
    0
    They are actually different.
     
  4. Dave

    Retired Moderator

    Nov 17, 2003
    6,960
    144
    No problem I will leave them both active.

    Dave
     
  5. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Is there some reason you can't designate the particular pin as an input?
     
  6. mpuvdd

    Thread Starter Active Member

    Feb 11, 2007
    50
    0
    Well, I know how to monitor a I/O pin's state (IN# or by using VAR), I just don't know what kind of code to write in order to make the stamp add 1 to a VAR (Value) when the I/O pins changes states.
     
  7. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    In Basic, you can usually INC a register.
     
  8. BladeSabre

    Senior Member

    Aug 11, 2005
    105
    0
    (I've never used Basic Stamp so I'm kind of guessing here.)

    It sounds like you're trying to detect rising and falling edge on a pin. On some microcontrollers, you can set up an interrupt that automatically calls your function when the level on the pin changes - I have no idea whether this is possible on the Basic Stamp.

    To detect if a pin has changed using a simple polling-loop, you can keep a record of its level, and each time round, compare its current level with what it was last time.

    psuedocode:
    Code ( (Unknown Language)):
    1. begin loop
    2.     if pinvalue != previous then dostuff
    3.     previous = pinvalue
    4.     dootherstuff
    5. end loop
    EDIT: Just thinking that might be a problem if the input changes at the wrong moment.

    Code ( (Unknown Language)):
    1. previous = pinvalue
    2. begin loop
    3.     temp = pinvalue
    4.     if temp != previous then dostuff
    5.     previous = temp
    6.     dootherstuff
    7. end loop
    However you're doing it, even with interrupts, note that if two changes occur too close together you're going to miss something.
     
Loading...