Chapter 10 Structured Texti

Download as pdf or txt
Download as pdf or txt
You are on page 1of 69

Compact Control Builder Training

Chapter 10 Structured Text

TABLE OF CONTENTS

Chapter 10 Structured Text ............................................................................................................................................................1


10.1 General Information ...........................................................................................................................................................2
10.1.1 Objectives ....................................................................................................................................................................2
10.1.2 Legend .........................................................................................................................................................................2
10.1.3 Reference Documentation ...........................................................................................................................................2
10.2 Structured Text ...................................................................................................................................................................3
10.2.1 Advantages of Using Structured Text..........................................................................................................................3
10.2.2 Structured Text Editor .................................................................................................................................................4
10.3 Basic Language Elements...................................................................................................................................................5
10.3.1 Assignment Statements................................................................................................................................................5
10.3.2 Comment Statements...................................................................................................................................................5
10.3.3 Operators .....................................................................................................................................................................6
10.3.4 Precedence...................................................................................................................................................................7
10.3.5 Conditional Structures .................................................................................................................................................8
10.3.6 Iteration Structures ......................................................................................................................................................9
10.3.7 RETURN Statement ..................................................................................................................................................10
10.4 Functions and Function Blocks ........................................................................................................................................10
10.4.1 Functions ...................................................................................................................................................................10
10.4.2 Function Blocks.........................................................................................................................................................10
10.4.3 How to Declare Function Block Instances ................................................................................................................11
10.4.4 How to Call a Function Block Instance .....................................................................................................................11
10.5 Common Mistakes and their Error Messages ...................................................................................................................14
10.6 How to Declare Variables from Error Messages ..............................................................................................................17
10.7 How to Change from ST to Function Block in Online mode ...........................................................................................18

Chapter 10 - 1
T530-10 Structured Text - RevG

10.1 General Information

10.1.1 Objectives
On completion of this chapter you will be able to:
• Describe the Structured Text Language rules
• Write simple application code in ST
• Use Functions and Function Blocks in ST

10.1.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

10.1.3 Reference Documentation


3BSE044222 Industrial IT – Compact Control Builder AC 800M
Application Programming – Introduction and Design
3BSE040935 Industrial IT – Compact Control Builder AC 800M
Basic Control Software – Introduction and Configuration
3BSE041488 Industrial IT – Compact Control Builder AC 800M
Extended Control Software – Binary and Analog Handling

Chapter 10 - 2
Compact Control Builder Training

10.2 Structured Text


Structured Text (ST) is a high-level programming language. It is compact, highly
structured and contains a comprehensive range of constructs for assignments,
function/function block calls, expressions, conditional statements, iterations and more.
The code is simple to write and easy to read, because of its logical and structured
layout. The compactness of the language gives an excellent overview of the code and
less scrolling in the editor.

10.2.1 Advantages of Using Structured Text


1. Free layout of code and comments
2. When in online mode the layout can be changed to Function Block or Ladder for
viewing by different personnel.
3. Text may be generated in any external text editor and pasted into the ST editor.
For example you might use macros in MS Word to generate code.
4. Structured text reads like English and is the most efficient way of writing code.
5. You will have to learn Structured Text in any case because it is the only choice in
the SFC editor!

A small example of code written in Structured Text is shown below:

Chapter 10 - 3
T530-10 Structured Text - RevG

10.2.2 Structured Text Editor


The appearance of the structured text editor for a program is shown below:

Declarations pane

Code pane

Messages pane

The code pane is used for writing code in Structured Text. It is a simple text editor.
Tabs and spaces are used to structure the code for easy reading.
The code pane may be divided into several ‘tabs’. Each tab is also referred to as Code
Blocks. When the code is compiled the execution order of the code is firstly in tab
order (left to right) and then from top to bottom inside the tabs.
Instances of variables and function blocks are declared in the declaration pane.

Chapter 10 - 4
Compact Control Builder Training

10.3 Basic Language Elements


This section gives a very brief review of the structured text language.

10.3.1 Assignment Statements


An assignment statement assigns a value to a variable.
The statement has two parts:
Result := In1 AND In2 OR In3;
The left hand side, before the assignment operator (:=) is called the assigned variable.
The right hand side is an expression which is evaluated to give a value to the assigned
variable.
In the above example the expression results in a Boolean – true/false value. (It is a
Boolean expression). The AND and the OR are referred to as operators (In this case
Boolean operators).
NOTE! The := symbol is used for the assignment of operators
and a statement must be ended with a semi-colon.

Another example of an assignment statement:


AverageFlow := (Flow1 + Flow2)/2;
The variable AverageFlow is assigned the value given by the result of the calculation
on the right. Flow1 is firstly added to Flow2 and then the total is divided by 2.
The expression on the right is a Real expression because it results in a Real value
(floating point value). The symbols + and / are called arithmetic operators because
they perform arithmetic operations on the variable values which follow them.

10.3.2 Comment Statements


Operator Description
(*…*) Comment according to IEC 1131-3.
(#…#) Comment that can be nested (ABB extension).

It is normally not possible to have comments within comments (nested comments):


(* This is not (* Inner Comment *) allowed *)
However there is an alternative comment symbol that allows this:
(# This is (* Inner Comment *) allowed #)
This is useful for commenting out large blocks of code containing comments.

Chapter 10 - 5
T530-10 Structured Text - RevG

10.3.3 Operators
Below is a list of the most commonly used operators:
Boolean Operators
Operator Description
NOT Negates the Boolean value (1/0, on/off or True/False).
AND Boolean AND.
& Boolean AND. See AND.
XOR Boolean XOR.
OR Boolean OR.

Arithmetic Operators
Operator Description
** Exponential, i.e. raising to the power.
* Multiplication.
/ Division.
+ Addition.
- Subtraction.
MOD Modulus.

Relational Operators
Operator Description
< Less than.
> Greater than.
<= Less than or equal to.
>= Greater than or equal to.
= Equal to.
<> Not equal to.

Chapter 10 - 6
Compact Control Builder Training

10.3.4 Precedence
The priority of operators decides the order of evaluation of an expression. Below is a
summary of available operators, in descending priority:

Operator Description Priority


(…) Parenthesized expression. Highest
Function (…) Parameter list of a function, function evaluation.
Not, - Negation, Boolean complement, i.e. value with "opposite"
value (0 becomes 1, 1 becomes 0) and arithmetical
negation (-).
** Exponentiation, i.e. raising to a power.
*, / ,mod Multiplication, division and modulus.
+, - Addition and subtraction.
<, >, <=, >= Comparison operators
=, <> Equality and inequality.
and, & Boolean AND.
xor Boolean exclusive OR
or Boolean OR Lowest

If you are unsure of the evaluation order then use parenthesis to force evaluation of
sub-expressions.

Chapter 10 - 7
T530-10 Structured Text - RevG

10.3.5 Conditional Structures


There are tow main groups of conditional structures:
IF…Then
Operator Description
IF Boolean Expression THEN If (and only If) the Boolean Expression
Statement(s); evaluates to True, then the Statement(s)
between the IF and END_IF is/are executed.
END_IF;
IF Boolean Expression THEN If the Boolean Expression evaluates to True,
Statement(s); then the Statement(s) before the ELSE is/are
executed. Else the statements after the ELSE
ELSE and before the END_IF are executed.
Statement(s);
END_IF;
IF Boolean Expression 1 THEN If the Boolean Expression 1 evaluates to True,
Statement(s); then the Statement(s) before the first ELSIF
is/are executed. If this condition is false then
ELSIF Boolean Expression 2 THEN the subsequent Boolean Condition is tested
Statement(s); and so on for each ELSIF. If no expression is
true then the ELSE statement(s) execute.
ELSIF Boolean Expression n THEN
The ELSE clause is optional. You may have
Statement(s);
as many ELSIF clauses as you wish.
ELSE
Statement(s);
END_IF;

NOTE! A conditional statement is always concluded with


END_IF;

Chapter 10 - 8
Compact Control Builder Training

IFs may be nested to many levels. A better structure to be used instead of nesting is
the CASE structure. This is very useful when many conditions need evaluation; there
are several forms:
CASE…OF
Operator Description
CASE Integer Expression OF A statement is executed depending on the
Integer Literal1 : Statement(s); value of an integer variable or an integer
expression.
END_CASE;
The <integer literal> is one or several integer
values or one or several ranges of values.
CASE Integer Expression OF In this example, three values are tested and
Integer Literal1 : Statement(s); the appropriate statements) executed. One
variation is to permit a range of values to be
Integer Literal2 : Statement(s); tested rather than an exact single value.
Integer Literal3 : Statement(s); If none of the test literals match the result of
ELSE the expression then the statement(s) in the
ELSE clause will be executed. If no ELSE
Statement(s);
exists, none of the statements will be
END_CASE; executed.

10.3.6 Iteration Structures


Several iteration constructs exist: They should be used with extreme caution. During
the iteration of the loop, the CPU remains in the loop. If a loop has a large number of
iterations then the normal scan time may be easily exceeded.
NOTE! Only use these constructs when you know exactly how
many iterations are going to be done.

Operator Description
FOR i := 0 to 15 DO The FOR statement is used to allow a statement (or
Statement(s); statements) to be executed repeatedly for a given
number of times. The counter used in the repetition
END_FOR; process can be used in the statements.
In the example, the statements between the FOR
and END_FOR will be executed 16 times.
WHILE Level > 80.0 DO The WHILE statement is used in order to allow a
Statement(s); statement (or statements) to be executed repeatedly
while a certain condition is True.
END_WHILE;
This separates it from the FOR statement. It has
some similarities with the REPEAT statement.
REPEAT The REPEAT statement is used in order to allow a
Statement(s); statement (or statements) to be executed repeatedly
until a certain condition is True.
UNTIL Boolean Expression
Note that the test to exit the loop is placed at the end,
END_REPEAT; so a minimum of one execution of the statement(s)
will occur even if the expression is true at the time
the loop is entered.
EXIT Use the EXIT statement whenever you want to
terminate a loop immediately and continue execution
from the first line after the iteration statement.

Chapter 10 - 9
T530-10 Structured Text - RevG

10.3.7 RETURN Statement


The RETURN statement causes immediate exit from the current code block (A tab in
a program or control module or function block). No further code in that block is
executed.

10.4 Functions and Function Blocks

10.4.1 Functions
Functions are called inside expressions with the following syntax:
Var := FunctionName(Parameter(s))
In the example below the square root of a flow signal is calculated by using the Sqrt()
function.

10.4.2 Function Blocks


Function block calls do not appear in assignment statements. The call is itself a valid
statement. Note that in ST, function block input parameters are listed with the :=
symbol and output parameters are listed with the => symbol.
The example below shows the code for calling a delay off timer:

The above timer function block is the same as the following in FBD form:

Function blocks are declared in a similar way to variables, by giving them a name (an
instance name). This name is then used to call them in the code. In the ST editor you
must declare function blocks explicitly in the “Function Block” declaration tab in the
editor by giving a name and a type:

Chapter 10 - 10
Compact Control Builder Training

10.4.3 How to Declare Function Block Instances


As an absolute minimum a function block instance must be given a name and a
function block type:

1. Mark the “Function Blocks” tab in the declarations pane of the POU.
2. Type in an instance name for the function block in the “Name” column.
3. Type in the required function block type in the “Function Block Type” column.
Place the cursor in the field and press ‘Ctrl + J’ to see a list of all available
function block types.

NOTE! Function Block Types are defined in the libraries.


If the library that contains the function block type that you want has not been
connected to the application then it will not appear in the list.

10.4.4 How to Call a Function Block Instance


In the example below a delay off timer has been declared in the “Function Block”
declaration tab, called MixTimer of type TOf:

Chapter 10 - 11
T530-10 Structured Text - RevG

Four variables which will be used to connect to the function block have also been
declared in the “Variables” declaration tab:

1. Call the function block instance by typing its instance name in the code pane
followed by an opening parenthesis ‘(‘

The system will then offer a dialogue for you to make connections.

2. Fill in the parameters that are to be connected to the function block instance in the
parameter column by any of the following methods:

Type the name of the variable to be connected directly into the “Parameter” field.
(After a few characters the system will try to help you finish by supplying first
matching variable name).

Chapter 10 - 12
Compact Control Builder Training

3. Use the “Insert from List” method by clicking on the Insert Variable … icon in the
menu bar or use the “Insert Path from Tree” Icon to browse the application for the
variable:

4. Click on the “Exit and Close” icon in the dialogue.

5. The result (for this example) looks like:

Chapter 10 - 13
T530-10 Structured Text - RevG

10.5 Common Mistakes and their Error Messages


Identifier, constant or opening parenthesis expected

Double clicking on the error message line places the cursor at the end of the statement
with the problem: Usually a missing semi-colon (;)at the end of a statement.

Variable name is not unique


Two variables have been declared with the same name. (Note that this results in two
error one for each non-unique name).

Note also that some other items are classed as ‘variables’ by the system:
- Instance names for function blocks
- Instance names for control modules
- Sequence Step names
- Code Block names
- Sequence Transition names
- Parameters (in function block types and control module types)
This means that within any POU all of the above must have unique names.

Chapter 10 - 14
Compact Control Builder Training

Identifier too long or invalid


This error message is given under two circumstances:
1. Variable naming rules have been disobeyed - the name begins with a number.

2. A key word has been used - both words “On” and “Off” are reserved.

Undefined function block


Usually caused by a typing error in the name of the function block instance:

The programmer has declared the function block with the name MixTimer but has
referenced MuxTimer in the code.

Chapter 10 - 15
T530-10 Structured Text - RevG

Type mismatch in assignment


This occurs when the programmer has mixed data types in an assignment statement

In this case the programmer has attempted to add a “real” and a “dint” to get a “dint”
result. (You can’t multiply apples with pears!)

Incompatible types in expression


This occurs when an operation has been attempted on different types that are not
compatible for that operation:

In the above a real has been added to a bool.

Chapter 10 - 16
Compact Control Builder Training

10.6 How to Declare Variables from Error Messages


There is a quick shortcut that can save a lot of time when programming. That is to let
the error checker do the work of declaring variables. This method is not for the purist!
1. Program as normal but without declaring the variables and then do a check on the
code. You will get “Variable not declared” errors:

2. Now do a check and you will get the following errors:

3. To get automatic declaration, mark the first error, click right and select “Declare
Variable”:

The system will copy the name into the declaration pane and also as an added
bonus will fill in the type if it can deduce it from the sense of the statement.

Chapter 10 - 17
T530-10 Structured Text - RevG

10.7 How to Change from ST to Function Block in Online mode


When in online mode the layout can be changed to Function Block or Ladder for
viewing by different personnel.
1. Start by online mode

2. Select “Tools > Setup”

3. Select “Structured Text” tab

Chapter 10 - 18
Compact Control Builder Training

4. Select the “Function Diagram” in “Structured Text” tab and press then “OK”.

5. To get the Structured Text code as Function Block Diagram

Chapter 10 - 19
T530-10 Structured Text - RevG

Chapter 10 - 20
Compact Control Builder Training

Exercise 10.1 Programming the Outlet Valves

10.1.1 Description
Program the outflow valves in the Structured Text language. Instantiate and use
function blocks in the ST editor.
We will be using the same ValveUni function block as we did for the tank inlet valves.
Declare global and local variables similar to the ones for the inlet valves.

10.1.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Exercise 10.1 - 1
J410-10 Exercise 10.1 - RevA

10.1.3 Exercise Steps

10.1.3.1 Create a New Code Block

F Open the program Tank in application Sxx_ReactorApp.

F Create a new code block “Outlet_Valves” and set the language to Structured Text.

10.1.3.2 Declare and Connect Global Variables

F Declare global variables for the Order value and the valve Open and Closed feedback
switches as was done for the inlet valves. Check, Save, and Close the Sxx_ReactorApp
editor.

Exercise 10.1 - 2
Compact Control Builder Training

F Connect the variables to the Oslo Simulation.


If you have a real Hardware Oslo Model skip this:

F If you use the Oslo_Sim skip this part. Connect the variables to the corresponding
channel on the I/O modules.
• The variables gV2_Ord and gV6_Ord are connected to the first DO801 module on
the PROFIBUS. The command to open V2 is wired to channel 4 and the V6 open
command is wired to channel 2.

• The valve position feedback signals are all connected to the DI801 module located
on the PROFIBUS as follows:

Exercise 10.1 - 3
J410-10 Exercise 10.1 - RevA

10.1.3.3 Create Outlet Valve V2

F Instantiate a ValveUni function block in the “Outlet_Valves” code block of program


Tank and name it Sxx_V2.

F Declare the following local variables in Tank.

F Connect the local and global variables for V2 to the Sxx_V2 function block.

Exercise 10.1 - 4
Compact Control Builder Training

10.1.3.4 Create Outlet Valve V6

F Copy Sxx_V2, paste it into the code block. Rename it to Sxx_V6 and replace the
variables for V6. Declare the new associated local variables for Sxx_V6

10.1.3.5 Download and Function Check

F Download the application to your controller and take Control Builder to the on-line
mode.

F Operate the outlet valves, V2 and V6 using Control Builder interaction windows.
Observe the reactor tank level.

Exercise 10.1 - 5
J410-10 Exercise 10.1 - RevA

Exercise 10.1 - 6
Compact Control Builder Training

Solution 10.1 Programming the Outlet Valves

10.1.1 Description
Program the outflow valves in the Structured Text language. Instantiate and use
function blocks in the ST editor.
We will be using the same ValveUni function block as we did for the tank inlet valves.
Declare global and local variables similar to the ones for the inlet valves.

10.1.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Solution 10.1 - 1
T530-10 Solution 10.1 - RevG

10.1.3 Solution Steps

10.1.3.1 Create a New Code Block

F Open the program Tank in application Sxx_ReactorApp.

F Create a new code block “Outlet_Valves” and set the language to Structured Text
1. Right-click the code block tabs at the bottom of the window and select “Insert…”
Name the new code block “Outlet_Valves” and select the “Structured Text (ST)”
radio button..

2. Result

Solution 10.1 - 2
Compact Control Builder Training

10.1.3.2 Declare and Connect Global Variables

F Declare global variables for the Order value and the valve Open and Closed feedback
switches as was done for the inlet valves. Check, Save, and Close the Sxx_ReactorApp
editor.
1. You can, of course, manually type the information for global variables. We will
use the Find & Replace functionality. Cell, row, and column selection in the
declaration pane of POU editors is similar to Microsoft Excel. Select the six rows
in the Sxx_ReactorApp editor that hold the V1 and V5 variables and copy them

2. Select the first empty cell and perform a paste operation.

Solution 10.1 - 3
T530-10 Solution 10.1 - RevG

3. With the newly pasted cells still highlighted, select “Edit” -> “Replace…” from
the editor’s menu bar

4. In the “Replace” dialog, replace all occurrences of “V1” with “V2”. Click
“Replace All”.

5. Click “OK”

6. Perform the same procedure to replace “V5” with “V6”. Close the “Replace”
dialog window.

Solution 10.1 - 4
Compact Control Builder Training

7. Check the Global Variable list

F Connect the variables to the corresponding channel on the I/O modules.


1. The variables gV2_Ord and gV6_Ord are connected to the first DO801 module on
the PROFIBUS. The command to open V2 is wired to channel 4 and the V6 open
command is wired to channel 2.

Solution 10.1 - 5
T530-10 Solution 10.1 - RevG

2. Copy , Paste and correct Description. Or write the description directly

3. Check Global variables are like this

4. The valve position feedback signals are all connected to the DI801 module located
on the PROFIBUS as follows:

Solution 10.1 - 6
Compact Control Builder Training

10.1.3.3 Create Outlet Valve V2

F Instantiate a ValveUni function block in the “Outlet_Valves” code block of program


Tank and name it Sxx_V2.
1. Instantiating a Function Block in ST is simply a matter of “declaring” it in the
declaration pane of the editor. Open the Tank program and select the “Function
Blocks” tab in the declaration pane. Enter the name as “Sxx_V2” and the Function
Block type as “ValveUni”. Save the Program (but do not close the editor).

2. You will notice that the instance “Sxx_V2” has been added in Control Builder M
under the Tank program

Solution 10.1 - 7
T530-10 Solution 10.1 - RevG

F Declare the following local variables in Tank.


1. Use Replace

The local variables until now

Solution 10.1 - 8
Compact Control Builder Training

F Connect the local and global variables for V2 to the Sxx_V2 function block.
1. Left click in the white Code pane select keyboard Ctrl J. Select Sxx_V2 with enter,
or write Sxx_V2 as a text.Type in the (

2. The parameter list for the Valve will open

Solution 10.1 - 9
T530-10 Solution 10.1 - RevG

3. Connect the Parameter to the variables. Type Ctrl j and type V2 in the box. Or use
arrow down

4. Six parameters has to be connected to six variables

Solution 10.1 - 10
Compact Control Builder Training

5. After save and close the instance will be like this

10.1.3.4 Create Outlet Valve V6

F Copy Sxx_V2, paste it into the code block and rename it to Sxx_V6 and replace the
variables for V6. Declare the new associated local variables for Sxx_V6
1. Use Replace

Solution 10.1 - 11
T530-10 Solution 10.1 - RevG

The local Variables until now

2. Declare a new Sxx_V6 Function Block the same way as you did for Sxx_V2.

3. Save the program (do not close the editor).

Solution 10.1 - 12
Compact Control Builder Training

4. Select and highlight the Sxx_V2 Function Block call in the code pane, right-click,
and select “Copy”.

5. Place cursor at the end of the existing code in the code pane, Keyboard Shift Enter
to insert two soft carriage return right-click and select “Paste”.

6. Change the pasted text to call the Sxx_V6 function block and change the variable
names for all V6 variables. Use Highlight “Edit” and select replace.

NOTE! Only replace one at a time an follow how far the tool
make changes. Replace all will replace outside the
highlighted zone
7. The text replaced to

Solution 10.1 - 13
T530-10 Solution 10.1 - RevG

8. Result for V2 and V6

Solution 10.1 - 14
Compact Control Builder Training

10.1.3.5 Download and Function Check

F Download the application to your controller and take Control Builder to the on-line
mode.

F Operate the outlet valves, V2 and V6 using Control Builder interaction windows.
Observe the reactor tank level.

Solution 10.1 - 15
Compact Control Builder Training

Exercise 10.2 Interlocking Inlet and Outlet Valves

10.2.1 Description
Connect additional parameters to already existing function blocks. These connections
will prevent the Tank Inlet valve V1 and Tank Outlet valve V2 from being open
simultaneously.

10.2.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Exercise 10.2 - 1
T530-10 Exercise 10.2 - RevG

10.2.3 Exercise Steps


The ValveUni Function Block has an interlock feature. When the “Ilock1” parameter
is true and the valve is closed, it will be prevented from opening. When the “Ilock0”
parameter is true and the valve is open, it will be prevented from closing.

10.2.4 Configure the Interlock

F Modify the code in your Tank program to prevent tank inlet valve V1 from being
opened if the tank outlet valve V2 is open.

F Place a comment on the Sxx_V1 function block to indicate that it is interlocked with
V2. Also place a page comment.

Exercise 10.2 - 2
Compact Control Builder Training

F Modify the code in your Tank program to prevent tank inlet valve V2 from being
opened if the tank outlet valve V1 is open, and place a comment in the code indicating
the interlock.

Exercise 10.2 - 3
T530-10 Exercise 10.2 - RevG

10.2.4.1 Download and Test the Program

F Download the application to the controller and place Control Builder in on-line mode.

F Open the interaction windows for V1 and V2. Attempt to open both valves. Observe
the Interlock indication in the windows.

F When finished testing, close the interaction windows and take Control Builder to the
off-line mode.

Exercise 10.2 - 4
Compact Control Builder Training

Solution 10.2 Interlocking Inlet and Outlet Valves

10.2.1 Description
Connect additional parameters to already existing function blocks. These connections
will prevent the Tank Inlet valve V1 and Tank Outlet valve V2 from being open
simultaneously.

10.2.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Solution 10.2 - 1
T530-10 Solution 10.2 - RevG

10.2.3 Solution Steps


The ValveUni Function Block has an interlock feature.
1. Select Help to get information

2. When the “Ilock1” parameter is true and the valve is closed, it will be prevented
from opening. When the “Ilock0” parameter is true and the valve is open, it will
be prevented from closing

10.2.4 Configure the Interlock

F Modify the code in your Tank program to prevent tank inlet valve V1 from being
opened if the tank outlet valve V2 is open.

Solution 10.2 - 2
Compact Control Builder Training

F Place a comment on the Sxx_V1 function block to indicate that it is interlocked with
V2.
1. Right-click the Sxx_V1 Function Block on the “Inlet_Valves” code block and
select “Edit Comment”.

2. Type in the text for the comment and select “OK”

3. The comment is placed above the Function Block with green text

Solution 10.2 - 3
T530-10 Solution 10.2 - RevG

4. Select the left Code pane and select “Edit Page Comment”

5. Type in the Page Comment

Solution 10.2 - 4
Compact Control Builder Training

6. The Page Comment appears above the Pin up marker

F Modify the code in your Tank program to prevent tank inlet valve V2 from being
opened if the tank outlet valve V1 is open, and place a comment in the code indicating
the interlock.
1. In the code block for the “Outlet_Valves” connect the Ilock1 parameter to the
gV1_Open.Value variable. You may type this in manually or right-click in the
Sxx_V2 Function Block and select “Edit Parameters”.

2. Select the gV1_Open variable select with a “.” (dot) the component Value,
gV1_Open.Value

Solution 10.2 - 5
T530-10 Solution 10.2 - RevG

3. Result

4. Place a comment in the code indicating the interlock.


You can insert comments in the code by enclosing them in the characters (* and *)
according to IEC 61131-3. You can also enclose the comments in the characters (#
and #). You can nest comments inside (#...#) comments. Enter your comments
using either method.

Solution 10.2 - 6
Compact Control Builder Training

10.2.4.1 Download and Test the Program

F Download the application to the controller and place Control Builder in on-line mode.
1. Open the interaction windows for V1 and V2.

2. Attempt to open both valves. Observe the Interlock indication in the windows.

F When finished testing, close the interaction windows and take Control Builder to the
off-line mode.

Solution 10.2 - 7
Compact Control Builder Training

Exercise 10.3 Programming the Temperature Control

10.3.1 Description
Write some very basic and simple logic in Structured Text programming the
functionality for tank temperature control.
Tank temperature is to be maintained at a certain temperature set point and control
band (called “hysteresis”) to prevent constant cycling of the heater and cooler.

10.3.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Exercise 10.3 - 1
T530-10 Exercise 10.3 - RevG

10.3.3 Exercise Steps

10.3.3.1 Declare Global Variables and Connect I/O Channels

F Declare global variables as shown below.

F Connect gTemp to the AI810 module on the PROFIBUS. Set the input range to 0..10V
and the scaling to 0-180DegC.

F Connect gHeater_Ord and gCooler_Ord to the first DO801 on the PROFIBUS.

Exercise 10.3 - 2
Compact Control Builder Training

F Connect gHeater_On and gCooler_On to the DI801 module on the PROFIBUS.

10.3.3.2 Write the Logic

F Declare local variables to hold some values in our program.


1. Real variable SP_Temp will hold the tank temperature setpoint which defaults to
100 Degrees C.
2. Real variable Temp_Hysteresis will hold the control band for temperature. Its
default value will be 5 Degrees C.
3. Bool variable Start_TempControl will enables automatic control of temperature by
the heater and cooler.

F Insert a new Structured Text code block name “Temp_Control” in program Tank and
write the necessary logic to control the heater and the cooler. The requirements that
the logic must meet are:
1. If the Start_TempControl variable is not true, automatic control of the Heater and
the Cooler is disabled.
2. Heating or Cooling will occur automatically if the measured tank temperature is
outside of the control range. The control range is determined by a user-changeable
setpoint and control band.

Exercise 10.3 - 3
T530-10 Exercise 10.3 - RevG

10.3.3.3 Download and Test the Program

F Download to the controller. Open the Sxx_ReactorApp on-line editor and the Tank
program editor. Manipulate the variables SP_Temp, Temp_Hysteresis, and
Start_TempControl to test your logic.

F Check and make sure the heater and cooler turn both ON and OFF.

Exercise 10.3 - 4
Compact Control Builder Training

Solution 10.3 Programming the Temperature Control

10.3.1 Description
Write some very basic and simple logic in Structured Text programming the
functionality for tank temperature control.
Tank temperature is to be maintained at a certain temperature set point and control
band (called “hysteresis”) to prevent constant cycling of the heater and cooler.

10.3.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Solution 10.3 - 1
T530-10 Solution 10.3 - RevG

10.3.3 Solution Steps

10.3.3.1 Declare Global Variables and Connect I/O Channels

F Declare global variables as shown below.

F Connect gTemp to the AI810 module on the PROFIBUS.

1. Set the input range to 0..10V

Solution 10.3 - 2
Compact Control Builder Training

2. Set the scaling to 0-180DegC

F Connect gHeater_Ord and gCooler_Ord to the first DO801 on the PROFIBUS.

F Connect gHeater_On and gCooler_On to the DI801 module on the PROFIBUS.

Solution 10.3 - 3
T530-10 Solution 10.3 - RevG

10.3.3.2 Write the Logic

F Declare local variables to hold some values in our program.


1. Real variable SP_Temp will hold the tank temperature setpoint which defaults to
100 Degrees C.
2. Real variable Temp_Hysteresis will hold the control band for temperature. Its
default value will be 5 Degrees C.
1. Bool variable Start_TempControl will enables automatic control of temperature by
the heater and cooler.

F Insert a new Structured Text code block name “Temp_Control” in program Tank and
write the necessary logic to control the heater and the cooler. The requirements that
the logic must meet are:

Solution 10.3 - 4
Compact Control Builder Training

1. If the Start_TempControl variable is not true, automatic control of the Heater and
the Cooler is disabled.

Select “If…then” icon

Solution 10.3 - 5
T530-10 Solution 10.3 - RevG

2. Heating or Cooling will occur automatically if the measured tank temperature is


outside of the control range. The control range is determined by a user-changeable
setpoint and control band.

10.3.3.3 Download and Test the Program

F Download to the controller. Open the Sxx_ReactorApp on-line editor and the Tank
program editor. Manipulate the variables SP_Temp, Temp_Hysteresis, and
Start_TempControl to test your logic.

Solution 10.3 - 6
Compact Control Builder Training

F Check and make sure the heater and cooler turn both ON and OFF.
1. In Online mode or Test mode set up the value True for variable
Start_TempControl

2. Set up the force and enter for example 98 DegC and check the
If then else statement

Solution 10.3 - 7
T530-10 Solution 10.3 - RevG

3. Set up the force and enter for example 118 DegC and check the
If then else statement

Solution 10.3 - 8
Compact Control Builder Training

Exercise 10.4 Limiting the Temperature

10.4.1 Description
Add new logic to existing “Temp_Control” code block to ensure the heater shuts off
anytime the temperate is above 130 Degrees C.

10.4.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Exercise 10.4 - 1
T530-10 Exercise 10.4 - RevG

10.4.3 Exercise Steps

F Write additional logic to stop the heater if the actual temp is > 130°C. Create a local
variable called Temp_High to indicate when tank temperature is high.

NOTE! The example is one of many ways the logic could be


configured.

F Download to the controller.

F Turn automatic temperature control on (set Start_TempControl to True) and set the
tank temperature control setpoint SP_Temp to 140 degrees. Observe the heater
energize and the tank temperature rise. The heater should stop when the tank
temperature reaches 130 degrees.

Exercise 10.4 - 2
Compact Control Builder Training

Solution 10.4 Limiting the Temperature

10.4.1 Description
Add new logic to existing “Temp_Control” code block to ensure the heater shuts off
anytime the temperate is above 130 Degrees C.

10.4.2 Legend
> Indicates when you go from one menu to a sub-menu
Italic Indicates object and file names
“ “ Indicates dialog box buttons, tabs, menus etc.
Bold Indicates important topics
Indicates start/explanation of student activity

Solution 10.4 - 1
T530-10 Solution 10.4 - RevG

10.4.3 Solution Steps

F Write additional logic to stop the heater if the actual temp is > 130°C.
1. Create a local variable called Temp_High to indicate when tank temperature is
high.

2. Write the logic

F Download to the controller.

Solution 10.4 - 2
Compact Control Builder Training

F Turn automatic temperature control on (set Start_TempControl to True) and set the
tank temperature control setpoint SP_Temp to 140 degrees. Observe the heater
energize and the tank temperature rise. The heater should stop when the tank
temperature reaches 130 degrees.

Solution 10.4 - 3

You might also like