Navigation bar
  Start Previous page
 182 of 283 
Next page End 177 178 179 180 181 182 183 184 185 186 187  

173
PulseIn (function form)
Type
Function returning Integer
Invocation
PulseIn(pin, level)
Parameter
Method
Type
Description
pin
ByVal
Byte
The pin on 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
period.  At the default I/O Timer clock period of 0.54µS, the returned value has units of 1.08µS.
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.  Note that for compatibility with
BasicX, the timing resolution is one half of the period of the selected I/O Timer frequency.
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.
Previous page Top Next page