Functions

Functions (FUN) are Program Organization Units (POUs) that upon execution deliver a data element as a result and any number of output values of the classes VAR_OUTPUT and VAR_IN_OUT. By specifying the result type VOID the function has no result.

They can also access global variables via VAR_EXTERNAL, VAR_EXTERNAL_RETAIN or VAR_EXTERNAL_CONSTANT.

Functions do not contain any internal status information, i.e. calling a function with the same input values for the classes VAR_INPUT, VAR_IN_OUT and VAR_EXTERNAL will always yield the same result and the same output values for the classes VAR_OUTPUT, VAR_IN_OUT and VAR_EXTERNAL.

Control FPWIN Pro7 provides two types of functions:

  1. System instructions of the system libraries

    • IEC standard library

    • FP library

    • FP tool library

    • FP pulsed library

  2. User-defined functions

    You can also program your own functions and store them in a user library. The new functions will then be available in all projects in which the user library is installed.

    Functions can be written in the following programming languages:

    • Ladder diagram (LD) or Function block diagram (FBD)

    • Structured text (ST)

    • Instruction list (IL)

NOTE
  • Functions cannot be assigned to a task as they can only be loaded by a program, function or function block.

  • A function cannot be called recursively.

    FUN1() -> FUN2() -> FUN3() -> FUN1() is not allowed.

  • The maximum of nested function calls, e.g. FUN1 (FUN2 (FUN3 (FUN4 (FUN5 (x))))), may not be exceeded.

    Maximum of nested function calls

    PLC types

    16

    FP7

    10

    Newer 16-bit PLC types like FP0H, FP_XH, FP0R

    15

    Older 16-bit PLC types

  • Except for ST or IL functions without formal parameters, function results and function outputs can be left unconnected.

  • When calling a function with formal parameters in the ST editor, the following conditions apply:

    • For arguments with formal parameters, the order of parameters does not matter.

    • With user functions, the EN input and output can be omitted. Omitted EN will be interpreted as TRUE.

Related topics:

Modified on: 2024-11-29Feedback on this pagePanasonic hotline