203
Type
Subroutine
Invocation
Parameter
Method
Type
Description
pin
ByVal
Byte
The pin to use.
level
ByVal
Byte
The expected initial logic level of the pin.
interval
ByRef
Single
The variable in which to return the charge/discharge interval.
Discussion
This routine measures how long the specified pin stays at the given logic level after it is made a tri-state
input. The return value is expressed in seconds with a resolution of about 1.085µs by default but this can
be changed using Register.TimerSpeed2. If the maximum time elapses (32,767 units times the
resolution) and the pin has not changed logic levels, the return value will be zero. If the pin is not at the
specified level when called, the routine returns immediately with a value of approximately 1.085e-6. The
pin will be left in the input tri-state mode.
This function can be used with an external resistor-capacitor circuit to measure the value of one element
when the other one is known. The charge/discharge time depends on the values of R and C as well as
the initial and final voltages. Before calling this routine, you should make the specified pin an output and
set it to the level specified.
Resource Usage
This routine uses the I/O Timer. If the timer is already in use when this routine is called, it will return
immediately with a zero value. The same is true if the specified pin is invalid.
Task switching is suspended and interrupts are disabled while the charge/discharge time is being
measured. However, RTC ticks are accumulated during the process and the RTC is updated when the
process has completed so that the RTC does not lose time.
Example
See the function form of this routine for more information.
Compatibility
In BasicX, the ability to change the resolution using Register.TimerSpeed2 is not supported.
The BasicX documentation indicates that the maximum value that can be returned is about 71ms. In this
implementation, the maximum value that can be returned is about 35.6 corresponding to 35.6ms at
standard resolution. The resolution can be changed by modifying Register.TimerSpeed2 which will
affect the maximum time value.
The BasicX implementation will miss RTC ticks if the charge/discharge time is too long.