99BProgramming concepts
6.3 Using blocks to structure your program
S7-1200 Programmable controller
System Manual, 11/2011, A5E02486680-05
139
The program cycle OB contains your main program. You can include more than one program
cycle OB in your user program. During RUN mode, the program cycle OBs execute at the
lowest priority level and can be interrupted by all other types of program processing. The
startup OB does not interrupt the program cycle OB because the CPU executes the startup
OB before going to RUN mode.
After finishing the processing of the program cycle OBs, the CPU immediately executes the
program cycle OBs again. This cyclic processing is the "normal" type of processing used for
programmable logic controllers. For many applications, the entire user program is located in
a single program cycle OB.
You can create other OBs to perform specific functions, such as for handling interrupts and
errors, or for executing specific program code at specific time intervals. These OBs interrupt
the execution of the program cycle OBs.
Use the "Add new block" dialog to create new OBs in your user program.
Interrupt handling is always event-
driven. When such an event occurs,
the CPU interrupts the execution of
the user program and calls the OB
that was configured to handle that
event. After finishing the execution
of the interrupting OB, the CPU
resumes the execution of the user
program at the point of interruption.
The CPU determines the order for handling interrupt events by a priority assigned to each
OB. Each event has a particular servicing priority. The respective priority level within a
priority class determines the order in which the OBs are executed. Several interrupt events
can be combined into priority classes. For more information, refer to the PLC concepts
chapter section on execution of the user program (Page 61).
Creating an additional OB within a class of OB
You can create multiple OBs for your user program, even for the program cycle and startup
OB classes. Use the "Add new block" dialog to create an OB. Enter the name for your OB
and enter an OB number 200 or greater.
If you create multiple program cycle OBs for your user program, the CPU executes each
program cycle OB in numerical sequence, starting with the program cycle OB with the lowest
number (such as OB 1). For example: after first program cycle OB (such as OB1) finishes,
the CPU executes the next higher program cycle OB (such as OB 200).