99BProgramming concepts
6.2 Structuring your user program
S7-1200 Programmable controller
136
System Manual, 11/2011, A5E02486680-05
Recommended steps
Tasks
Create the
configuration drawings
Based on the requirements of the functional specification, create configuration drawings of the
control equipment:
Overview drawing that shows the location of each PLC in relation to the process or machine.
Mechanical layout drawing of each PLC and any I/O modules, including any cabinets and
other equipment.
Electrical drawings for each PLC and any I/O modules, including the device model numbers,
communications addresses, and I/O addresses.
Create a list of
symbolic names
Create a list of symbolic names for the absolute addresses. Include not only the physical I/O
signals, but also the other elements (such as tag names) to be used in your program.
6.2
Structuring your user program
When you create a user program for the automation tasks, you insert the instructions for the
program into code blocks:
●
An organization block (OB) responds to a specific event in the CPU and can interrupt the
execution of the user program. The default for the cyclic execution of the user program
(OB 1) provides the base structure for your user program and is the only code block
required for a user program. If you include other OBs in your program, these OBs
interrupt the execution of OB 1. The other OBs perform specific functions, such as for
startup tasks, for handling interrupts and errors, or for executing specific program code at
specific time intervals.
●
A function block (FB) is a subroutine that is executed when called from another code
block (OB, FB, or FC). The calling block passes parameters to the FB and also identifies
a specific data 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.
●
A function (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
the OB for the cyclic execution of the program (OB 1).
●
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 technological functions of 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.