99BProgramming concepts
6.3 Using blocks to structure your program
6.3
Using blocks to structure your program
By designing FBs and FCs to perform generic tasks, you create modular code blocks. You
then structure your 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.
You can nest the block calls for a more modular structure. In the following example, the
nesting depth is 4: the program cycle OB plus 3 layers of calls to code blocks.
6.3.1
Organization block (OB)
Organization blocks provide structure for your program. They serve as the interface between
the operating system and the user program. OBs are event driven. An event, such as a
diagnostic interrupt or a time interval, will cause the CPU to execute an OB. Some OBs have
predefined start events and behavior.
138
A
Calling block
B
Called (or interrupting) block
①
Program execution
②
Instruction or event that initiates the execution of
another block
③
Program execution
④
Block end (returns to calling block)
①
②
System Manual, 11/2011, A5E02486680-05
Start of cycle
Nesting depth
S7-1200 Programmable controller