Advanced PLC 3
Advanced PLC 3
ADVANCED PLC
Dr. Tamer Fetouh
Mathematical Operations
• Tia portal provides different instructions for
Math functions that covers most of
calculations operations that may be needed in
control and monitoring.
• The complete list of math functions available
in S7-1200 PLC is shown in Fig.
• The data types of operand and the result
should be compatible with the data type of the
math function.
1
04/09/1444
Mathematical Operations
Calculate
• The "Calculate" instruction is used to define and execute an expression for
the calculation of mathematical operations or complex logic operations
depending on the selected data type.
• The following table shows the
instructions that, depending on the
selected data type, can be combined
and executed in the expression of the
"Calculate" instruction:
Mathematical Operations
2
04/09/1444
Mathematical Operations
Mathematical Operations
3
04/09/1444
Mathematical Operations
Mathematical Operations
4
04/09/1444
Mathematical Operations
• The mathematical instructions can be
included in the "Calculate" instruction or
have a separate blocks.
• For example, you can add two or more
inputs using the Calculate block or the
ADD block as shown below.
• To add more inputs to the Math operation,
use the * icon behind the IN2.
Mathematical Operations
• The MUL instruction shown in Fig. multiplies two inputs (IN1, IN2) and store the
result in (OUT).
• The data type of the MUL is set to Int
• The IN1 tag has a Real data type.
• The IN2 tag has an Int data type.
• The OUT tag has a Real data type.
• An Implicit conversion is carried out by default at
the OUT and IN1 to convert the data type from:
• Real to Int at the IN1
• Int to Real at the OUT
10
5
04/09/1444
Mathematical Operations
• The LIMIT operation guarantees the level of a specific signal is kept between
Minimum (MN) & Maximum (MX) levels.
11
6
04/09/1444
2. Explicit conversion
13
Conversion Operations
• The operands data types may need to be converted
from type to another to suit the operation block
data type.
• The instruction CONVERT is used to convert
explicitly the data types.
• Other conversion instructions are available as
shown in Fig.
• In addition, operands may need to be Scaled or
normalized. Using the instructions (SCALE_X,
NORM_X)
14
7
04/09/1444
Conversion Operations
• Round ➔ convert the number to the nearest integer number
Round (1.2) = 1 Round (1.7) = 2
Round ( – 3.95) = – 4 Round (– 3.1) = – 3
15
Conversion Operations
• Ceil ➔ convert the number to the higher integer number
Ceil (1.2) = 2 Ceil (1.7) = 2
Ceil ( – 3.95) = – 3 Ceil (– 5.49) = – 5
16
8
04/09/1444
Conversion Operations
SCALE_X ➔ To scale the value at the VALUE input by mapping it to a specified
value range (0 to 1 are mapped to MIN to MAX).
17
Conversion Operations
• The following figure shows how the values can be scaled.
𝑽𝒂𝒍𝒖𝒆 𝑶𝒖𝒕−𝑴𝑰𝑵
= MAX
𝟏−𝟎 𝑴𝑨𝑿−𝑴𝑰𝑵
Out
𝑶𝒖𝒕 = 𝑴𝑰𝑵 + 𝑽𝒂𝒍𝒖𝒆 ∗ (𝑴𝑨𝑿 − 𝑴𝑰𝑵)
MIN
• If the MIN = 0, then:
0 Value 1
𝑶𝒖𝒕 = 𝑽𝒂𝒍𝒖𝒆 ∗ 𝑴𝑨𝑿
18
9
04/09/1444
Conversion Operations
• If Min = 0, Max = 10, then:
19
Conversion Operations
• If Min = 5, Max = 10, then:
𝑶𝒖𝒕 = 𝟓 + 𝟓 ∗ 𝑽𝒂𝒍𝒖𝒆
20
10
04/09/1444
Conversion Operations
NORM_X ➔ To normalize the value of the tag at the VALUE input by mapping it
to a linear scale. (MIN to MAX are mapped to 0 to 1)
21
Conversion Operations
• The following figure shows how the values can be scaled.
𝑶𝒖𝒕 𝑽𝒂𝒍𝒖𝒆−𝑴𝑰𝑵
= 1
𝟏−𝟎 𝑴𝑨𝑿−𝑴𝑰𝑵
𝑽𝒂𝒍𝒖𝒆 − 𝑴𝑰𝑵 Out
𝑶𝒖𝒕 =
(𝑴𝑨𝑿 − 𝑴𝑰𝑵)
0
• If the MIN = 0, then:
Min Value MAX
𝑶𝒖𝒕 = 𝑽𝒂𝒍𝒖𝒆/𝑴𝑨𝑿
22
11
04/09/1444
Conversion Operations
• If Min = 0, Max = 10, then:
𝑽𝒂𝒍𝒖𝒆 𝑽𝒂𝒍𝒖𝒆
𝑶𝒖𝒕 = =
𝑴𝑨𝑿 𝟏𝟎
23
Conversion Operations
• If Min = 5, Max = 10, then:
𝑽𝒂𝒍𝒖𝒆 − 𝑴𝑰𝑵
𝑶𝒖𝒕 =
(𝑴𝑨𝑿 − 𝑴𝑰𝑵)
𝑽𝒂𝒍𝒖𝒆 − 𝟓
𝑶𝒖𝒕 =
𝟓
• If the input value is 8, then:
Out = ( 8 – 5 ) / 5 = 0.6
24
12