Functions

Top  Previous  Next

 

1        Task

In functions you formulate subtasks of the program. If you access a function in OB 1 or another block the instructions of the function will be executed. The process within the accessed block will be continued after the access at the end of the function.

 

Functions are prepared to be called nestedly, i.e. they are able to call a function within another one. Functions with continually returning tasks are prepared to be called repeatedly.

 

 

2        Parameter

Functions can also be provided with parameter (place holders). These enable the function to work with different raw data at every call and to pass back values from the function to the calling block. Within a function the parameter are named formal-parameter.

While programming the function you use the parameter like in- and outputs, markers or data words. Calling the function you predefine which data are really used by the PLC then. These data are named actual-parameter. Which parameter shall have your function you adjust in the header of the function. For each parameter you have to declare these properties which are explained in the following:

 

1. Declaration type      In, Out, InOut, Temp

2. Name                  By this the parameter within the function is named

3. Data type             By this the size is adjusted

4. Default value         Has no importance within the functions!

5. Comment               In order to make others understand your program

 

3        Declaration type

There are three kinds of parameter and one kind of variables within the functions:

 

In-parameter
Out-parameter
In-out-parameter
Temporary variables

 

Calling a function In-parameter are set to the value of the actual-parameter. In-parameter should only be read within the function. Indeed you are able to write them onto In-parameter and to work with the modified value within the function then, but this change does not have an effect on the actual-parameter in the calling block.

 

The operands connected to the Out-parameter are set to the value calculated in the function when returning to the calling block. Within a function you are able to read the Out-parameter but if you do this before you have assigned a value to the parameter the result will be an accidental one because Out-parameter are not set to the value of the connected operand when calling a function.

 

In-Out-parameter finally combine the behaviour of the In- and Out-parameter. Calling a function they are set to the value of the connected operand. They can be read and modified within the function. Returning to the calling block the modified value is copied to the connected operand.

 

The parameter model used in TrySim differs just slightly from that one of a S7. Please pay attention to the section divergently implemented properties.

 

To save intermediate results which are only needed within the function you can use the temporary variables.

 

4        Name

The parameter and the variables get a name each which you use while programming to access them. In the program code the names are marked with a ‘#’(double cross) which stands in front of the names. With clear names which are neither used in the symbol table nor correspond to a keyword you do not have to enter the sign ‘#’, just in case that mix-up possibilities are given the input is necessary.

 

5        Data type

Except of the specification whether a parameter shall have in-, out- or in-out-character you have to declare the data type of the parameter as well.

These are, for example:.

 

Type

Size

Example for connectable actual-parameter

BOOL

1 Bit

M 1.2

BYTE

1 Byte

IB 2

CHAR

1 Byte

MB 5

INT

2 Bytes

QW 10

WORD

2 Bytes

DBW 10

REAL

4 Bytes

DBD 20

 

See also:

Data types

 

6        Default value

This column is just relevant with function blocks.

 

7        Comment

With this you can explain the meaning of the parameter and variables so that others can understand your program as well. As you are one of the ‘Others’ as well within one year you should use this possibility extensively.

 

8        ENO-Output

If you call a function in FBD or LAD you will be able to let carry out other operations (or further calls) in dependence on calculation results in the function by connecting the ENO-output of the function. The operations which are connected to this output will be executed if the BR-bit within the function is set to ‘1’. They will be ignored if the BR-bit is ‘0’.

 

See also:

Organization Blocks

Function Blocks

 

STEP®5, STEP®7, S7-300 and S7-400 are registered trademarks of the Siemens AG.