Start Back Next End
  
ZBasic System Library
109
ZBasic Microcontrollers
DelayMicroseconds
Type
Subroutine
Invocation
DelayMicroseconds(usDelay)
Parameter
Method
Type
Description
usDelay
ByVal
constant integral
The amount of time to delay, in microseconds.
Discussion
This routine effects a delay for at least as long as the specified time.  The actual delay depends on the
particular processor clock frequency and whether interrupts are enabled.  If interrupts are enabled, the
delay will be extended by the amount of time required to service any interrupt that occurs.  Further, if a
task switch occurs (which will occur only if interrupts are enabled), the delay will be extended further until
the task containing the delay resumes execution.
The delay is effected by executing a series of instructions in a loop repeatedly and possibly executing one
or more NOP instructions to consume at least the specified delay time.  As an example, requesting a 10
microsecond delay on a device running at 14.7456MHz will result in a series of instructions that consume
149 cycles; the actual delay being slightly more than 10.1 microseconds.
The minimum delay incurred by calling this subroutine is 1 CPU cycle.  The maximum delay obtainable is
approximately (2^24 * 5) cycles; slightly more than 5.6 seconds at 14.7MHz.
Example
Do
Call PutPin(Pin.RedLED, 0)
Call DelayMicroseconds(500000)
Call PutPin(Pin.RedLED, 1)
Call DelayMicroseconds(500000)
Loop
This loop causes the red LED to turn on and off alternately for approximately one half second each.
Compatibility
This subroutine is only available for native mode devices and is not available in BasicX compatibility
mode.
See Also
Register.RTCStopWatch
Previous page Top Next page