0% found this document useful (0 votes)
97 views17 pages

TIA PRO2 14 Introduction SCL

The document provides an overview of Structured Control Language (SCL) within the SIMATIC TIA Portal S7-1500 programming environment, detailing its applications, advantages, and programming structures. It covers topics such as creating SCL blocks, using operators, control structures, and addressing methods, along with practical exercises for users to gain hands-on experience. The content is aimed at helping participants understand and effectively utilize SCL for complex calculations and data processing tasks in PLC programming.

Uploaded by

adamraz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views17 pages

TIA PRO2 14 Introduction SCL

The document provides an overview of Structured Control Language (SCL) within the SIMATIC TIA Portal S7-1500 programming environment, detailing its applications, advantages, and programming structures. It covers topics such as creating SCL blocks, using operators, control structures, and addressing methods, along with practical exercises for users to gain hands-on experience. The content is aimed at helping participants understand and effectively utilize SCL for complex calculations and data processing tasks in PLC programming.

Uploaded by

adamraz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

SIMATIC TIA Portal S7-1500 Programming 2

Contents 14
14. Structured Control Language SCL ..................................................................... 14-2
14.1. Task Description: Storing Weight Values in DB-Variables ................................................. 14-3
14.2. SCL: Programming Complex Calculations and Algorithms ................................................ 14-4
14.3. Advantages of the SCL Programming Language ............................................................... 14-5
14.4. Using an SCL Network in LAD/FBD Blocks ........................................................................ 14-6
14.5. Creating an SCL Block ........................................................................................................ 14-7
14.5.1. SCL Block Editor ................................................................................................................. 14-8
14.5.2. Operators ............................................................................................................................ 14-9
14.5.3. Control Operation Structures ............................................................................................ 14-10
14.5.4. Direct Addressing .............................................................................................................. 14-11
14.5.5. Indirect Addressing ........................................................................................................... 14-12
14.5.6. Calling an SCL Block ........................................................................................................ 14-13
14.5.7. Useful Function Expansions ............................................................................................. 14-14
14.5.8. Monitoring SCL Blocks ...................................................................................................... 14-15
14.6. Exercise 1: Copying the SCL Block from the Library ........................................................ 14-16
14.6.1. Exercise 2: Exchanging the Call of "FB_Weight" with "FB_Weight_SCL" ........................ 14-17

TIA-PRO2 - SCL
Training Document, V15.01.00 14-1
SIMATIC TIA Portal S7-1500 Programming 2

14. Structured Control Language SCL

At the end of the chapter the participant will ...

... be familiar with the application areas of SCL

… be familiar with operators and control operation structures


of SCL

... be able to commission a given SCL block

TIA-PRO2 - SCL
14-2 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.1. Task Description: Storing Weight Values in DB-Variables

sum

#AutoLeftStop
346
237
144

Task Description
The tasks of "FB_Weight" – to store the weight values of the transported parts in "DB_Weight", to
check whether the Weight storage is full, to calculate the minimum, the maximum, the average
weight and the sum of all weights and initialize the data for "P_Operation" ON-OFF – is to be
taken over by a function block written in SCL.

TIA-PRO2 - SCL
Training Document, V15.01.00 14-3
SIMATIC TIA Portal S7-1500 Programming 2

14.2. SCL: Programming Complex Calculations and Algorithms

Structured Control Language as text-based structured high-level language

• Structured Text
• Complex calculations & algorithms
• Database operations, for example, sorting
data
• Program code exchangeable between
S7-1200 and S7-1500 as well as between
S7-300, S7-400 and WinAC

WinAC
S7-300
S7-1500
S7-400
S7-1200

S7-SCL
SCL (Structured Control Language) is a PASCAL-similar high-level textual language. It simplifies
the programming of mathematical algorithms and complex data processing tasks for PLCs. SCL
therefore also enables S7 PLCs to be used for more complex tasks such as closed-loop control
or statistical evaluation.
SCL offers the functional scope of a high-level language such as:
• Loops
• Alternatives
• Branch distributors, etc.
combined with PLC-specific functions such as:
• Bit accesses to the I/O, bit memories, timers, counters etc.
• Access to the symbol table
• STEP 7 block accesses

TIA-PRO2 - SCL
14-4 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.3. Advantages of the SCL Programming Language

Solution in SCL for S7-300/400 AND S7-1200/1500

Solution in STL
for S7-300/400

Solution in FBD for S7-1200/1500

Solution in STL
for S7-1500

Advantages of SCL
• Easy to learn programming language, especially for beginners
• Easy to read (understandable) programs are created.
• Easier programming of complex algorithms and processing of complex data structures
• System integration in S7 languages, such as STL, LAD and FBD.
• Relatively easy for PLC technicians to understand through similarity with S7 languages.

TIA-PRO2 - SCL
Training Document, V15.01.00 14-5
SIMATIC TIA Portal S7-1500 Programming 2

14.4. Using an SCL Network in LAD/FBD Blocks

1xR

An SCL network can be inserted anytime in a LAD or FBD block. For this, the function "Insert
SCL network" in the context menu of the instruction section is used (right-click in the
instruction section).

TIA-PRO2 - SCL
14-6 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.5. Creating an SCL Block

Creating an SCL Block


SCL blocks are inserted in the same manner as blocks in the programming languages LAD/FBD.
Depending on the task, SCL blocks can be of the OB, FC, or FB block type.
Even the internal structure in the declaration and statement section is identical to the LAD/FBD
blocks:
Declaration Section:
The IN, OUT and INOUT parameters as well as the local temporary and local static variables of
the block are declared in the declaration section of a block.
Statement Section:
The statement section contains the instructions that are executed after a logic block (OB, FB, FC)
is called. These instructions are used to process data and operands.

Note
In programming instructions, the following points must be taken into consideration:
• Each instruction must be completed with a semicolon.
• All identifiers (names) used in the statement section must be declared.

TIA-PRO2 - SCL
Training Document, V15.01.00 14-7
SIMATIC TIA Portal S7-1500 Programming 2

14.5.1. SCL Block Editor

Same interface as in
LAD/FBD/STL
Regions (use as
Networks) Master copies for
control operation
structures

Automatic
indentation of
statement sections

Statement Section
The statement section contains the instructions that are executed after a code (logic) block (OB,
FB, FC) is called. These instructions are used to process data and operands.
Subdivision
The individual instructions can basically be divided into three groups:
• Value assignments:
− They are used to assign an expression or a value to a variable.
• Control instructions:
− They are used to branch within a program or to repeat groups of instructions.
• Subroutine call:
− They are used to process functions and function blocks.

Note
In programming instructions, the following points must be taken into consideration:
• Each instruction must be completed with a semicolon.
• All identifiers (names) used in the statement section must be declared.

Using Regions as Networks:


• Code structuring
• Greater clarity & readability
• Easy navigation even in large blocks
In addition, there is a synchronized navigation column including the display of syntax errors.

TIA-PRO2 - SCL
14-8 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.5.2. Operators

Syntax: result := expression;


Example: #Q_Average := (#Value1 + Value2) / 2;

Logic operation Description Operator

Assignment Assignment :=

Parenthesis (Expression) (,)

Negation NOT
AND AND, &
Binary logic operation
OR OR
Exclusive-OR XOR

Less than, less than or equal to, greater


<, <=, >, >=
Comparison than, greater than or equal to, equal to,
=, <>
not equal to

Plus, Minus (sign) +,-


Addition, Subtraction +,-
Math
Multiplication, Division *, /, MOD
Exponentiation **

Expressions
Expressions consist of operands, operators and round brackets (parenthesis). Within an
expression the operators (e.g. +, -, *, /, etc.), that is, the active components of an expression, are
linked with the passive elements, such as constants, variables and function values, in order to
form a new value. An expression therefore stands for the value it represents. SCL permits the
formation of standard expressions, that is, mathematical, logical and comparative expressions.
Variables from data blocks, arrays, structures and CPU memory areas (inputs, outputs, etc.) can
be enlisted for the formation.

Operators and Operands


Expressions consist of operators and operands. Most SCL operators link two operands
(e.g. A + B) and are therefore termed binary operators. The others work with only one operand
and are thus called unary operators.
The result of an expression can
• be assigned to a variable (e.g. A := B + C;)
• be used as a condition for a control statement
(e.g. IF A< B DO ... )
• be used as an actual parameter for the call of a function or a
function block (e.g. FB20 (Input := A + B))

TIA-PRO2 - SCL
Training Document, V15.01.00 14-9
SIMATIC TIA Portal S7-1500 Programming 2

14.5.3. Control Operation Structures

There are master copies (so-called code snippets) for the control operation structures!

Keyword Functionality

IF Program branching with Boolean value


Program branching
CASE Program branching with INT value

FOR Program loop with run variable

Program loops
WHILE Program loop with execution condition
(Abort possible)

REPEAT Program loop with abort condition

CONTINUE Abort current loop pass


Loop aborts
EXIT Exit program loop

Block abort RETURN Exit the block

Control Instructions
These are used for changing the sequence in which the instructions are normally processed.
A choice from the various alternatives in the program execution can be made with conditional
instructions (IF and CASE instructions).
Loop instructions (FOR, WHILE and REPEAT instructions) are used to repeatedly execute
instructions.
Jump instructions (CONTINUE, EXIT and GOTO instructions) permit the sequence of processing
to be interrupted and to jump to a resumption point
FB and FC Calls
According to the principle of structured programming, other function blocks and functions can also
be called from an SCL block.
Callable blocks are:
+ Functions and function blocks that were created in SCL or in another STEP 7 language (STL,
LAD, etc.).
+ Standard functions and standard function blocks that are supplied with SCL.
+ Instructions with and without instance.

TIA-PRO2 - SCL
14-10 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.5.4. Direct Addressing

Direct addressing (absolute and symbolic) for


inputs, outputs and memory bits is identical to LAD/FBD/STL!

Area Notation examples Examples

Bit %DBz.DBXy.x , %Iy.x %DB5.DBX0.7 , %I0.0

Byte %DBz.DBBy , %MWy %DB5.DBB2 , %QB2


Absolute
Addressing
Word %DBz.DBWy , %MWy %DB5.DBW4 , %MW20

Double-word %DBz.DBDy %DB5.DBD8

"<DB-Symbol>".<Variable-Name> "Motor".Setvalue

Symbolic <Variable-Name>.%X<Bitnumber>
Addressing "Motor".Alarms.%X1
<Variable-Name>.%B<Bytenumber>
(Bit 1 of the variable
<Variable-Name>.%W<Wordnumber>
"Alarms" in DB "Motor")
<Variable-Name>.%D<Doublewordnumber>

Direct Addressing
In the statement section of a block, the actions are described that are to be executed with local
operands (parameters or local variables) or global variables (PLC tags or variables in a global
data block). The global variables can be addressed either absolutely or symbolically.

TIA-PRO2 - SCL
Training Document, V15.01.00 14-11
SIMATIC TIA Portal S7-1500 Programming 2

14.5.5. Indirect Addressing

Indirect addressing, both for I/Q/M/Peripheral access,


and for variables in data blocks!

Area Instruction Examples

Indirect PEEK_BOOL
Addressing Bit #OUT1 :=PEEK_BOOL(area:=#Memory _area,
POKE_BOOL
dbNumber:=#DB_Number,
BYTE - PEEK byteOffset:=#Byte_addr,
LWORD POKE
bitOffset:=Bit_addr);
WORD PEEK_WORD
POKE(area:= Memory_area,
DWORD PEEK_DWORD
dbNumber:=#DB_Number,
LWORD PEEK_LWORD byteOffset:=#Byte_addr,

Area POKE_BLK value:=w#16#12);

Indexed
Access “<DB-
Array
Symbol>”.<Array- “Motor”.Value[#Index]
element
Symbol>[Index]

Indirect Addressing
The instructions PEEK (read) and POKE (write) are used for indirect addressing.
Memory_area, DB_Number, Byte_addr and Bit_addr are constants, at runtime, changeable
variables or expressions.
The following memory areas (area) can be addressed in this way:
• 16#81: Input
• 16#82: Output
• 16#83: Memory bit
• 16#84: DB
• 16#1: Peripheral input for PEEK or Peripheral output for POKE (only S7-1500)
If the memory area is not 16#84, then the DB_Number must be specified with 0.

Example Poke_BLK:
POKE_BLK(AREA_SRC := "Tag_Source_Area", //Memory area Source
DBNUMBER_SRC := "Tag_Source_DBNumber", //DB-Number Source
BYTEOFFSET_SRC := "Tag_Source_Byte"), //Byte number Source
AREA_DEST := "Tag_Destination_Area", //Memory area Destination
DBNUMBER_DEST := "Tag_Destination_DBNumber", //DB-Number Destination
BYTEOFFSET_DEST := "Tag_Destination_Byte", //Byte number Destination
COUNT := "Tag_Count"); //Number of bytes

Array Elements
Array elements can be addressed with a variable Index (Indexed access) at runtime.

TIA-PRO2 - SCL
14-12 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.5.6. Calling an SCL Block

Input parameters and In/Out parameters are identified with :=


Output parameters with =>

FC Call FB Call

FBD

STL

SCL

Calling an SCL Block


Depending on the task, SCL blocks can be created as FC or FB. According to the principle of
structured programming, other function blocks, functions as well as instructions with and without
instance can also be called from an SCL block. In that way, other functions and function blocks
that were created in SCL or in another STEP 7 language (STL, LAD, etc.) can be called.

Note:
Functions usually calculate a return value / function value. This function value can be delivered to
the calling block via the output parameter RET_VAL. When a function which supplies a return
value / function value (RET_VAL) is called, this return value must be stored in an operand.
<Operand>:=<Function name> (Parameter list);
Functions with return value / function value can also be called directly in an expression. The
result of the expression is then formed with the calculated function value. For that reason, in SCL,
the data type ANY is not permitted for the function value.

TIA-PRO2 - SCL
Training Document, V15.01.00 14-13
SIMATIC TIA Portal S7-1500 Programming 2

14.5.7. Useful Function Expansions

Recursive block call in SCL

FC/FB

Multiple assignment:
• Easy assignment of a value to any number of variables (e.g. Initialization)

New arithmetic functions:


• +=, -=, *=, /=
• For S7-1200/1500

Recursive Block Call


It is possible to call a block recursively. That means that a block can call itself again. Keep in
mind that the call depth is limited to 24 and that no multiple instances can be used.

TIA-PRO2 - SCL
14-14 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.5.8. Monitoring SCL Blocks

When a variable is selected, the value is


displayed in the tooltip

Always the result of the instruction

Not executed instructions are greyed-


out

Display all values of the instruction

When the line is selected, the values are


presented in a popup

Monitoring an SCL Block


Just as in all other programming languages, SCL blocks can be monitored. All values of control
operation instructions are displayed when these are "opened and revealed".
The values of not executed instructions are grayed out.

Special Features of Selected Variables:


• In the online mode, a Tooltip displays the value of the variable.
• The value of IN-OUT variables is displayed before and after the call of the function.

TIA-PRO2 - SCL
Training Document, V15.01.00 14-15
SIMATIC TIA Portal S7-1500 Programming 2

14.6. Exercise 1: Copying the SCL Block from the Library

Task
You are to copy the prepared block "FB_Weight_SCL" from the "PRO2_Lib" global library into
your project.

What to Do
1. From the "Master copies > Chapter14" folder of the "PRO2_Lib" global library, copy the
"FB_Weight_SCL" block into your project using drag & drop.
2. Save your project.

TIA-PRO2 - SCL
14-16 Training Document, V15.01.00
SIMATIC TIA Portal S7-1500 Programming 2

14.6.1. Exercise 2: Exchanging the Call of "FB_Weight" with "FB_Weight_SCL"

Task
The new block "FB_Weight_SCL" fulfills the same function as "FB_Weight" did previously.
The block is now to be integrated into the program by you.

What to Do
1. In "OB_Cycle", instead of "FB_Weight" call the new block "FB_Weight_SCL". For this, use the
"Change block call" function; by double-clicking on the name of the already called
"FB_Weight" block at the call location.
2. Change the instance via the context menu at the call and give the new instance block the
symbolic name "iDB_FB_Weight_SCL".
3. Compile the program and download all changes into the CPU.
4. Open "DB_Weight" and monitor whether all data is correctly written, calculated and initialized.
5. Save your project.

TIA-PRO2 - SCL
Training Document, V15.01.00 14-17

You might also like