Page 262 of 346 Start Back Next End ZBasic System Library 250 ZBasic Microcontrollers RCTime (subroutine form) Type Subroutine Invocation RCTime(pin, level, interval) 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 default resolution as shown in the table below 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 one unit of resolution. The pin will be left in the input tri-state mode. RCTime Resolution 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 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 32,767 units of resolution. The BasicX implementation will miss RTC ticks if the charge/discharge time is too long.