BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – PULSIN
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 343
PULSIN
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
PULSIN Pin, State, Variable
Function
Measure the width of a pulse on Pin described by State and store the result
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.
State is a variable/constant/expression (0 – 1) that specifies whether
the pulse to be measured is low (0) or high (1). A low pulse begins
with a 1-to-0 transition and a high pulse begins with a 0-to-1
transition.
Variable is a variable (usually a word) in which the measured pulse
duration will be stored. The unit of time for Variable is described in
Table 5.83.
Quick Facts
Table 5.83: PULSIN Quick Facts.
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
Units in
Variable
10 µs 2 µs 2 µs 0.8 µs 0.8 µs 2 µs 0.81 µs
Maximum
Pulse Width
655.35 ms 131.07 ms 131.07 ms 52.428 ms 52.428 ms 123.6 ms 53.08 ms
Related
Commands
PULSOUT and COUNT
Explanation
PULSIN is like a fast stopwatch that is triggered by a change in state (0 or
1) on the specified pin. The entire width of the specified pulse (high or
low) is measured, in units shown in Table 5.83, and stored in Variable.
Many analog properties (voltage, resistance, capacitance, frequency, duty
cycle) can be measured in terms of pulse durations. This makes PULSIN a
valuable form of analog-to-digital conversion.
PULSIN will wait, for the desired pulse, for up to the maximum pulse
width it can measure, shown in Table 5.83. If it sees the desired pulse, it
measures the time until the end of the pulse and stores the result in
Variable. If it never sees the start of the pulse, or the pulse is too long
NOTE: Expressions are not allowed as
arguments on the BS1. The range of
the Pin argument on the BS1 is 0 – 7.
S
PECIFICS OF PULSIN'S OPERATION.
1
A
ll
2
1