PDA

View Full Version : How do I count...



ERM
11-14-2006, 05:41 AM
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

Martin Hebel
11-14-2006, 06:09 AM
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 (http://www.stampplot.com/)
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers (http://www.selmaware.com/appbee)·

Bullwinkle
11-14-2006, 11:28 AM
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.