WAIT / WAIT_TIME

Statement - Suspends the execution of an ST program.

Syntax

WAIT<BOOL expression> ;
WAIT_TIME<TIME expression> ;

Remarks

  • The WAIT statement:
    • Provides an easy way to program a state machine.
      • This avoids the use of complex CASE structures.
    • Verifies the attached Boolean expression and takes these actions:
      • If the expression is TRUE, the program continues normally.
      • If the expression is FALSE, then the execution of the program is suspended up to the next PLC cycle. The Boolean expression will be checked again during next cycles until it becomes TRUE. The execution of other programs is not affected.
  • The WAIT_TIME statement suspends the execution of the program for the specified duration.
    • The execution of other programs is not affected.

These instructions are available in ST Language only and have no correspondence in other languages.

  • The WAIT and WAIT_TIME instructions:
    • Cannot be called in a User-Defined Function Block (UDFB).
      • The use of WAIT or WAIT_TIME in a UDFB provokes a compile error.
    • Can be called in a sub-program.
      • However, it can lead to some unsafe situation if the same sub program is called from various programs.
    • Do not support re-entrancy.
      • Avoiding this situation is the responsibility of the programmer.
      • The compiler outputs some warning messages if a sub-program containing a WAIT or WAIT_TIME instruction is called from more than one program.
    • Must not be called from ST parts of SFC programs.
      • This makes no sense as SFC is already a state machine.
      • The use of WAIT or WAIT_TME in SFC or in a sub-program called from SFC provokes a compile error.
    • Are not available when the code is compiled through a "C" compiler.
      • Using "C" code generation with a program containing a WAIT or WAIT_TIME instruction provokes an error during post-compiling.
  • This statement is an extension to the standard and is NOT IEC 61131-3 compliant.

  • This instruction is NOT UDFB safe.
    Do not use inside UDFBs.

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

(* use of WAIT with different kinds of BOOL expressions *)
WAIT BoolVariable;
WAIT (diLevel > 100) AND NOT bAlarm;
WAIT SubProgCall ();

(* use of WAIT_TIME with different kinds of TIME expressions *)
WAIT_TIME t#2s;
WAIT_TIME TimeVariable;