Programming options
5.2 Structuring your user program is easy
Easy Book
Manual, 05/2009, A5E02486774-01
51
block (DB) that stores the data for the specific call or instance of that FB. Changing the
instance DB allows a generic FB to control the operation of a set of devices. For example,
one FB can control several pumps or valves, with different instance DBs containing the
specific operational parameters for each pump or valve. The instance DB maintains the
values of the FB between different or consecutive calls of that FB, such as to support
asynchronous communication.
●
An FC is a subroutine that is executed when called from another code block (OB, FB, or
FC). The FC does not have an associated instance DB. The calling block passes
parameters to the FC. The output values from the FC must be written to a memory
address or to a global DB.
Choosing the type of structure for your user program
Based on the requirements of your application, you can choose either a linear structure or a
modular structure for creating your user program:
●
A linear program executes all of the instructions for your automation tasks in sequence,
one after the other. Typically, the linear program puts all of the program instructions into
one program cycle OB (OB 1) for cyclic execution of the program.
●
A modular program calls specific code blocks that perform specific tasks. To create a
modular structure, you divide the complex automation task into smaller subordinate tasks
that correspond to the functional tasks being performed by the process. Each code block
provides the program segment for each subordinate task. You structure your program by
calling one of the code blocks from another block.
Linear structure:
Modular structure:
2%
)%
)&
2%
By designing FBs and FCs to perform generic tasks, you create modular code blocks. You
then structure your user program by having other code blocks call these reusable modules.
The calling block passes device-specific parameters to the called block. When a code block
calls another code block, the CPU executes the program code in the called block. After
execution of the called block is complete, the CPU resumes the execution of the calling
block. Processing continues with execution of the instruction that follows after the block call.