PulseIn

Syntax:

    PulseIn pin, user_variable, time units

Command Availability:

Available on all microcontrollers.

Explanation:

The PulseIn command will monitor the specified pin when the pin is high, and then measure the high time. It will store the time in the user variable. The user variable must be a WORD if returned units are expected to be > 255 (Example: Pulse is 500 ms)

PulseIn is not recommended for accurate measurement of microsecond pulses

Example:

    #chip 12F629, 4

    Dir GPIO.0 In
    Dim TimeResult as WORD

    Do while GPIO.0 = Off        'Wait for next positive edge to start measuring
    Loop

    Pulsein GPIO.0, TimeResult, ms          ' <<< the PulseIn instruction

Key line: Pulsein GPIO.0, TimeResult, ms — waits for GPIO.0 to go low again, then stores how long it was high, in milliseconds, into TimeResult.

See Also:

  • PulseInInv — related command in the same category
  • PulseOut — related command in the same category