Shop OBEX P1 Docs P2 Docs Learn Events
How do I count... — Parallax Forums

How do I count...

ERMERM Posts: 34
edited 2006-11-14 03:28 in BASIC Stamp
HI guys,

How do I count the duration of a pulse? I would like to count the duration of an on state and then the duration of the off state. Do I use the count command on this? I don't believe it will work. An analogy of the operation, me holding a button down and it measure how long I hold it and when I release, it measures how long without the button pressed.

Thanks in advance,
Tony

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-11-13 22:09
    Depending on the length of the press,the best means to measure a time is PULSIN (see your help files).
    The problems are the maximum time it can time is 131mS, pretty quick for a button press. Also, mechanical switches bounce occurs and the switch may flucuate between high and low several times before setting in.

    The BASIC Stamp has no real time base that can be used.

    Depending on how critical your timing is, something like this might work for 100mS timing:

    X var word

    DO WHILE (IN0=1) 'loop until it goes low
    X = X + 1
    PAUSE 100
    LOOP

    DEBUG "time = ", dec x * 100," ms",CR

    There is loop and processing time involved, so I'm not sure how much faster you could push your increment timing.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    StampPlot - Graphical Data Acquisition and Control
    AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
  • BullwinkleBullwinkle Posts: 101
    edited 2006-11-14 03:28
    Couldn't you use RCTIME for this also?

    As soon as you "see" the IO pin go HIGH, issue an RCTIME command. It will return the time the pin remained HIGH.
Sign In or Register to comment.