The document discusses various logic functions, timers, counters, math instructions, and program flow instructions that can be implemented in a PLC ladder logic program. It includes examples of how to use NOT, AND, OR, XOR logic gates. It also provides details on using on delay and off delay timers, accumulative timers, up counters, and up/down counters. Additionally, it demonstrates how to use math instructions like add, subtract, multiply, divide, compare values, use shift registers, conditional jumps, and call subroutines in a PLC program.
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
Automation and Robotics 20ME51I_Week_2_Practicals.pdf
1. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 17
2. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 18
7. Recap and Practice PLC Ladder Diagram for Logic Gates, Timers, Counters
Hardware: Desktop with latest windows configuration and PLC Trainer kit (DVP-14SS2)
Software: PLC programming software- WPLSoft 2.48
Communication Protocol: Serial communication RS-232
NOT
NOT
X0 Y0
0 1
1 0
1. One Normally Closed contact, NOT Logic Gate can be implemented.
2. Inverted state of input is obtained as an output.
AND
AND
X0 X1 Y0
0 0 0
0 1 0
1 0 0
1 1 1
1. Normally Open contacts in series, AND gate can be implemented.
2. When both inputs are set to 1, then and then only output goes high.
3. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 19
NAND
NAND
X0 X1 Y0
0 0 1
0 1 1
1 0 1
1 1 0
Normally Closed contacts in parallel to each other, NAND Gate can be implemented.
OR
OR
X0 X1 Y0
0 0 0
0 1 1
1 0 1
1 1 1
1. Normally Open contacts in parallel, OR Gate can be implemented.
2. When either input is set to high, output goes high.
4. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 20
NOR
NOR
X0 X1 Y0
0 0 1
0 1 0
1 0 0
1 1 0
1. Normally Closed contacts in series, NOR Logic Gate can be implemented.
2. If both inputs are Reset to 0, output goes High otherwise remains in Low state.
EX-OR
EX-OR
X0 X1 Y0
0 0 0
0 1 1
1 0 1
1 1 0
1. Normally Opened and Normally Closed in series with parallel to Normally Closed
and Normally Opened in series, EX-OR Gate can be implemented.
2. When both inputs are identical, output is 0. Output is high when X0 ≠ X1.
5. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 21
EX-NOR
EX-NOR
X0 X1 Y0
0 0 1
0 1 0
1 0 0
1 1 1
1. Normally Closed contacts in series with parallel to two Normally Opened contacts
in series, EX-NOR gate can be implemented.
2. When both inputs are identical X0=X1=0 or X0=X1=1, output Y0 goes high.
Timer instructions in DVP 14 SS2 PLC
Timers are available in resolutions of 1ms, 10ms and 100ms and the counting method
is count-up.
Device Item Range Function
T
100ms
Timer
T0~T126------------------------------127 points
T128~T183----------------------------56 points
Total
256
points
Timer indicated by TMR
instruction. If timing
reaches its target, the T
contact of the same
number will be ON.
T184~T199 for Subroutines---------16 points
T250~T255(accumulative)------------6 points
10ms
Timer
T200~T239----------------------------40 points
T240~T245(accumulative)------------6 points
1ms
Timer
T127--------------------------------------1 points
T246~T249(accumulative)------------4 points
The set value should be a K value in decimal and can be specified by the content of
data register D. The actual set time in the timer = timer resolution× set value
Ex: If set value is K100 and timer resolution is 100 ms, the actual set time in timer
will be 100 ms×100 =10,000ms = 10sec
6. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 22
1. General Timers (On Delay & Off Delay)
Generally, timers are used to control the circuit for a certain amount of time. Using
timers, we can delay the circuit operation. Two types of timers are the most used in the electric
circuit. One is On-delay timer (TON), and the second one is off-delay timer (TOF). All are
functionally same but the delaying operation will be varied.
On Delay
Off Delay
Implementing ON DELAY using PLC built in Timers
ON delay = delayed ON. It means the timer does not give the output until the preset
time reached. After reaching the preset time the timer makes the contact changeover. Such
Timers are called ON delay timers.
When X0 = ON, TMR instruction is driven. When current value achieves K100, the
associate timer contact T0 is ON to drive Y0. If X0 = OFF or the power is off, the current value
in T0 will be cleared (Reset) as 0 and output Y0 driven by contact T0 will be OFF.
7. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 23
Implementing OFF DELAY using PLC built in Timers
OFF-delay = delayed OFF. It means that, even if you cut the input power to the timer,
the timer still provides the output and it turns OFF after the delay of preset time.
2. Accumulative (Retentive) Timer
The timer executes once when the program reaches END instruction. When TMR
instruction is executed, the timer coil will be ON when the current value reaches its preset
value. For accumulative timers, current value will not be cleared (Reset) when timing is
interrupted.
Timer T250 will be driven when X0
= ON. When X0 = OFF or the power is off,
timer T250 will pause and retain the current
value. When X0 is ON again, T250 resumes
timing from where it was paused. When X1
= ON, T250 timer we become Reset.
8. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 24
3. Timers for Subroutines and Interrupts
Timers for subroutines and interrupts count once when END instruction is met. The
associated output coils will be ON if the set value is achieved when End instruction executes.
T184~T199 are the only timers that can be used in subroutines or interrupts. General timers
used in subroutines and interrupts will not work if the subroutines or interrupts are not
executing.
Counter instruction in DVP 14 SS2 PLC
Counters will increment their present count value when input signals are triggered from
OFF→ON (Momentary).
Device Item Range
C
16-bit count-up C0~C199………………………...199 points
Total
233 points
32-bit count up/down C200~C232……………………….33 points
32bit high-speed
count up/down
Soft-ware
Hard-ware
C235~C242………………………...8 points
Total
22 points
C233~C234………………………...2 points
C243~C244………………………...2 points
C245~C250………………………...6 points
C251~C254………………………...4 points
16-bit counters
The 16-bit counter counts a maximum value 32767. So, If we want to count the items
more than 32767 then 32-bit counters are used.
Counter instructions come in two basic types:
1. Up counters,
2. Up/down counters
9. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 25
1. Up Counter (CTU): These counters are incrementing counter, which means it counts up.
Example
When X0 = ON, RST instruction resets C0. Every time When X1 is driven, C0 will
count-up (add 1). When C0 reaches the preset value K5, output coil Y0 will be ON and C0 will
stop counting and ignore the signals from input X1.
2. Up/down Counters: These Counters are used to counting up/down function.
Example
1. DCNT instruction enables the 32-bit high-speed counters C200 ~ C255.
2. For general purpose addition/subtraction counters C200~C234. When DCNT instruction
is set from OFF to ON, the present value in the counter will count up (plus 1) or count
down (minus 1) according to the modes set in special M1200 ~ M1234.
3. Counting actions: Counting-up (present value plus “1”); counting down (present value
minus “1”)
4. When DCNT instruction goes “OFF”, the counter stops counting, but the present value
will not be cleared.
10. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 26
8. Explain and Practice PLC Ladder Diagram for Math Instructions, compare, Shift
Registers, Conditional jump and jump to subroutine
Math Instruction:
Use all the Math Instructions to implement various Mathematical Arithmetic Functions.
1. Use ADD to add one piece of data to another.
2. Use SUB to subtract one piece of data from another.
3. Use MUL to multiply one piece of data by another.
4. Use DIV to divide one piece of data by another.
5. Use SQR to find the square root of a piece of data.
6. Use NEG to change the sign of a piece of data.
PLC Program
List of Inputs and Outputs
X0 = Input A to Add (Input)
X1 = Input B to Subtract (Input)
X2 = Input C to Multiply (Input)
X3 = Input D to Divide (Input)
X4 = Input E to find Square Root (Input)
X5 = Input F to change the sign of a Number (Input)
11. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 27
Compare Instruction:
Compare instruction is commonly used to compare values and make decisions based
on the result. If the comparison is true, a specific action or sequence of actions may be executed.
If the comparison is false, an alternative action or sequence of actions may be taken.
1. Equal to (=)
2. Greater than (>)
3. Less than (<)
4. Greater than or equal to (>=)
5. Less than or equal to (<=)
1. Equal block (LD= D0 D1) is used to compare the two values and gives output as “1” if
both are equal and “0” if both are not equal.
2. Greater than block (LD> D0 D1) is used to compare the two values and gives output as
“1” if D0 value is Greater than D1 value and “0” if D0 value is lesser than or equal to D1
value.
3. Lesser than block (LD< D0 D1) is used to compare the two values and gives output as
“1” if D0 value is Lesser than D1 value and “0” if D0 value is greater than or equal to
D1 value.
4. Greater than or equal to block (LD>= D0 D1) is used to compare the two values stored
in D0 and D1 and gives output as “1” if D0 value is greater than or equal value to D1
value and “0” if D0 value is greater D1 value.
5. Lesser than or equal to block (LD<= D0 D1) is used to compare the two values stored in
D0 and D1 and gives output as “1” if D0 value is lesser than or equal value to D1 value
and “0” if D0 value is greater D1 value.
12. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 28
Shift registers
The term register is used to store binary data (0s & 1s). The shift register is a number
of internal relays grouped together that allow stored bits to be shifted from one relay to another.
Normally 8, 16, or 32. The term bit is used for each such binary digit. Therefore, if we
have eight internal relays in the register, we can store eight 0 or 1 states.
Each relay might store an OFF/ON (0s/1s) signal. Below Example: relay 1 is on, relay
2 is off, relay 3 is on, relay 4 is on, relay 5 is off, and so on.
Shift registers require three inputs:
1. To load data into the first location of the register,
2. To give command to shift data along by one location,
3. To reset or clear the register of data.
To illustrate this idea, consider the following situation where we start with an 8-bit
register in the following state:
Suppose we now receive the input signal 0. This is an input signal to the first internal relay.
Thus, a set of internal relays that were initially 1, 0, 1, 1, 0, 0, 1, 0 are now 0, 1, 0, 1, 1, 0, 0, 1
13. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 29
Bit shift Left
BSL (Bit Shift Left) instruction, the bits are shifted to the left each time the instruction
goes true. BSL - shifts left from the LSB to the MSB. The LSB must be supplied
Example:
14. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 30
Bit shift Right
BSR (Bit Shift Right) is that the bits are shifted to the right each time the instruction
goes true. BSR – the bit is input to the MSB and shifted to the LSB
Example:
15. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 31
Conditional jump
A function which is often provided with PLCs is the conditional jump function. Such a
function enables programs to be designed so that if a certain condition exists then a section of
the program is jumped. The JMP instruction will allow the PLC to bypass some ladder logic
instructions.
Following a section of program, A, the program rung is encountered with Input 1 and
the conditional jump relay CJP. If Input 1 occurs then the program jumps to the rung with the
end of jump relay coil EJP and so continues with that section of the program labelled as C,
otherwise it continues with the program rungs labelled as program B.
Conditional jump instruction in Delta PLC
16. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 32
Example 1
1. The input (X0) Input CJ is used to drive Conditional Jump Instruction.
2. The input (X1) Switch 1 is used to turn on (Y0) Motor 1.
3. The input (X2) Switch 2 is used to turn on (Y1) Motor 2.
4. The input (X3) Switch 3 is used to turn on (Y2) Motor 3.
5. (P0) is destination pointer of conditional jump.
Example 2
17. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 33
Call Subroutine
Sub routines are sub programs in a PLC project used to split the whole program by its
function or sequence which can call the sub programs using call instruction.
Operands:
S: The destination pointer P of the call subroutine.
Explanations:
1. When the CALL instruction is active it forces the program to run the subroutine
associated with the called pointer.
2. A CALL instruction must be used in conjunction with FEND (First End) and SRET
(Subroutine Return) instructions.
3. The program jumps to the subroutine pointer (located after an FEND instruction) and
processes the contents until an SRET (Subroutine Return) instruction is encountered.
This forces the program flow back to the line of ladder immediately following the
original CALL instruction.
18. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 34
Program example 1:
When X7 = ON, the CALL instruction will jump to P0 and run the subroutine. With
the execution of the SRET instruction, it will jump back and continue the execution.
19. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 35
Program example 2:
When X7 = ON, the CALL instruction will jump to P0 and run the subroutine (Turning
ON Y0 Lamp 1 for 10 sec). When X6 = ON, the CALL instruction will jump to P1 and run the
subroutine (Turning ON Y1 Lamp 2 for 15 sec). With the execution of the SRET instruction,
it will jump back and continue the execution.
20. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 36
9. Explain and Practice PLC Program using Functional Block Diagram (FBD)
FBDs are part of the IEC 61131-3 standard, which defines a set of programming
languages for PLCs.
FBDs consist of various interconnected function blocks, which are graphical
elements representing specific operations or functions. These function blocks can include
logical operations, mathematical calculations, input/output operations, timers, counters,
and other control functions.
Key elements of Function Block Diagrams:
1. Function Blocks: These are the basic building blocks of an FBD. Each function block
performs a specific operation or function. They can be logical operations like AND,
OR, NOT gates, timers, counters, arithmetic operations etc,
2. Input and Output Variables: Function blocks have input and output variables that allow
them to interact with other function blocks or external devices. Inputs represent signals
or data coming into a function block, and outputs represent the results or processed data
generated by the functional block.
3. Connections and Signals: Function blocks are connected together using lines that
represent the flow of signals or data between them.
4. Data Types: FBDs support different data types such as Boolean (true/false), integer,
floating-point numbers, time and more.
5. Networks: FBDs are organized into networks, which are groups of interconnected
function blocks. Each network represents a specific operation or control task.
21. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 37
FBD- logic Gates
Logic Ladder mode
FBD (Data type for I/P and O/P is
BOOL)
NOT
AND
OR
NAND
NOR
XOR
XNOR
22. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 38
Arithmetic Operation (Data type INT/REAL for both I/P and O/P)
Instruction Description Function Block Diagram
ADD
Use ADD to add one
piece of data to another.
SUB
Use SUB to subtract one
piece of data from
another.
MUL
Use MUL to multiply
one piece of data by
another.
DIV
Use DIV to divide one
piece of data by another.
MOD
Use MOD to find the
reminder of data pieces
23. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 39
Comparision Operations (Data type INT/REAL for I/P and BOOL for O/P)
Instruction Description Function Block Diagram
GT
GT block is used to
compare the two values
and gives output as “1” if
IN1 greater than IN2 and
“0” if it is not.
GE
GE block is used to
compare the two values
and gives output as “1” if
IN1 greater than equal to
IN2 and “0” if it is not.
EQ
EQ block is used to
compare the two values
and gives output as “1” if
both are equal and “0” if
both are not equal
LT
LT block is used to
compare the two values
and gives output as “1” if
IN1 Less than IN2 and “0”
if it is not.
NE
NE block is used to
compare the two values
and gives output as “1” if
both are not equal and “0”
if both are equal
LE
GT block is used to
compare the two values
and gives output as “1” if
IN1 less than equal to IN2
and “0” if it is not.
24. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 40
Timers (Data type for I/P and O/P is BOOL)
Instruction Description
Function
Block
Diagram
TON
An on-delay timer
will wait for a set
time after a line of
ladder logic has been
true before turning
on, but it will turn off
immediately.
TOF
An off-delay timer
will turn on
immediately when a
line of ladder logic is
true, but it will delay
before turning off.
Counters (Data type for I/P and O/P is BOOL)
Instruction Description
Function
Block
Diagram
CTU
This particular
counter instruction
(CTU) is an
incrementing
counter, which
means it counts up
CTD
This particular
counter instruction
(CTD) is decrement
counter, which
means it counts
down
25. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 41
Case study 1: There are 3 mixing devices on a processing line A, B, C. After the process
begin mixer-A is to start after 7 seconds elapse, next mixer-B is to start 3.6 second after
A. Mixer-C is to start 5 seconds after B. All of them remain ON until a master enable
switch is turned off. Develop Functional Block diagram.
We can solve this problem by using simple time logic. Particular time delay is generated to mix the
materials for a definite time. For mixing, agitator is used and it is connected with motor shaft. Here
materials are mixed until it reaches the set point (Master enable switch is turned off).
# Name Class Type
1 START Local BOOL
2 STOP Local BOOL
3 RELAY Local BOOL
4 MOTOR1 Local BOOL
5 MOTOR2 Local BOOL
6 MOTOR3 Local BOOL
Variable Declaration
26. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 42
Case study 2: Write a FBD to count the number of Items moving on a conveyor Belt and
Simulate the Same
1. Mostly proximity sensors are used to detect the objects. Here we mount proximity sensor to
detect the parts or objects moving on the conveyor.
2. Inductive sensor is mostly used to detect metal objects. For other type of objects, Capacitive
proximity sensor for detecting the objects moving on the conveyor. We connect this sensor
to the PLC and by using counter logic, we will count the number of objects.
# Name Class Type
1 START Local BOOL
2 STOP Local BOOL
3 RELAY Local BOOL
4 MOTOR Local BOOL
5 RESET Local BOOL
Variable Declaration
27. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 43
Case study 3: Execute the FBD for relay-based motor control automation such that the
motor reverses its direction when the limit switches are activated.
1. The Workpiece starts moving on the left side and moves to the right when the start button is
pressed.
2. When it reaches the rightmost limit, the drive motor reverses and brings the workpiece back to
the leftmost position again and the process repeats.
3. The forward and reverse pushbuttons provide a means of starting the motor in either forward or
reverse so that the limit switches can take over automatic control.
# Name Class Type
1 START Local BOOL
2 STOP Local BOOL
3 RELAY Local BOOL
4 MOTOR_COIL1 Local BOOL
5 MOTOR_COIL2 Local BOOL
6 Position1_sen Local BOOL
7 Position2_sen Local BOOL
Variable Declaration
28. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 44
Case study 4: Develop the FBD for an alarm system
1. Here we can use two sensors, one motion sensor and second window sensor. Window sensor is the
loop of wires.
2. The motion sensor is designed such that when person is detected in a house or room, then
the sensor will be activated (change its state to ON)
3. In window sensor the current is always passing until the breakage occurs in the glass. Hence output
always true and when someone will try to break the window glass, current will not flow in the circuit
and turned to OFF.
# Name Class Type
1 START Local BOOL
2 STOP Local BOOL
3 RELAY Local BOOL
4 MOTION_SEN Local BOOL
5 WINDOW_SEN Local BOOL
6 ALARM_STOP Local BOOL
7 ALARM Local BOOL
Variable Declaration
29. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 45
Case study 5: Develop the FBD for Water level controlling
1. To detect high and low level of liquid in the tank, two level switches/sensors are used
which gives output in digital (ON/OFF), that is when corresponding levels are detected,
it gives output high otherwise remain low.
2. Start/stop is provided to start or shut down the entire process. To control level of this
system, valve can be used which has two states, either fully open or fully close.
3. Level low Switch is mounted at the bottom of the tank and Level High switch
mounted at the side upper most position.
# Name Class Type
1 START Local BOOL
2 STOP Local BOOL
3 COIL Local BOOL
4 HLS Local BOOL
5 LLS Local BOOL
6 IN_VALVE Local BOOL
7 OUT_VALVE Local BOOL
Variable Declaration
30. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 46
10. Practice PLC Program using Structural Text language
PLC (Programmable Logic Controller) Structural Text language refers to one of the
programming languages used for programming PLCs.
Structured Text is a high-level textual programming language that is like other
programming languages such as Pascal or C. It is used to write complex control algorithms and
logic for industrial automation systems. ST is based on structured programming concepts, that
use control structures like loops, conditionals, and functions.
Key features and elements of the PLC structural text:
1. Variables: Variables are used to store and manipulate data within the PLC program.
They can be defined with specific data types, such as Boolean, integer, real, etc.
2. Data Types: PLC programming languages support various data types, including integer
(INT), real (REAL), Boolean (BOOL), timers (T), counters (C), arrays, and more. These
data types determine the kind of data that can be stored in variables and how they can
be manipulated.
3. Operators: Operators are used to perform mathematical, logical, and comparison
operations on variables and values. Examples of operators include arithmetic operators
(+, -, *, /), logical operators (AND, OR, NOT), and comparison operators (=, <, >, <=,
>=, <>).
4. Control Structures: PLC programming languages support control structures to control
the flow of the program execution. These include conditional statements (IF-THEN-
ELSE), loops (FOR, WHILE), and case statements (CASE, SELECT).
5. Commenting: Comments are used to add explanatory notes or remarks within the
program. They are ignored by the PLC during program execution but serve as helpful
documentation for programmers.
31. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 47
Arithmetic operators (+, -, *, /)
Arithmetic operators are used to perform mathematical operations on numerical values.
1. Addition: +
The addition operator is used to add two values together.
Example: result := data1 + data2;
2. Subtraction: -
The subtraction operator is used to subtract one value from another.
Example: result := data1 - data2;
3. Multiplication: *
The multiplication operator is used to multiply two values.
Example: result := data1 * data2;
4. Division: /
The division operator is used to divide one value by another.
Example: result := data1 / data2;
5. Modulus: MOD
The modulus operator calculates the remainder of the division between two values.
Example: result := data1 MOD data2;
These operators can be combined and used within expressions to perform various
mathematical calculations in Structured Text.
32. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 48
Logical operators (AND, OR, NOT)
In Structured Text (ST), logical operators are used to evaluate conditions and perform
logical operations on Boolean values. The common logical operators in ST are:
1. Logical AND: AND
The logical AND operator returns true if both inputs are true; otherwise, it returns false.
Example: result := event1 AND event2;
2. Logical OR: OR
The logical OR operator returns true if at least one of the operands is true; otherwise, it
returns false. Example: result := event1 OR event2;
3. Logical NOT: NOT
The logical NOT operator negates the value of the input.
Example: result := NOT event;
Logical operators can be combined and used within logical expressions to create
complex conditions and control the flow of the program based on the evaluation of those
conditions.
Example of using logical operators in conditional statement IF-THEN-ELSE:
VAR
a: Bool;
b: Bool;
result: Bool;
lamp1: Bool;
lamp2: Bool;
END_VAR
result := a AND b (* Logical expression *)
IF result THEN
lamp1 := TRUE;
lamp2 := FALSE;
ELSE
lamp1 := FALSE;
lamp2 := TRUE;
END_IF;
The logical expression ‘(a AND b)’ is evaluated. If the result of the expression is true,
the statements within the ‘IF’ block will be executed. Otherwise, the statements within the
‘ELSE’ block will be executed.
33. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 49
Comparison operators (=, <>, <, >, <=, >=)
Comparison operators are used to compare values and gives Boolean result (true or
false) based on the outcome of the comparison. The common comparison operators in ST are:
1. Equal To: =
The equal to operator checks if two values are equal.
Example: result := data1 = data2;
2. Not Equal To: <> or #
The not equal to operator checks if two values are not equal.
Example: result := data1 <> data2;
3. Less Than: <
The less than operator checks if the first value is less than the second value.
Example: result := data1 < data2;
4. Greater Than: >
The greater than operator checks if the first value is greater than the second value.
Example: result := data1 > data2;
5. Less Than or Equal To: <=
The less than or equal to operator checks if the first value is less than or equal to the
second value.
Example: result := data1 <= data2;
6. Greater Than or Equal To: >=
The greater than or equal to operator checks if the first value is greater than or equal to
the second value.
Example: result := data1 >= data2;
These comparison operators can be used in conditional statements, such as IF-THEN-
ELSE statements or while evaluating logical expressions, to control the flow of the program
based on the comparison results.
34. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 50
Example of comparison operators in Structured Text:
VAR
a: INT;
b: INT;
result: BOOL;
motor1 := BOOL;
motor2 := BOOL;
END_VAR
result := a < b;
IF result THEN
motor1 := TRUE;
motor2 := FALSE;
ELSE
motor1 := FALSE;
motor2 := TRUE;
END_IF;
In this example, the comparison expression ‘a < b’ compares the values of variables ‘a’
and ‘b’. If the result of the comparison is true (i.e., ‘a’ is less than ‘b’), the statements within
the ‘IF’ block will be executed. Otherwise, the statements within the ‘ELSE’ block will be
executed.
35. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 51
Control structure: Syntax
Conditional statement (IF-THEN-ELSE)
IF-THEN-ELSE statement is used to conditionally execute different blocks of
code based on a specified condition (result of evaluation).
IF condition THEN
(* executes if the result of evaluation is true *)
Statement 1;
Statement 2;
Statement n;
ELSE
(* executed if the result of evaluation is false *)
Statement 3;
statement 4;
statement n;
END_IF;
IF is the conditional statement.
‘condition’ is the expression that evaluates to either true or false.
It can be a logical expression, a comparison, or any other expression that gives a Boolean result.
‘THEN’ beginning of the block of statements executed if the condition is true.
‘statement1’, ‘statement2’, and any additional statements are executed if the condition is true.
‘ELSE’ beginning of the block of statements executed if the condition is false.
‘statement3’, ‘statement4’, and any additional statements are executed if the condition is false.
‘END_IF’ ends the conditional statement.
Example of IF-THEN-ELSE construct in Structured Text:
VAR
temperature: INT;
coolingFan: BOOL;
heatingElement:= BOOL;
END_VAR
IF temperature > 30 THEN
coolingFan := TRUE;
heatingElement := FALSE;
ELSE
coolingFan := FALSE;
heatingElement := TRUE;
END_IF;
The program checks the value of the ‘temperature’ variable. If it is greater than 30,
it sets the ‘coolingFan’ variable to ‘TRUE’ and the ‘heatingElement’ variable to ‘FALSE’.
Otherwise, if the temperature is not greater than 30, it sets ‘coolingFan’ to ‘FALSE’ and
‘heatingElement’ to ‘TRUE’.
36. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 52
Timer in Structured Text
In Structured Text (ST), timers are commonly used to create time-based delays, control
the execution of certain tasks, or measure the elapsed time.
VAR
MyTimer: TON; (* Declare a timer variable *)
DelayTime: TIME := T#50s; (* Set the desired delay time *)
END_VAR
MyTimer(IN := TRUE, PT := DelayTime);
(* Check if the timer is done *)
IF MyTimer.Q THEN
(* Timer is done, perform actions *)
statement1;
statement2;
(* Additional statements *)
END_IF;
In this example, we use a timer variable named MyTimer of type TON (Timer ON-
delay).
1. We declare the MyTimer variable of type TON to represent the timer.
2. We set the DelayTime variable to the desired delay time. In this case, it's set to T#50s,
which represents 50 seconds.
3. To start the timer, we provide the input condition TRUE to MyTimer.IN and set the
preset time MyTimer.PT to the DelayTime value.
4. We then check if the timer is done using the Q output of the timer (MyTimer.Q).
When the timer reaches the preset time (DelayTime), MyTimer.Q becomes true,
indicating that the specified delay has elapsed.
5. If the timer is done (i.e., MyTimer.Q is true), we can perform the desired actions,
denoted by statement1, statement2, and any additional statements.
37. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 53
1. There are 3 mixing devices on a processing line A, B, C. After the process begin
mixer-A is to start after 7 seconds elapse, next mixer-B is to start 3.6 second after
A. Mixer-C is to start 5 seconds after B. All them remain ON until a master enable
switch is turned off. Develop structured text program.
Timers are commonly used to create time-based delays, control the execution of
this tasks.
# Name Class Type
Initial
Value
1 start Local BOOL
2 stop Local BOOL
3 coil Local BOOL
4 mixerA Local BOOL
5 mixerB Local BOOL
6 mixerC Local BOOL
7 timer1 Local TON
8 timer2 Local TON
9 timer3 Local TON
10 delay1 Local TIME T#7s
11 delay2 Local TIME T#3.6s
12 delay3 Local TIME T#5s
IF (start OR coil) AND NOT stop THEN
coil:= TRUE;
ELSE
coil:= FALSE;
END_IF;
Timer1(IN := coil, PT := delay1);
IF timer1.Q THEN
mixerA:= TRUE;
END_IF;
Timer2(IN := (coil AND mixerA), PT := delay2);
IF timer2.Q THEN
mixerB:= TRUE;
END_IF;
Timer3(IN := (coil AND mixerB), PT := delay3);
IF timer3.Q THEN
mixerC:= TRUE;
END_IF;
IF stop THEN
mixerA:= FALSE;
mixerB:= FALSE;
mixerC:= FALSE;
END_IF;
38. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 54
2. Execute the Structured Text for relay-based motor control automation such that
the motor reverses its direction when the limit switches are activated.
1. The Workpiece starts moving on the left side and moves to the right when the start
button is pressed.
2. When it reaches the rightmost limit, the drive motor reverses and brings the workpiece
back to the leftmost position again and the process repeats.
3. The forward and reverse pushbuttons provide a means of starting the motor in either
forward or reverse so that the limit switches can take over automatic control.
Variable declaration
# Name Class Type
1 start Local BOOL
2 stop Local BOOL
3 coil Local BOOL
4 Position1_sen Local BOOL
5 Position2_sen Local BOOL
6 motor_coil1 Local BOOL
7 motor_coil2 Local BOOL
IF (start OR coil) AND NOT stop THEN
coil:= TRUE;
ELSE
coil:= FALSE;
END_IF;
IF (coil AND (position1_sen OR motor_coil1) AND NOT position2_sen) THEN
motor_coil1:= TRUE;
ELSE
motor_coil1:= FALSE;
END_IF;
IF (coil AND (position2_sen OR motor_coil2) AND NOT position1_sen) THEN
motor_coil2:= TRUE;
ELSE
motor_coil2:= FALSE;
END_IF;
39. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 55
3. Develop the ST program for an alarm system
# Name Class Type
1 start Local BOOL
2 stop Local BOOL
3 coil Local BOOL
4 motion_sen Local BOOL
5 window_sen Local BOOL
6 stop_alarm Local BOOL
7 alarm Local BOOL
IF (start OR coil) AND NOT stop THEN
coil:= TRUE;
ELSE
coil:= FALSE;
END_IF;
IF (coil AND (motion_sen OR alarm OR (NOT window_sen)) AND NOT
stop_alarm) THEN
alarm:= TRUE;
ELSE
alarm:= FALSE;
END_IF;
40. PLC, SCADA & HMI: INDUSTRIAL AUTOMATION
PRACTICAL HAND BOOK Page 56
4. Develop the ST program for Automatic Water level controlling system
# Name Class Type
1 start Local BOOL
2 stop Local BOOL
3 coil Local BOOL
4 motion_sen Local BOOL
5 window_sen Local BOOL
6 stop_alarm Local BOOL
7 alarm Local BOOL
IF (start OR coil) AND NOT stop THEN
coil:= TRUE;
ELSE
coil:= FALSE;
END_IF;
IF (coil AND (lhs OR outlet) AND NOT lls) THEN
outlet:= TRUE;
ELSE
outlet:= FALSE;
END_IF;
IF (coil AND (lls OR pump) AND NOT lhs) THEN
pump:= TRUE;
ELSE
pump:= FALSE;
END_IF;