Professional Documents
Culture Documents
S7 Programming Language & Blocks Type
S7 Programming Language & Blocks Type
Introduction:
There are several programming languages in STEP 7 that can be used depending on preference
and knowledge. By adhering to specific rules, the program can be created in Statement List and
later converted into another programming language.
LAD
Ladder Diagram is very similar to a circuit diagram. Symbols such as contacts and coils are used.
This programming language often appeals to those who have a drafting or electrical background.
STL
The Statement List consists of STEP 7 instructions. You can program fairly freely with STL.
This programming language is preferred by programmers who are already familiar with other
programming languages.
FBD
This programming language has the advantage that even a “non-programmer” can work with it.
Function Block Diagram is available as of Version 3.0 of the STEP7 Software.
View
You choose the View menu to switch from one STEP 7 programming language to another:
Block types
Blocks
The programmable logic controller provides various types of blocks in which the user program
and the related data can be stored. Depending on the requirements of the process, the program
can be structured in different blocks.
Organization Block OB
Organization blocks (OBs) form the interface between the operating system and the user
program. The entire program can be stored in OB1 that is cyclically called by the operating
system (linear program) or the program can be divided and stored in several blocks (structured
program).
System functions (SFC) are parameter-assignable functions integrated in the CPU‘s operating
system. Both their number and their functionality are fixed.
As a result, function blocks are suited for programming frequently recurring, complex
functionalities such as closed-loop control tasks.
System function blocks (SFB) are parameter-assignable functions integrated in the CPU‘s
operating system. Both their number and their functionality are fixed.
Data Blocks DB
Data blocks (DB) are data areas of the user program in which user data are managed in a
structured manner.
Permissible Operations
You can use the entire operation set in all blocks (FB, FC and OB).
Linear Program
The entire program is found in one continuous program block. This model resembles a hard-
wired relay control that was replaced by a programmable logic controller. The CPU processes the
individual instructions one after the other.
Partitioned Program
The program is divided into blocks, whereby every block only contains the program for solving a
partial task. Further partitioning through networks is possible within a block. You can generate
network templates for networks of the same type.
The OB 1 organization block contains instructions that call the other blocks in a defined
sequence.
When a parameter assignable block is called, the programming editor lists the local variable
names of the blocks. Parameter values are assigned in the calling block and passed to the
function or function block.
Example:
• The program blocks, which are responsible for the control of special pumps, call the "pump
block" and give it information about which pump is to be controlled with which parameters.
• When the "pump block" has completed the execution of its instructions, the program returns to
the calling block (such as OB 1), which continues processing the calling block‘s instructions.
The CPU checks the status of the inputs and outputs in every cycle. There are specific memory
areas in which the module‘s binary data are stored: PII and PIQ. The program accesses these
registers during processing.
PIQ
The Process-Image Output (Q) table contains the output values that result from the program
execution. These output values are sent to the actual outputs (Q) at the end of the cycle.
User Program
When you check inputs in the user program with, for example, A I 2.0, the last state from the PII
is evaluated. This guarantees that the same signal state is always delivered throughout one cycle.
Note
Outputs can be assigned as well as checked in the program. Even if an output is assigned a state
in several locations in the program, only the state that was assigned last is transferred to the
appropriate output module.
Starting
The CPU carries out a complete restart (with OB100) when switching on or when switching from
STOP --> RUN. During a complete restart, the operating system:
Scan Cycle
The cyclical operation of the CPU consists of three main sections, as shown in the diagram
above. The CPU:
• Checks the status of the input signals and updates the process-image input table.
• Executes the user program with the respective instructions.
• Writes the values from the process-image output table into the output modules.
Inserting a Block
With the appropriate "Blocks" folder highlighted, from a specific "S7 Program", select the Insert
-> S7 Block menu option to display a list of block types:
-Functions (FC) and function blocks (FB) contain the actual user program.
They enable a complex program to be divided into small, easy-to-follow units.
After choosing the type of block you want, the "Properties" dialog box opens so that you can
enter the block number and choose a programming language (LAD, STL or FBD).
There are other settings you can make, depending on the type of block, but these will be
discussed later.
When you have made your settings and confirmed them by clicking the "OK" button, the new
block is inserted in the current program.
Declaration Table
The declaration table belongs to the block. This table is used for declaring variables and
parameters for the block.
The declaration table is discussed in detail in the "Functions and Function Blocks" chapter.
Code Section
The code section contains the program itself, divided into separate networks if required.
A syntax check is made during instruction input (in STL) and in labeling program elements or
operation symbols.
Detail Window
The detail window provides the following functions and information:
1: Error:
Lists the syntax errors found in the course of a context check or a compilation procedure
2: Info:
Gives additional information such as "expected data type of an address"
3: Cross references
A list of addresses used in the network and where they are used in the entire program
4: Address info
Enables you to monitor the addresses used in the network
5: Modify
Enables you to modify the addresses used in the network
6: Diagnostics
Display of existing data for process diagnostics (only if configured)
7: Comparison
Navigation with the function "Compare blocks"