You are on page 1of 3

Organization Block for Cyclic Program Processing (OB1) Page 1 of 3

Organization Block for Cyclic Program Processing (OB1)


Cyclic program processing is the "normal" type of program execution on programmable logic controllers. The operating system calls OB1 cyclically and with this call
it starts cyclic execution of the user program.
Sequence of Cyclic Program Processing
The following table shows the phases of cyclic program processing:

Step Sequence in CPUs to 10/98 Sequence in CPUs from 10/98


1 The operating system starts the cycle The operating system starts the cycle
monitoring time. monitoring time.
2 The CPU reads the state of the inputs of the The CPU writes the values from the process
input modules and updates the process image image table of the outputs to the output
table of the inputs. modules.
3 The CPU processes the user program and The CPU reads the state of the inputs of the
executes the instructions contained in the input modules and updates the process image
program. table of the inputs.
4 The CPU writes the values from the process The CPU processes the user program and
image table of the outputs to the output executes the instructions contained in the
modules. program.
5 At the end of a cycle, the operating system At the end of a cycle, the operating system
executes any tasks that are pending, for executes any tasks that are pending, for
example downloading and deleting blocks, example downloading and deleting blocks,
receiving and sending global data. receiving and sending global data.
6 Finally, the CPU returns to the start of the Finally, the CPU returns to the start of the
cycle and restarts the cycle monitoring time. cycle and restarts the cycle monitoring time.

Process Images
So that the CPU has a consistent image of the process signals during cyclic program processing, the CPU does not address the input (I) and output (Q) address
areas directly on the I/O modules but rather accesses an internal memory area of the CPU that contains an image of the inputs and outputs.
Programming Cyclic Program Processing
You program cyclic program processing by writing your user program in OB1 and in the blocks called within OB1 using STEP 7.
Cyclic program processing begins as soon as the startup program is completed without errors.
Interrupts
Cyclic program processing can be interrupted by the following:
z An interrupt
z A STOP command (mode selector, menu option on the programming device, SFC46 STP, SFB20 STOP)
z A power outage
z The occurrence of a fault or program error
Scan Cycle Time
The scan cycle time is the time required by the operating system to run the cyclic program and all the program sections that interrupt the cycle (for example,
executing other organization blocks) and system activities (for example, updating the process image). This time is monitored.
The scan cycle time (TC) is not the same in every cycle. The following figures show different scan cycle times (TC1 z TC2) for CPUs up to 10/98 and CPUs from
10/98:

In the current cycle, OB1 is interrupted by a timeofday interrupt.


Cycle Monitoring Time
With STEP 7, you can modify the default maximum cycle monitoring time. If this time expires, the CPU either changes to STOP mode or OB80 is called in which
you can specify how the CPU should react to this error.

mk:@MSITStore:C:\Program%20Files%20(x86)\Siemens\Step7\S7bin\s7bashdB.chm::/bas00105.htm 5/24/2019
Organization Block for Cyclic Program Processing (OB1) Page 2 of 3

Minimum Cycle Time


With STEP 7, you can set a minimum cycle time for S7-400 CPUs and the CPU 318. This is useful in the following situations:
z When the interval at which program execution starts in OB1 (main program scan) should always be the same or
z When the process image tables would be updated unnecessarily often if the cycle time is too short.
The following figures show the function of the cycle monitoring time in program processing in CPUs up to 10/98 and in CPUs from 10/98.

Updating the Process Image


During cyclic program processing by the CPU, the process image is updated automatically. With the S7-400 CPUs and the CPU 318 you can deselect the update of
the process image if you want to:
z Access the I/O directly instead or
z Update one or more process image input or output sections at a different point in the program using system functions SFC26 UPDAT_PI and SFC27
UPDAT_PO.
Communication Load
You can use the CPU parameter "Scan Cycle Load from Communication" to control within a given framework the duration of communication processes that always
increase the scan cycle time. Examples of communication processes include transmitting data to another CPU by means of MPI or loading blocks by means of a
programming device.
Test functions with a programming device are barely influenced by this parameter. However, you can increase the scan cycle time considerably. In the process
mode, you can limit the time set for test functions (S7-300 only).
How the Parameter works
The operating system of the CPU constantly provides the communication with the configured percent of the entire CPU processing capacity (time slice technique).
If this processing capacity is not needed for the communication, it is available to the rest of the processing.
Effect on the Actual Scan Cycle Time
Without additional asynchronous events, the OB1 scan cycle time is extended by a factor that can be calculated according to the following formula:

Example 1 (no additional asynchronous events):

mk:@MSITStore:C:\Program%20Files%20(x86)\Siemens\Step7\S7bin\s7bashdB.chm::/bas00105.htm 5/24/2019
Organization Block for Cyclic Program Processing (OB1) Page 3 of 3

When you set the load added to the cycle by communication to 50%, the OB1 scan cycle time can be doubled.

At the same time, the OB1 scan cycle time is also influenced by asynchronous events (such as hardware interrupts or cyclic interrupts). From a statistical point of
view, even more asynchronous events occur within an OB1 scan cycle because of the extension of the scan cycle time by the communication portion. This causes
an additional increase in the OB1 scan cycle. This increase depends on how many events occur per OB1 scan cycle and on the duration of event processing.
Example 2 (additional asynchronous events considered):
For a pure OB1 execution time of 500 ms, a communication load of 50% can result in an actual scan cycle time of up to 1000 ms (provided that the CPU always
has enough communication jobs to process). If, parallel to this, a cyclic interrupt with 20 ms processing time is executed every 100 ms, this cyclic interrupt would
extend the scan cycle by a total of 5*20 ms = 100 ms without communication load. That is, the actual scan cycle time would be 600 ms. Because a cyclic interrupt
also interrupts communication, it affects the scan cycle time by 10 * 20 ms with 50% communication load. That is, in this case, the actual scan cycle time amounts
to 1200 ms instead of 1000 ms.

Note
z Check the effects of changing the value of the "Scan Cycle Load from
Communication" parameter while the system is running.
z The communication load must be taken into account when setting the
minimum scan cycle time; otherwise time errors will occur.

Recommendations
z Where possible, apply the default value.
z Increase this value only if you are using the CPU primarily for communication purposes and your user program is not time critical.
z In all other cases, only reduce the value.
z Set the process mode (S7-300 only), and limit the time needed there for test functions.
See also:

Process-Image Input/Output Tables


Organization Blocks for Interrupt-Driven Program Processing
Checking Scan Cycle Times to Avoid Time Errors
Module Information Functions
Background Organization Block (OB90)
Basic Procedure for Creating Logic Blocks
Block Folder Object
Reference Help on OBs

mk:@MSITStore:C:\Program%20Files%20(x86)\Siemens\Step7\S7bin\s7bashdB.chm::/bas00105.htm 5/24/2019

You might also like