WAITUS/de
Action
Hält die Programmausführung für die angegebene Zeit in Mikrosekunden an.
Contents |
Syntax
WAITUS uS
Remarks
US |
The number of microseconds to wait. (1-65535)
This must be a constant. Not a variable! In version 1.12.x.x and higher you can use a variable as well. |
Ein genaues Timing ist mit WAITUS nicht möglich. Für genaue Zeiten sollte ein Timer verwendet werden.
Außerdem können Interrupts die Wartezeit verlängern.
The minimum delay possible is determined by the used frequency.
The number of cycles that are needed to set and save registers is 17.
When the loop is set to 1, the minimum delay is 21 uS. In this case you can better use a NOP that generates 1 clock cycle delay.
At 4 MHz the minimum delay is 5 uS. So a waitus 3 will also generate 5 uS delay.
Above these values the delay will become accurate.
When you really need an accurate delay you should use a timer.
Set the timer to a value and poll until the overflow flag is set. The disadvantage is that you can not use the timer for other tasks during this hardware delay.
The philosophy behind BASCOM is that it should not use hardware resources unless there is no other way to accomplish a task.
The WAITUS is used internal by some statements. It was added to the BASCOM statements but it does NOT accept a variable. Only a constant is accepted.
When you use a variable for the delay, the accuracy will depend on the value of the oscillator. A higher oscillator value will result in a better accuracy.
When you clock the micro with 1 MHz, it means that you have a million cycles per second. A NOP instructions takes 1 cycle and will thus delay for 1 us.
If you must load registers, and call a subroutine, it means you need more cycles.
At 8 Mhz the following results were measured:
With a constant
1us : 2.6 us
10us : 11.5 us
25us : 26.3 us
With a variable
1us : 1.4 us
10us : 10.2 us
25us : 25.0 us
See also
Example
WAITUS 10 'wait for 10 uS Print "*"
Languages | English • Deutsch |
---|