Page 340 of 346 Start Back Next End ZBasic System Library 328 ZBasic Microcontrollers WaitForInterval Type Subroutine Invocation WaitForInterval(flags) Parameter Method Type Description flags ByVal Byte A set of flag bits that control the operation. See the discussion below. Discussion This routine allows a task to suspend itself and wait for an interval timer to expire. The length of the interval is set by the routine SetInterval. Note that there is only one interval timer that is shared by all tasks. This means that at most one task may be awaiting the expiration of an interval at any one time. If another task is already awaiting an interval, calls to WaitForInterval will return immediately. The bit values for the flags parameter are described in the table below. Interval Timer Flag Values Value Description &H01 Wait until the next interval expires. &H02 Reset the interval counter to its original value. The remaining bits are currently undefined but may be employed in the future. After a call to SetInterval the interval counter is decremented on every RTC tick. When it reaches zero, if a task is awaiting the expiration of the interval, that task will be scheduled to run immediately. If no task is awaiting the expiration of the interval, the fact that the interval expired is recorded and the interval counter is reset to the original value. If the flags value is zero when a task calls WaitForInterval and an interval expiration has previously been recorded (with no waiting task), the call will return immediately. Otherwise, the task will be suspended until the interval expiration. If the flags value is &H01, the task will be suspended until the next expiration of the interval. If the flags value is &H03, interval counter will be reloaded and then the task will be suspended until the interval expires. The last mode of operation is similar to a task calling Sleep. The difference is that when the interval expires, the task is immediately reactivated. With a Sleep call, the task will execute again when its sequential turn comes up. A task awaiting the expiration of an interval has lower priority than one awaiting an interrupt. Note that a task awaiting the expiration of an interval will exhibit some latency between the expiration of the interval and when the waiting task begins execution. The latency depends on a number of factors including the specific instruction being executed at the time and the number and frequency of system interrupts that need to be handled. Instructions that may take a long time to execute such as OutputCapture, ShiftIn, ShiftOut, X10Cmd, etc. will introduce more latency than simple instructions like assigning a value to a variable. Example Call SetInterval(1.0) Do Call WaitForInterval(0) <other code here> Loop