WAITUS

From MCS Wiki AVR
(Difference between revisions)
Jump to: navigation, search
(Created page with "= <span class="f_Header">Action</span> = Suspends program execution for a given time in uS. <span style="font-family: Arial;"> </span> <span style="font-family: Arial;...")
 
 
Line 57: Line 57:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
When you really need an accurate delay you should use a timer.
+
In version 2.0.7.6 the compiler will create different code depending on the $CRYSTAL value and the specified delay.
  
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.
+
When you use a constant, the timing is reasonable accurate. When using a variable, the timing accuracy depends on the oscillator speed.
  
<span style="font-family: Arial;">&nbsp;</span>
+
As a general rule : the higher the clock speed, the better the result.
 
+
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.
+
  
 
&nbsp;
 
&nbsp;
  
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 really need an accurate delay you should use a timer.
  
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.
+
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.
  
If you must load registers, and call a subroutine, it means you need more cycles.
+
<span style="font-family: Arial;">&nbsp;</span>
  
&nbsp;
+
The philosophy behind BASCOM is that it should not use hardware resources unless there is no other way to accomplish a task.
 
+
At 8 Mhz the following results were measured:
+
 
+
&nbsp;
+
 
+
<span style="font-family: 'Courier New';">With a constant</span>
+
 
+
<span style="font-family: 'Courier New';">1us &nbsp;: &nbsp; 2.6 us</span>
+
 
+
<span style="font-family: 'Courier New';">10us&nbsp;: &nbsp;11.5 us</span>
+
 
+
<span style="font-family: 'Courier New';">25us&nbsp;: &nbsp;26.3 us</span>
+
 
+
<span style="font-family: 'Courier New';">&nbsp;</span>
+
 
+
<span style="font-family: 'Courier New';">With a variable</span>
+
 
+
<span style="font-family: 'Courier New';">1us &nbsp;: &nbsp; 1.4 us</span>
+
 
+
<span style="font-family: 'Courier New';">10us&nbsp;: &nbsp;10.2 us</span>
+
 
+
<span style="font-family: 'Courier New';">25us&nbsp;: &nbsp;25.0 us</span>
+
 
+
<span style="font-family: 'Courier New';">&nbsp;</span>
+
 
+
<span style="font-family: Arial;">&nbsp;</span>
+
  
 
= <span class="f_Header">See also</span> =
 
= <span class="f_Header">See also</span> =

Latest revision as of 12:53, 24 August 2013

Contents

Action

Suspends program execution for a given time in uS.

 

 

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.

 

No accurate timing is possible with this command. For accurate timing you can best use a timer.

In addition, the use of interrupts can slow down this routine.

 

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.

 

In version 2.0.7.6 the compiler will create different code depending on the $CRYSTAL value and the specified delay.

When you use a constant, the timing is reasonable accurate. When using a variable, the timing accuracy depends on the oscillator speed.

As a general rule : the higher the clock speed, the better the result.

 

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.

See also

DELAY , WAIT , WAITMS

 

 

Example


WAITUS 10 'wait for 10 uS
Print "*"

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language