Automatic Execution Order by Data Flow

The execution order in POUs is uniquely determined in text-based and network-based editors. In the CFC editor, however, you can position the elements freely, so the execution order is initially not unique. For this reason, CODESYS determines the execution order by data flow and, in the case of multiple networks, by the topological position of the elements. The elements are sorted from top to bottom and left to right. Now the execution order is unique and makes sure that the POU is processed while optimized by time and by cycle.

You can get information about the chronological order of the elements in the chart and temporarily display the execution order. When you program networks with feedback you can define an element as the starting point in the feedback loop.

You can also explicitly edit the processing order in a CFC object if necessary. To do this, switch the Auto Data Flow Mode property of the CFC object to Explicit Execution Order Mode. In this mode, you have the option of editing the execution order by means of menu commands.

Before CODESYS Development System V3.5 SP15, you had to define the execution order explicitly for each POU. The was no mode switching.

Data flow

In general, data flow is described as the chronological order in which data is read or written when and how in which programming objects. A POU can process any number of data flows, which can also be executed independently of each other.

Displaying the execution order

By default, the execution order of a CFC object is determined automatically. The Auto Data Flow Mode property is selected for this. You can temporarily display the automatically determined execution order in the CFC editor.

  1. Create a new project using the Standard project template and specify the name Minimal for example.

  2. Extend the application with the function block FB_DOIt in the ST implementation language with inputs and outputs.

    FUNCTION_BLOCK FB_DoIt
    VAR_INPUT
     iAlfa : INT;
     iBravo: INT;
     sCharlie : STRING := 'Charlie';
     xItem : BOOL;
    END_VAR
    VAR_OUTPUT
             iResult : INT;
             sResult : STRING;
             xResult : BOOL;
    END_VAR
    VAR
    END_VAR
    
    iResult := iAlfa + iBravo;
    
    IF xItem = TRUE THEN
     xResult := TRUE;
    END_IF
    
  3. Create the function block ExecuteCFC in the CFC implementation language.

    PROGRAM ExecuteCFC
    VAR
     fb_DoIt_0: FB_DoIt;
     fb_DoIt_1: FB_DoIt;
     iFinal_1: INT;
     iFinal_0: INT;
     xFinal: BOOL;
    END_VAR
    

    Recently created programming objects in CFC have the Auto Data Flow Mode selected. The execution order of the programming object is optimally defined internally.

  4. Click CFC ‣ Execution Order ‣ Display Execution Order .

    ⇒ The execution order of the object is shown. The boxes and inputs are numbered accordingly and reflect the chronological processing order. The numbering is hidden as soon as you click again in the CFC editor.

Determining the execution order in feedback networks

  1. Create a CFC program with feedback.

    ⇒ The POU PrgPositiveFeedback counts.

    PROGRAM PrgPositiveFeedback
    VAR
     iResult: INT;
    END_VAR
    
  2. Select an element within the feedback.

    ⇒ The selected element is highlighted in red.

  3. Click CFC ‣ Execution Order ‣ Set Start of Feedback .

    At runtime, this POU is processed first. The start POU of the feedback is defined and decorated with the symbol. The execution order is resorted and the selected element gets the number 0. (This is the lowest number of the feedback.)

  4. Select the start POU again.

  5. Click CFC ‣ Execution Order ‣ Set Start of Feedback .

    ⇒ The POU is not selected as the start POU.

    The execution order is defined internally.

  6. Click CFC ‣ Execution Order ‣ Display Execution Order .

    ⇒ The execution order by data flow is displayed.

Defining the execution order explicitly

Note

The automatically defined execution order by data flow results in time- and cycle-optimized execution of the POU. You do not need any information about the internally managed execution order during the development process.

In Explicit Execution Order Mode, it is your responsibility to adapt the execution order and to assess the consequences and impacts. This is another reason why the execution order is always displayed.

You can change the automatically defined execution order of a CFC object explicitly when you select the Explicit Execution Order Mode option for the object.

  1. In the Devices or POUs view, select a CFC object.

  2. In he context menu, click Properties.

  3. Click the CFC Execution Order tab.

    ⇒ The Execution order list box displays the currently selected mode.

  4. In the Execution order list box, select Explicit Execution Order Mode.

  5. Click OK to confirm the dialog.

    ⇒ The Explicit Execution Order Mode property is selected. The networks are numbered in the CFC editor, and the following commands are provided in the CFC ‣ Execution Order menu for editing the execution order.

  6. Open a CFC object.

  7. Select a numbered element and click CFC ‣ Execution Order ‣ Send to Front .

    ⇒ The execution order is resorted and the selected element has the number 0.

See also