Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
Understanding Structured Control Language (SCL) Elements
Advanced

Understanding Structured Control Language (SCL) Elements

PLC Programming
Siemens
Structured Control Language (SCL)
TIA Portal

Introduction

Structured Text (ST) is an advanced PLC programming language established in the IEC 61131-3 standard, also known as Structured Control Language (SCL) in Siemens software. If you’re looking to become a Senior Automation Engineer, learning how to program Siemens PLCs using SCL is an important skill to have.

SCL is an important programming language for applications where industrial automation and IT overlap, such as smart factories, additive manufacturing, oil and gas, and networked control systems, to name a few.

In this tutorial, we will go over the fundamental elements of the SCL programming language. First, we’ll look at arithmetic, logical, and relational expressions. Next, we go over the different operators available within expressions. And finally, we look at how to assign expressions to tags using value assignments.

Prerequisites

To follow along with this tutorial, you’ll need:

SCL Elements

In addition to common PLC elements such as counters, inputs, coils, or memory bits, SCL has advanced elements including:

  • Expressions
  • Operators
  • Value assignments

As a result, SCL is well suited for applications such as data administration in IIoT systems, process improvement in the automotive industry, recipe control in food and beverages, and statistics and math challenges in equipment manufacturing.

Understanding SCL Expressions

Expressions are computed during program execution or program compilation and return a value. An Expression is made up of operands (for example, tags or constants) and possibly operators (for example, power (**) or subtraction (-)).

Figure 1.1: SCL expression components 

Expressions may be connected or nested inside of one another by operators.

Figure 1.2: SCL expression connection types

According to the operator, there are three types of Expressions available:

  • Arithmetic expressions
  • Relational expressions
  • Logical expressions

You will learn each one of them in detail in the next few sections.

Understanding SCL Arithmetic Expressions

Numerical values or combinations of two expressions or values using arithmetic operators make up arithmetic expressions. In figure 2.1, you can see some examples representing arithmetic expressions.

Figure 2.1: SCL arithmetic expressions examples

Arithmetic operations can process the permitted data types for the active CPU. If an arithmetic operation uses two operands, the data type of the result is decided based on the following standards: (Since there are many standards, we'll focus on the most common criteria)

  • A) The output is given the data type of the lengthier operand if both operands are integers with signs and of different lengths.
  • B) The output is given the data type of the lengthier operand if both operands are integers without signs and of different lengths.
  • C) If one integer operand has a sign and the other integer operand has no sign, the output is the next more extensive data type with a sign, which includes the integer without a sign.
  • D) When a floating-point number and an integer are both used as operands, the result is given the data type of the floating-point number.
  • E) The output is given the data type of the lengthier operand if both operands are floating-point numbers and of different lengths.
Figure 2.2: The result data type of SCL arithmetic expressions

Understanding SCL Relational Expressions

A Relational expression provides a Boolean value by comparing the data types or values of two operands. If the comparison holds correct, the outcome is True; else, it is False.

For example, look at the relational expression in the first sentence of the following IF statement. If the boiler temperature is below 100.00 Fahrenheit, the relational expression yields a Boolean value of True. And if the temperature sensor senses above 100.00 Fahrenheit, the relational expression returns a Boolean value of False.

Figure 3.1: SCL relational expression example

Understanding SCL Logical Expressions

Logical expressions use logical operators such as NOT, And or &, XOR, and OR to join two operands. If both operands of a logical expression have the data type Boolean, the result will also have this data type.

Figure 4.1: SCL logical expression example

If at least one of the operands is a bit string, the result is also a bit string, and the type of the highest operand determines the result type. For instance, when a Word type operand is linked to a Byte type operand, the outcome is of type Word.

Figure 4.2: The result data type of SCL logical expression

If you want to connect a Boolean type operand to a bit string, you must correctly convert it to a bit string.

Understanding SCL Operators

The most common operators used in arithmetic expressions, in order of precedence, are power, followed by multiplication, and division, followed by addition and subtraction. However, other operators such as unary plus, unary minus, modulo function, and combined value assignments are also available in arithmetic expressions as operators.

Figure 5.1: SCL operators' priority in arithmetic expressions

In order of precedence, the operators used in relational expressions are less than, greater than, less than or equal, greater than or equal, equal, and not equal.

Figure 5.2: SCL operators' priority in relational expressions

And in order of precedence, the operators used in logical expressions are Negation, Boolean And, Exclusive OR, and Boolean OR.

Figure 5.3: SCL operators' priority in logical expressions

Arithmetic operators are assessed first, followed by relational operators, and then by logical operators. Also, it is vital to keep in mind that whenever you see operations between brackets, they should be evaluated first.

For example, if you look at the following equations, you will understand that by using brackets, the order of priority can be changed, and thus, the output result can be altered.

Figure 5.4: An example of SCL operators' priority

Understanding Value Assignments in SCL

The value of an expression can be assigned to a tag by using a value assignment, which can be numerical or logical in arithmetic and logical expressions. The tag that accepts the value of the expression on the right is on the assignment operator’s (: =) left side.

Figure 6.1: Value assignments examples

A function's name can also be given as an expression. Value assignment calls the function, which then sends its function value to the tag on the left.

Figure 6.2: Calling FC from the SCL programming block

The tag data type on the left determines the data type of value assignment. There must be a match between this type and the data type of the expression on the right.

Figure 6.3: Data type match between value assignment and expression

The following choices are available when you are dealing with programming value assignments:

  • Single value assignments: When using single value assignments, a tag or an expression is only assigned to one tag. You can find the following assignments shown in figure 6.4.
  1. Assignment of a tag
  2. Assignment of an expression
  3. Assignment of a tag to a structure element
  4. Assignment of a tag to an ARRAY element
  5. Assignment of an ARRAY element to a tag
  6. Assignment of a STRING element to another STRING element
Figure 6.4: SCL single value assignments examples
  • Multiple value assignments: When assigning multiple values, several assignments can be carried out by a single instruction. For example, a := b := c; which is equivalent to the following notation: b := c; and a := b; You can find the following assignments in the picture below the list. shown in figure 6.5.
  1. Assignment of a tag
  2. Assignment of an expression
  3. Assignment of a tag to two structure elements
  4. Assignment of a tag to two ARRAY elements
  5. Assignment of an ARRAY element to two tags
  6. Assignment of a STRING element to two STRING elements
Figure 6.5: SCL multiple value assignments examples
  • Combined value assignments: The addition (+), subtraction (-), multiplication (*), and division (/) operators can be used in conjunction with the assignment operator in the case of combined value assignments. For example, a += b; which is equivalent to the following notation: a := a + b; Additionally, you can repeat the assignment of combination value assignments. For instance, a += b += c *= d; which is equivalent to the following notation: c := c * d; and b := b + c; and a := a + b; In the picture below figure 6.6, you can see another example of this type of assignment.
Figure 6.6: SCL combined value assignments examples

Conclusion

In this tutorial, you learned about SCL elements, expression function, different types of expressions, operator function, different types of operators, value assignment functions, and the different kinds of value assignments available in SCL elements.

Understanding SCL programming elements is essential in getting started with Siemens PLC programs using Structured Control Language (SCL).