T315C-08 Variables and Data Types - RevE
T315C-08 Variables and Data Types - RevE
TABLE OF CONTENTS
Chapter 8 - 1
776516416.doc
8.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
8.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 8 - 2
System 800xA Training
8.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 8 - 3
776516416.doc
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
Variables declared inside a program are known only within that program. They are
local to the program itself.
Commmunication Variables
Variables declared as commmunication variables will be used for inter application
data exchange, and will be covered later in the chapter “Communication”.
Chapter 8 - 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 8 - 5
776516416.doc
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 8 - 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 emphasis key words in the name and again to make it more
readable.
Chapter 8 - 7
776516416.doc
When the configuration is applied the filtering tool hides the rows that don’t match the
filtering criteria and the filter icon will show up in the filtered column.
Chapter 8 - 8
System 800xA Training
TypeName will have the default length of 40 characters, while Name has a capacity for
30 characters.
Chapter 8 - 9
776516416.doc
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
having the Hidden attribute will be exported to the OPC server.
Chapter 8 - 10
System 800xA Training
T
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 8 - 11
776516416.doc
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.
Chapter 8 - 12
System 800xA Training
Chapter 8 - 13
776516416.doc
Chapter 8 - 14
System 800xA Training
Chapter 8 - 15
776516416.doc
8.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, the agitator that is used in the exercises has the following data associated
with it:
Mixer’s motor current
Mixer’s motor RUN feedback
Mixer’s motor OUTPUT
Mixer’s motor reference speed
Mixer’s motor ON command
This data could be packed into a data type called say, “Agitator_Signals”.
Once the “Agitator_Signals” data type has been defined, variables of that type may be
declared in any application. Suppose a variable is now declared called
“gMixerSignals”. The individual componets of this variable may be accessed using
“dot notation”:
gMixerSignals.Mixer_Current
gMixerSignals.Mixer_On
gMixerSignals.Mixer_Pulse
gMixerSignals.Mixer_Ref
gMixerSignals.Mixer_Ord
Chapter 8 - 16
System 800xA Training
Data types defined in libraries become available to all applications (and libraries) that
have that library connected to them.
Chapter 8 - 17
776516416.doc
3. Select “Editor”.
4. Define the components of the data type. For each component type in at least a
name and a data type:
Chapter 8 - 18
System 800xA Training
If you want to set the Full component of the Tank variable to 1 (i.e. "True"), write:
Tank1_Data.Full := true ;
Chapter 8 - 19
776516416.doc
8.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:
8.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 8 - 20
System 800xA Training
Note that the last component ‘Parameters’ is itself a structured variable of type
SignalPar. The data type SignalPar has the following components:
(0 mA->100%, 20 mA->0%).
Fraction Dint Specifies the number of decimals to be displayed.
Unit string Display the physical unit.
Chapter 8 - 21
776516416.doc
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 8 - 22
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.
Chapter 8 - 23
776516416.doc
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”.
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 8 - 24