68 of 307
ZBasic System Library 58 ZX Microcontroller Family CountTransitions Type Function returning Long Invocation CountTransitions(pin, interval) Parameter Method Type Description pin ByVal Byte The pin on which logic transitions will be counted. interval ByVal Single or Long The time interval specified in seconds or I/O Timer ticks respectively, during which transitions will be counted. See the discussion below for information on range and resolution. Discussion When called, this routine will begin counting logic transitions on the specified pin and will continue until the specified interval has elapsed. During the counting process processor interrupts are disabled. This strategy allows high precision in measuring the interval but has the drawback that other processes that utilize interrupts will not function correctly. Among such affected processes are all serial communication and multi-tasking. For this reason, the counting interval should be kept as short as possible. RTC ticks that occur during the counting process are accumulated and the RTC is updated when the counting is finished. The specified pin, which you must configure to be an input before calling, is sampled at a fixed rate of approximately 500KHz. The default resolution of the measurement interval is approximately 2.441µS with a maximum interval length of 5.2 seconds. If the interval parameter is specified using a Single value the units are seconds, otherwise the units are I/O Timer ticks where each tick is approximately 2.441 µS (1/409.6KHz). You may modify the range and resolution of the measurement interval by modifying the built-in variable Register.TimerSpeed1. See the special section on Timers for more details. Resource Usage This function uses the I/O Timer and disables interrupts during the counting process. However, RTC ticks are accumulated during the process and the RTC is updated upon completion. Compatibility In BasicX missed RTC ticks are not accounted for.