Cyclic execution

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Cyclic execution

mapp Services V5.16

Statements programmed between CYCLIC (or CYCLIC_BL) and CYCLIC_END define sections that are cyclically executed in the context of a cyclic task.

Syntax

CYCLIC [TC<number>] | CYCLIC_BL [TC<number>] | CYCLIC_PS [TC<number>] | CYCLIC_PS_BL [TC<number>]
  Statements
END_CYCLIC

Description

A cyclic section is executed in the context of a defined cyclic task class. Depending on the type of cyclic section, the statements within it are scheduled to run in the next cycle of the cyclic task. If the section is marked as "Blocking", then it will block execution of the next line.

Block type

Blocking

Schedule

CYCLIC

No

Next cycle

CYCLIC_BL

Blocks the next line

Next cycle

A cyclic execution block can be used for code that requires execution in the context of a cyclic task, e.g. calling function blocks or cyclic evaluation of process variables and a deterministic response to their changes. A sequence of consecutive blocking (_BL) cyclic sections can be used to implement a simple state machine.

Limitations

When a program ends, all scheduled or running cyclic sections are aborted.

Temporary data (function arguments, function-local variables) is not permitted to be referenced in cyclic sections (except CYCLIC_BL).

Cyclic sections cannot be nested.

TC<Number>

Each cyclic block can be optionally scheduled for execution in a defined task class. Without the TC statement, the cyclic block is called in default task class TC#1.

The TC statement is specified followed by statement CYCLIC on the same line.

<number>

Task class number 1-8. The number must be specified after the TC statement without using spaces.

EXIT

The EXIT statement ends cyclic execution.

Examples

CYCLIC: Non-blocking execution

A cyclic section is executed "in parallel" to the main program until "Signal" is set to 1.

PROGRAM _MAIN

 CYCLIC

  IF (signal = 1) THEN

    EXIT;

   END_IF

   counter := counter + 1;

 END_CYCLIC

(* Continue execution immediately *)

END_PROGRAM

CYCLIC_BL: Blocking execution

Execution of the main program is blocked until "Signal" is set to 1. "Signal" is checked cyclically in relation to TC#5.

PROGRAM _MAIN

 CYCLIC_BL TC5

  IF (signal = 1) THEN

    EXIT;

   END_IF

 END_CYCLIC

(* Continue execution when the variable signal is set to 1 *)

END_PROGRAM

CYCLIC_BL: State machine

State machine implemented by CYCLIC_BL. Two function blocks are called consecutively until each is completed.

PROGRAM _MAIN

  (* State 1 - Call FB1 until completed *)

   CYCLIC_BL

       FB1_0();

      IF FB1_0.Done THEN

          EXIT;

       END_IF

   END_CYCLIC

  (* State 2 - Call FB2 until completed *)

   CYCLIC_BL

       FB2_0();

      IF FB2_0.Done THEN

          EXIT;

       END_IF

   END_CYCLIC

END_PROGRAM