Introduction

In FBD, subroutines are called using a special subroutine block, see also section Subroutine call in the Reference manual.

The subroutine to be called must be located in the same task as the FBD section calling.

For an unconditional subroutine call, EN and ENO of the subroutine block are hidden or the input EN is assigned the value 1.

For a conditional subroutine call, EN and ENO of the subroutine block are shown and the input EN is linked with a Boolean FFB output.

For a parallel call of several subroutines, EN and ENO of the subroutine blocks are shown and the output ENO is connected to the EN input of the next subroutine block.

Subroutine calls are expansions to IEC 61131-3 and must be explicitly enabled via the Tools > Project Settings dialog box, in the Language extensions tab by activating the Allow subroutines check box.

Activating the placement mode for subroutine blocks

You have the following options to activate the placement mode for subroutine blocks:

  • Use the Edit > New > Subroutine menu command.

  • Use the Subroutine menu command from the shortcut menu.

    or

  • Select the symbol.

The active placement mode for subroutine blocks is indicated by the cursor symbol.

Note

In the Tools > Options dialog box, in the Data and Languages tab, if the Automatically affect a variable on a new graphical object check box is activated, its properties dialog box is automatically opened when an object is placed. The procedures explained here are used when the check box is cleared.

Placing subroutine blocks:

Placing subroutine blocks:

Step

Action

1

Activate the placement mode for subroutine blocks, see also Activating the placement mode for subroutine blocks.

2

Click the target cell in the FBD section.

or

Use the arrow keys to move the cursor to the target position, and press Enter.

Result: The selected subroutine block is inserted and the selection mode is active again.

3

  • Placing other subroutine blocks:

    Click the target cell in the FBD section.

    or

    Use the arrow keys to move the cursor to the target position, and press Enter.

  • To return to selection mode:

    Press the Esc key.

  • To insert other objects:

    Select the object you wish to insert.

Unconditional subroutine call

Unconditional subroutine call:

Step

Action

1

Place a subroutine block in the section, see also Placing subroutine blocks:.

2

Place the mouse pointer on the subroutine block.

Result: The mouse pointer changes its symbol to .

3

Double-click the EN input of the subroutine block.

Result: A data selection box is opened.

4

Enter 1 or TRUE for the unconditional subroutine call.

Example:

5

Double-click the SR_NAME input of the subroutine block.

Result: A selection dialog box for selecting the subroutine to be called is opened.

Example:

6

Enter the name of the subroutine, or click the symbol and select the subroutine to be called from the list. Confirm the entry with Enter.

Result: The subroutine call is inserted into the section and a syntax and semantics check is performed.

Example:

If the subroutine has already been created (see also Create a Sub-Program Section (SR)), the procedure ends here.

If the subroutine has not yet been created, continue with step 7.

7

Create the subroutine, see alsoCreate a Sub-Program Section (SR).

Conditional subroutine call

Conditional subroutine call:

Step

Action

1

Execute the Unconditional subroutine call procedure, but do not assign a value to the EN input.

2

Create a Boolean logic for the subroutine call.

3

Connect the logic’s Boolean output to the EN input of the subroutine block.

Example:

Note: To execute the conditional subroutine call you can also allocate any Boolean variable to the EN input.

Example:

Parallel call of several subroutines

Calling several subroutines:

Step

Action

1

Execute the Unconditional subroutine call procedure for all subroutines to be called in parallel.

2

Connect the ENO outputs and the EN inputs of the subroutine block.

Example:

3

Possibly create a Boolean logic for the first subroutine block.