172
Type
Subroutine
Invocation
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).
var
ByRef
Single
The variable to receive the pulse width value.
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 pulse width is stored in the specified variable and has units of seconds with a default
resolution of approximately 1.085µ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 stored result will be zero.
The timing resolution may be adjusted using Register.TimerSpeed2. However, if this is done, the
resulting pulse width value will need to be scaled proportionally. 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 Single
' measure a positive-going pulse
Compatibility
The BasicX implementation does not support adjustable timing resolution.