Specifications
BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 289
2
Pulsin
PULSIN
pin, state, resultVariable
Measure the width of a pulse in 2µs units.
•
Pin
is a variable/constant (0–15) that specifies the I/O pin to use.
This pin will be placed into input mode during pulse measurement
and left in that state after the instruction finishes.
•
State
is a variable or constant (0 or 1) that specifies whether the
pulse to be measured begins with a 0-to-1 transition (1) or a 1-to-
0 transition (0).
•
ResultVariable
is a variable in which the pulse duration (in 2µs
units) will be stored.
Explanation
You can think of Pulsin as a fast stopwatch that is triggered by a change
in state (0 or 1) on the specified pin. When the state on the pin changes
to the state specified in Pulsin, the stopwatch starts. When the state on
the pin changes again, the stopwatch stops.
If the state of the pin doesn’t change–even if it is already in the state
specified in the Pulsin instruction–the stopwatch won’t trigger. Pulsin
waits a maximum of 0.131 seconds for a trigger, then returns with 0 in
resultVariable. If the pulse is longer than 0.131 seconds, Pulsin returns a
0 in resultVariable.
If the variable is a word, the value returned by Pulsin can range from 1
to 65535 units of 2 µs. If the variable is a byte, the value returned can
range from 1 to 255 units of 2 µs. Regardless of the size of the variable,
Pulsin internally uses a 16-bit timer. When your program specifies a
byte variable, Pulsin stores the lower 8 bits of the internal counter into
it. This means that pulse widths longer than 510 µs will give false, low
readings with a byte variable. For example, a 512-µs pulse would re-
turn a Pulsin reading of 256 with a word variable and 0 with a byte
variable.










