How do I count...
ERM
Posts: 34
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
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
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·
As soon as you "see" the IO pin go HIGH, issue an RCTIME command. It will return the time the pin remained HIGH.