Programming options
5.2 Structuring your user program is easy
Easy Book
54
Manual, 05/2009, A5E02486774-01
Configuring the operation of an OB
You can modify the operational
parameters for an OB. For example, you
can configure the time parameter for a
time-delay OB or for a cyclic interrupt
OB.
5.2.2
FBs and FCs make programming the modular tasks easy
A function (FC) is like a subroutine. An FC is a code block that typically performs a specific
operation on a set of input values. The FC stores the results of this operation in memory
locations. Use FCs to perform the following tasks:
●
To perform standard and reusable operations, such as for mathematical calculations.
●
To perform functional tasks, such as for individual controls using bit logic operations.
An FC can also be called several times at different points in a program. This reuse simplifies
the programming of frequently recurring tasks.
Unlike an FB, an FC does not have an associated instance DB. The FC uses its temp
memory (L) for the data used to calculate the operation. The temporary data is not saved. To
store data for use after the execution of the FC has finished, assign the output value to a
global memory location, such as M memory or to a global DB.
A function block (FB) is like a subroutine with memory. An FB is a code block whose calls
can be programmed with block parameters. The FB stores the input (IN), output (OUT), and
in/out (IN_OUT) parameters in variable memory that is located in a data block (DB), or
"instance" DB. The instance DB provides a block of memory that is associated with that
instance (or call) of the FB and stores data after the FB finishes.
You typically use an FB to control the operation for tasks or devices that do not finish their
operation within one scan cycle. To store the operating parameters so that they can be
quickly accessed from one scan to the next, each FB in your user program has one or more
instance DBs. When you call an FB, you also open an instance DB that stores the values of
the block parameters and the static local data for that call or "instance" of the FB. The
instance DB stores these values after the FB finishes.
You can assign initial values to the parameters in the FB interface. These values are
transferred to the associated instance DB. If you do not assign parameters, the values
currently stored in the instance DB will be used. In some cases, you must assign
parameters.