BS1 icon BS2 icon BS2e icon BS2sx icon BS2p icon BS2pe icon BS2px icon

PULSIN Example




Syntax: PULSIN Pin, State, Variable


Measure the width of a pulse on Pin described by State and store the result in Variable.

* Note: expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0–7.

Quick Facts

  BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
Units in Variable 10 µs 2 µs 2 µs 0.8 µs 0.75 µs 2 µs 0.81 µs
Maximum pulse width 655.35 ms 131.07 ms 131.07 ms 52.428 ms 49.151 ms 123.6 ms 53.08 ms
Related Commands



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 above and stored in Variable.

Many analog properties (voltage, resistance, capacitance, frequency, duty cycle) can be measured in terms of pulse duration. 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 the table above. 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 (greater than the Maximum Pulse Width shown above), PULSIN "times out" and store 0 in Variable. This operation keeps your program from locking-up should the desired pulse never occur.

Regardless of the size of Variable, PULSIN internally uses a 16-bit timer. Unless the pulse widths are known to be short enough to fit in an 8-bit result, it is recommended using a word-sized variable. Not doing so may result in strange and misleading results as the BASIC Stamp will only store the lower 8-bits into a byte variable.

Go to PBASIC Language home page

Open Getting Started with Stamps in Class

Open Connection Troubleshooting

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.