4.4
Execution of the user program
The CPU supports the following types of code blocks that allow you to create an efficient
structure for your user program:
● An organization block (OB) is a code block that typically contains the main program logic.
● A function block (FB) is a subroutine that is executed when called from another code
● A function (FC) is a subroutine that is executed when called from another code block
The size of the user program, data, and configuration is limited by the available load memory
and the work memory in the CPU. There is no limit to the number of blocks supported; the
only limit is due to memory size.
Using OBs to handle events
The processing of the CPU scan is driven by events. The default event is a program cycle
event that starts the execution of the program cycle OB. (You are not required to use a
program cycle OB in your program.) Other events can be enabled if required. Some events,
such as the cyclic event, are enabled at configuration time. Other events, such as the time
delay event, are enabled at runtime. When enabled, an event is attached to an associated
OB. (The program cycle and startup events can each be attached to multiple OBs.) An
occurrence of an event leads to the execution of its event service routine, which is the
attached OB plus any functions called from the OB. Priorities, priority groups, and queues
are used to determine the processing order for the event service routines.
The number of pending (queued) events from a single source is limited using a different
queue for each event type. Upon reaching the limit of pending events for a given event type,
the next event is lost. Each event has an associated priority, and the event priorities are
classified into priority groups, as shown in the following table.
Easy Book
Manual, 05/2009, A5E02486774-01
The 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. 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. :
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 of valve. The
instance DB maintains the values of the FB between different or consecutive calls of that
FB, such as to support asynchronous communication.
(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.
How the S7-1200 works
4.4 Execution of the user program
37