0% found this document useful (0 votes)
5 views13 pages

Structured Text Programming Cont

The document outlines the various types of operators used in Structured Text programming, including arithmetic, relational, logical, and bitwise operators, along with their precedence and functions. It also describes assignment statements, conditional statements (IF and CASE), and iteration using loops (FOR, WHILE, REPEAT). Additionally, it highlights the applications of Programmable Logic Controllers (PLCs) in various industries for automation tasks.
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)
5 views13 pages

Structured Text Programming Cont

The document outlines the various types of operators used in Structured Text programming, including arithmetic, relational, logical, and bitwise operators, along with their precedence and functions. It also describes assignment statements, conditional statements (IF and CASE), and iteration using loops (FOR, WHILE, REPEAT). Additionally, it highlights the applications of Programmable Logic Controllers (PLCs) in various industries for automation tasks.
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

• Operators Expression

- composed of operators and operands.


Operation Symbol Precedence
Parenthesization (expression) Highest
Function Evaluation MAX(A,B)

Negation –
Complement NOT
Exponentiation **
Multiply *
Divide /
Modulo MOD
Add +
Subtract –
Comparison <, >, <=, >=
Equality =
List of structured text operators Inequality <>
Boolean AND &/ AND
Boolean Exclusive OR XOR
Example: A + B * MAX(C, D)
Boolean OR OR Lowest
▪ Types of Operators
4 groups- Each group has a specific function and yields a specific data type.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
Arithmetic Operators
Represent math - called mathematical operators. Output- mathematical result of expression.
∙ + (add)
∙ – (subtract/negate)
∙ * (multiply)
∙ ** (exponent)
∙ / (divide)
∙ MOD (modulo divide)
Relational Operators
Used to compare or find a relation between two values.
Result- a boolean value (BOOL type), either TRUE or FALSE.
∙ = (equal)
∙ < (less than)
∙ <= (less than or equal)
∙ > (greater than)
∙ >= (greater than or equal)
∙ <> (not equal)
Logical Operators
Used to compare boolean values (BOOL) and make some logic out of it,
yield a boolean value of TRUE or FALSE as result of expression.
• & or AND
∙ OR
∙ XOR
∙ NOT
Example: LIMIT_SWITCH1 := TRUE;

LIMIT_SWITCH2 := FALSE;

LIMIT_SWITCH1 OR LIMIT_SWITCH2

Result: TRUE

Bitwise Operators
Operations are performed bitwise logic operation is performed for each bit of 2 numbers.
Result: a new number – total result of bitwise operations.
•& or AND
•OR
•XOR
•NOT
Bit number 1111 (15) 1000 (8) Result

Example: 15 AND 8 0 1 1 1
Result: 8 1 1 0 0

2 1 0 0

3 1 0 0
▪ Assignment Statement and Operator
Several statements available in Structured Text, representing action or condition.
With actions, most fundamental statement assignment statement.
Example: A := B;
To take the value of variable B and put it in variable A.
Assigning a value to a variable
Example: A := 10;
Another statement with an expression:
B := A + 2;
Compiler replaces expression with result 12. The statement appears to compiler as:
B := 12;
▪ Conditional Statements
PLC looks at states of all inputs and use PLC program to decide outputs to set.
In PLC program, one needs a way to make decisions conditional statements

Writing conditional statements - 2 ways


IF statements and CASE statements

IF statements are decisions with conditions.


Syntax for IF statements:

IF [boolean expression] THEN


<statement>;
ELSIF [boolean expression] THEN
<statement>;
ELSE
<statement>;
END_IF ;
Combination of multiple expressions is possible by a logical operator, to get a larger
expression.
IF (INPUT1) AND (INPUT2) THEN
OUTPUT1 := TRUE;
END_IF;

Expression evaluates to TRUE, only if INPUT1 and INPUT2 are TRUE.

▪ CASE Statements

- Second way of making decisions

CASE statements and IF statements are almost same.


But CASE statements use numeric expressions, instead of boolean expressions.
CASE statements have slightly different syntax – making more suitable for certain purposes.
Syntax for CASE statements:
PROGRAM_STEP := 3;
CASE [numeric expression] OF
CASE PROGRAM_STEP OF
result 1: <statement>;
1: PROGRAM_STEP := PROGRAM_STEP+1;
Result N: <statemtent>;
2: PROGRAM_STEP := PROGRAM_STEP+2;
ELSE
3: PROGRAM_STEP := PROGRAM_STEP+3;
<statement>;
ELSE
END_CASE;
PROGRAM_STEP := PROGRAM_STEP+10;
END_CASE;

▪ Iteration with Repeating Loops

• Most powerful features in Structured Text ability to make loops, repeating lines of code.
A function or a set of statements are executed a certain amount of times or until something
stops loop. 3 different types of repeating loops in Structured Text:
1. FOR 2. WHILE 3. REPEAT
Common for all types of loops - a condition for either repeating or stopping loop.
Condition in FOR and WHILE loops decides whether loop should repeat or not.
For REPEAT loop, condition is UNTIL condition decides whether loop should stop or
not.

• FOR Loops
Used to repeat a specificFOR
number of times. Other keywords: TO, BY, DO and END_FOR.
count := initial_value TO final_value BY increment DO
Syntax of FOR loops: <statement>;

END_FOR;

Use of IF with keyword EXIT to stop loop before the count. If added boolean condition is
TRUE, loop stops. IF [boolean expression] THEN

EXIT;

END_IF;
• WHILE Loops
Little different from FOR loop - used to repeat loop as long as some conditions are TRUE.
A WHILE loop repeats as long as a boolean expression is TRUE.
Syntax of WHILE loops: WHILE [boolean expression] DO

<statement>;

END_WHILE;

To stop loop at 1 point, a value in the boolean expression is to be changed.


Only then, boolean expression goes from TRUE to FALSE.
counter := 0;
Example:
WHILE counter < 10 DO

counter := counter + 1;

machine_status := counter * 10;

END_WHILE;
• REPEAT Loops
Last type of repeating loop, works the opposite way of WHILE loop. This loop stops
repeating when a boolean expression is TRUE.

Syntax for REPEAT loops:


REPEAT

<statement>;

UNTIL [boolean expression]

END_REPEAT;

Statements will always be executed at least 1 time.

Structured Text Programming Software


Beckhoff TwinCat 3: advantage- simulator, soft PLC
Codesys: open-source software environment
Applications of PLCs
▪ Programmable Logic Controllers suitable for variety of automation tasks.
They provide simple and economic solution to many automation tasks.
Examples:
• Logic/Sequence control
• PID control and computing
• Coordination and communication
• Operator control and monitoring
• Plant start-up, shut-down

▪ PLC’s find their applications in many industries, such as:


• Beverage production
• Food industries
• Automation industry
• Street/Traffic Lights
• Basically, any industry, aiming to reduce human input to minimize errors, uses PLCs
▪ Any manufacturing application, involving controlling repetitive, discrete operations is a
potential candidate for PLC usage,
e.g. machine tools, automatic assembly equipment, molding and extrusion machinery,
textile machinery and automatic test equipment.

Chemical/ Petrochemical Metals Manufacturing/Machining

Batch process Blast Furnace Material Conveyors, Cranes

Pipeline Control Continuous Casting Assembly

Weighing, Mixing Rolling Mills Milling, Grinding, Boring

Finished Product Handling Soaking Pit Plating, Welding, Painting

Water/ Waste Treatment Steel Melting Shop Molding/ casting/forming

Some Industrial Areas for Programmable Controller Application

You might also like