BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – COUNT
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 149
COUNT
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
COUNT Pin, Duration, Variable
Function
Count the number of cycles (0-1-0 or 1-0-1) on the specified pin during the
Duration time frame and store that number in Variable.
Pin is a variable/constant/expression (0 – 15) that specifies the I/O
pin to use. This pin will be set to input mode.
Duration is a variable/constant/expression (1 – 65535) specifying the
time during which to count. The unit of time for Duration is
described in Table 5.6.
Variable is a variable (usually a word) in which the count will be
stored.
Quick Facts
Table 5.6: COUNT Quick Facts.
NOTE: All timing values are
approximate.
BS2, BS2e BS2sx BS2p BS2pe BS2px
Units in Duration
1 ms 400 µs 287 µs 720 µs 287 µs
Duration range
1 ms to
65.535 s
400 µs to
26.214 s
287 µs to
18.809 s
720 µs to
47.18 s
287 µs to
18.809 s
Minimum pulse
width
4.16 µs 1.66 µs 1.20 µs 3.0 µs 1.20 µs
Maximum
frequency
(square wave)
120,000 Hz 300,000 Hz 416,700 Hz 166,667 Hz 416,700 Hz
Related
Command
PULSIN
Explanation
The COUNT instruction makes the Pin an input, then for the specified
Duration of time, counts cycles on that pin and stores the total in Variable.
A cycle is a change in state from 1 to 0 to 1, or from 0 to 1 to 0.
According to Table 5.6, COUNT on the BS2 can respond to transitions
(pulse widths) as small as 4.16 microseconds (µs). A cycle consists of two
transitions (e.g., 0 to 1, then 1 to 0), so COUNT (on the BS2) can respond to
square waves with periods as short as 8.32 µs; up to 120 kilohertz (kHz) in
frequency. For non-square waves (those whose high time and low time are
unequal), the shorter of the high and low times must be at least 4.16 µs in
All
2