T314-09 Variables and Data Types - RevC
T314-09 Variables and Data Types - RevC
TABLE OF CONTENTS
Chapter 9 - 1
T314-09 Variables and Data Types - RevC
9.1.1 Objectives
On completion of this chapter you will be able to:
• Describe the scope of variables
• Declare variables
• Declare and use structured data types
• Explain the use of project constants
9.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
Chapter 9 - 2
System 800xA Training
9.2 Variables
Variables are used to store data inside the controller memory. During execution of the
control code the data may change following changes in the process states or else due
to calculations made.
When the application code is written, the programmer must create variables to store
the data which is manipulated by the application code. Variables are the containers
for values within the application, its programs, its function blocks and its control
modules.
Modern controllers are capable of handling many different sorts of data. The simplest
type is boolean, but other types are possible such as integer (whole numbers), real
(floating point numbers) and string (character strings such as text messages).
Additionally, in System 800xA, many other more complex data types are possible.
Two sorts of variable may be declared within an application (by selecting the
appropriate tab at the bottom of the editor).
Chapter 9 - 3
T314-09 Variables and Data Types - RevC
Global Variables
These variables are known within the application and also within any program
contained within the application. Global variables are declared whenever data needs to
be exchanged between programs.
It is also usual (but not essential) to declare any variables connected to I/O channels as
global variables.
Variables
These variables are known only within the application and they are not visible to
programs inside the application. They are used to exchange data between control
modules in an application. These variables are local to the application.
Variables declared inside a program are known only within that program. They are
local to the program itself.
Chapter 9 - 4
System 800xA Training
When a function block is instantiated, the variables declared in the type are created in
each instance.
When a control module is instantiated, the variables declared in the type are created in
each instance.
Chapter 9 - 5
T314-09 Variables and Data Types - RevC
External variables are not a new type of variable but a reference from inside a type to
a global variable in the application.
If global variables are to be used inside function block types or control modules, they
must be declared as external variables in the function block type editor or control
module editor.
NOTE! External variables should be used only to supply values
that are application wide.
Chapter 9 - 6
System 800xA Training
Conventions
It is usual to give variables meaningful names rather than abbreviated mnemonics,
such as: FillValve_FB_Open
• The underscore character is commonly used when a space is required and to
increase readability.
• Upper and lower case characters are used.
• Capitals are used to emphases key words in the name and again to make it more
readable.
Chapter 9 - 7
T314-09 Variables and Data Types - RevC
Chapter 9 - 8
System 800xA Training
Name Description
The value of the variable is not maintained after a restart. Instead it is set
to the initial value of the variable. 4101085346kqfv223
no attribute
If the variable has no initial value assigned to it, it will get the default value
of the data type.
The value of the variable is maintained after a warm restart.
retain The system sets retain on all variables by default. To override this default
the attribute column is cleared and left empty (no attribute).
The value of the variable is maintained after a warm or cold restart.
coldretain
This attribute overrides the retain attributes in a structured data type.
You cannot change the value of the variable once given (after compilation
and download).
constant
This attribute overrides the coldretain and retain attributes in a structured
data type.
The variable will not be visible to the OPC server, and therefore not
available in the 800xA system.
hidden In general all variables not needed by the HSI should be given the hidden
attribute as this will considerably reduce network traffic. All variables not
T having the Hidden attribute will be exported to the OPC server.
Variables declared in a control module can also have the additional attributes state and
nosort. These attributes will be described later (they are only available for control
modules).
The diagram below shows the syntax used:
Chapter 9 - 9
T314-09 Variables and Data Types - RevC
The attributes no attribute, retain and coldretain affect how the value of the variable is
maintained following a restart of the controller or following a download of the
application.
The controller may be restarted in two ways:
At a Cold Restart, variables without the attribute coldretain lose their values. Instead,
they are given their initial value (or if no initial value is stated then the default initial
value for the type). Variables specified using the attribute ColdRetain keep their
values.
At Warm Restart, variables with the attribute Retain or ColdRetain are stored before
restart. Variables without these attributes are given their initial value (or if no initial
value is stated then the default initial value for the type).
Chapter 9 - 10
System 800xA Training
Chapter 9 - 11
T314-09 Variables and Data Types - RevC
Chapter 9 - 12
System 800xA Training
Chapter 9 - 13
T314-09 Variables and Data Types - RevC
9.5.1 Overview
Structured data types have two or more components. The components may be simple
or themselves structured. They can also be seen as wires in a multicore cable.
For example, suppose you have a vessel which has the following data associated with
it:
• Tank is Full
• The volume of fluid (measured in cubic meters).
• The temperature of the fluid (measured in Kelvin).
• The minimum permitted temperature of the fluid.
• The maximum permitted temperature of the fluid (both measured in Kelvin).
This data could be packed into a data type called say, TankType.
Once the “TankType” data type has been defined, variables of that type may be
declared in any application. Suppose a variable is now declared called Tank. The
individual componets of this variable may be accessed using “dot notation”:
• Tank.Full
• Tank.Volume
• Tank.Temperature
• Tank.MinTemp
• Tank.MaxTemp
Chapter 9 - 14
System 800xA Training
Data types defined in libraries become available to all applications (and libraries) that
have that library connected to them.
4. Select “Editor”.
Chapter 9 - 15
T314-09 Variables and Data Types - RevC
5. Define the components of the data type. For each component type in at least a
name and a data type:
If you want to set the Full component of the Tank variable to 1 (i.e. "True"), write:
Tank1_Data.Full := true ;
Chapter 9 - 16
System 800xA Training
9.6.1.1 BoolIO
Use a BoolIO type when you connect to either a digital input or digital output channel.
The datatype is defined by the system and has the following components:
9.6.1.2 RealIO
Use a RealIO type when you connect to an analog input or analog output channel.
The Value, IOValue, Forced and Status components are given by the system to the
application. The Inverted, Max, Min, Unit and Fraction components are given by the
user of the application to the system in the “Scaling” tab.
The data type has the following components.
Chapter 9 - 17
T314-09 Variables and Data Types - RevC
Note that the last component ‘Parameters’ is itself a structured variable of type
SignalPar. The data type SignalPar has the following components:
It is possible to connect variables to I/O from the POU editor, but is recommended to
do it from the I/O unit, because you cannot browse to the correct I/O address from the
I/O address column in the POU editor.
Chapter 9 - 18
System 800xA Training
Once a value has been defined as a project constant, it may be referenced directly in
the code in a program, control module type or function block type.
Alternatively the constant may be used as an initial value for a variable.
Example
To be able to change the severity for all “High level alarms” in the entire project, set
up a project constant that defines the severity and use the project constant in all alarm
blocks in all applications. To change the severity, just change the value of the project
constant.
When a constant is defined in a library, that constant is also added to the list for the
constants in the project as a whole.
You can insert, edit and group project constants in the Project Constant editor. Select
“Tools > Project Constants” from the menu in the Project Explorer or right click on
the library / application and select “Project Constants”.
Chapter 9 - 19
T314-09 Variables and Data Types - RevC
Select either “Insert in Sublevel” or “Insert After” to define the constant. Define the
value and data type.
Any project constant declared in a library will be a part of that library. They will
however also be incorporated in the main list of project
NOTE! To use project constants, just use the constant names
directly in the code, as an initial value or as a connections
to a control module / function block instance.
Chapter 9 - 20