233 of 307
ZBasic System Library 223 ZX Microcontroller Family RCTime (function form) Type Function returning Integer Invocation RCTime(pin, level) Parameter Method Type Description pin ByVal Byte The pin to use. level ByVal Byte The expected initial logic level of the pin. Discussion This function measures how long the specified pin stays at the given logic level after it is made a tri-state input. The return value has units of about 1.085µS by default but this can be changed using Register.TimerSpeed2. If the maximum time elapses (32,767 units) 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 1. The pin will be left in the input tri-state mode. As an example, 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. Example Const pin as Byte = 12 Call PutPin(pin, 1) ' make the pin an output high to start charging Call Delay(1.4e-4) ' delay a bit to allow nearly full charging i = RCTime(pin, 1) ' measure the time to reach logic zero level 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. Compatibility In BasicX, the ability to change the resolution using Register.TimerSpeed2 is not supported. The BasicX implementation will miss RTC ticks if the charge/discharge time is too long.