![]() ZBasic System Library
234
ZBasic Microcontrollers
Type
Function returning Integer
Invocation
PulseIn(pin, level)
Parameter
Method
Type
Description
pin
ByVal
Byte
The pin on which a pulse width will be measured.
level
ByVal
Byte
The expected pulse logic value (high = 1).
Discussion
This routine waits for the input pin to be in the idle state (the opposite of that specified by the level
parameter), waits for it to change to the specified logic level and then measures the time that it stays at
that level. The width of the pulse is returned by the function, the units of which are shown in the table
below.
PulseIn Units
Target
I/O Scaling
Resolution
ZX devices running at 14.7456MHz
True
False
1.085 µS
0.542 µS
all other targets
n/a
1/F_TS2
The pin is made an input if it is not already so. If the awaited logic transition never occurs or if the pulse
width exceeds the maximum representable width the returned value will be zero.
The timing resolution may be adjusted using Register.TimerSpeed2.
Resource Usage
This routine uses the I/O Timer and interrupts are disabled during the pulse measurement. However,
RTC ticks will be accumulated during the pulse measurement and the RTC will be updated when the
process is complete.
Example
Dim width as Integer
i = PulseIn(12, 1)
' measure a positive pulse
Compatibility
The BasicX implementation does not support adjustable timing resolution.
|