0% found this document useful (0 votes)
82 views

T314-09 Variables and Data Types - RevC

The document discusses variables and data types in automation systems. It describes declaring and scoping of variables, as well as different data types. It also covers defining structured data types and allocating variables to I/O channels.

Uploaded by

Rio Yuwandi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

T314-09 Variables and Data Types - RevC

The document discusses variables and data types in automation systems. It describes declaring and scoping of variables, as well as different data types. It also covers defining structured data types and allocating variables to I/O channels.

Uploaded by

Rio Yuwandi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

System 800xA Training

Chapter 9 Variables and Data Types

TABLE OF CONTENTS

Chapter 9 Variables and Data Types ....................................................................................................................................... 1


9.1 General Information ..................................................................................................................................................... 2
9.1.1 Objectives.............................................................................................................................................................. 2
9.1.2 Legend .................................................................................................................................................................. 2
9.1.3 Reference Documentation ...................................................................................................................................... 2
9.2 Variables...................................................................................................................................................................... 3
9.2.1 Declaration and Scope of Variables ........................................................................................................................ 3
9.2.2 External Variables.................................................................................................................................................. 6
9.2.3 Variable Scope....................................................................................................................................................... 6
9.2.4 Variable Naming Rules .......................................................................................................................................... 7
9.3 Data Types ................................................................................................................................................................... 8
9.3.1 Simple Data Types................................................................................................................................................. 8
9.3.2 Initial Values for a Variable ................................................................................................................................... 9
9.3.3 Variable Attributes................................................................................................................................................. 9
9.3.4 Further Information...............................................................................................................................................10
9.4 Declaration of Variables ..............................................................................................................................................11
9.4.1 How to Declare a Variable in a Program................................................................................................................11
9.4.2 How to Declare a Variable in an Application .........................................................................................................11
9.4.3 How to Declare a Variable in a Function Block Type.............................................................................................12
9.4.4 How to Declare a Variable in a Control Module Type............................................................................................13
9.5 Structured Data Types .................................................................................................................................................14
9.5.1 Overview..............................................................................................................................................................14
9.5.2 Data Types in Libraries and Applications ..............................................................................................................15
9.5.3 How to Define a User Data Type...........................................................................................................................15
9.5.4 Reference to Components in a Structured Variable ................................................................................................16
9.6 Allocating Variables to I/O Channels ...........................................................................................................................17
9.6.1 System defined I/O Data Types .............................................................................................................................17
9.6.2 Allocation in the Hardware Editor .........................................................................................................................18
9.7 Project Constants.........................................................................................................................................................19
9.7.1 Purpose and Usage................................................................................................................................................19
9.7.2 Defining Project Constants....................................................................................................................................19
9.7.3 Dot Notation used with Project Constants..............................................................................................................20

Chapter 9 - 1
T314-09 Variables and Data Types - RevC

9.1 General Information

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

9.1.3 Reference Documentation


3BSE035980 Industrial IT 800xA – Control and IO
Basic Control Software – Introduction and Configuration
3BSE043732 Industrial IT 800xA – Control and IO
Application Programming – Introduction and Design

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.

9.2.1 Declaration and Scope of Variables


When a variable is created by the programmer it is said to be declared. When a
variable is declared you must, at the very least, give it a name and a data type.

9.2.1.1 Variables in Applications


Variables are declared in an application by opening the application editor from the
Project Explorer tree:

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.

9.2.1.2 Variables in Programs


Variables are declared inside programs within an application by opening the program
editor of the program concerned:

Variables declared inside a program are known only within that program. They are
local to the program itself.

Chapter 9 - 4
System 800xA Training

9.2.1.3 Variables in Function Block Types


Variables may also be declared inside a Function Block Type. Such variables are local
to the function block and are not ‘visible’ outside the function block.
Variables are declared in the Function Block Type Editor:

When a function block is instantiated, the variables declared in the type are created in
each instance.

9.2.1.4 Variables in Control Module Types


Variables may be declared inside a control module type. Such variables are local to the
control module and are not ‘visible’ outside the control module.

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

9.2.2 External Variables


In the function block type editor and also the control module type editor there is a tab
for declaring “External Variables”.

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.

9.2.3 Variable Scope


It is important to understand the scope of a variable declared in the various objects
described above. Here is a summary:
Application variables known only in the application space
Application Global variables known in the application space and also in any
program contained in the application
Program variables known only in the program in which declared
Variables in function block
and control module Types known only in the function block or control
module instances

Chapter 9 - 6
System 800xA Training

9.2.4 Variable Naming Rules


The following rules apply when declaring a variable:
• A variable name may have up to 32 characters
• The name of the variable must not begin with a number
• No spaces are permitted in a variable name
• In general use only alphanumeric characters and the underscore character. Do not
include any special characters such as $, # or others.
• Variable names are NOT case sensitive.
• A variable may not have a ‘Key word’ as a name. Some key words are reserved by
the system and you will be warned if you have used a key word for a variable
name.
• Within any one POU (application, control module, function block or program),
variable names must be unique.

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

9.3 Data Types


A variable must be given a data type when it is declared.
There are many different data types in the system, a user may also define his own
types. Data type definitions are usually done within libraries and the standard libraries
from ABB contain additional data type definitions which are used by the objects
within the respective library.

9.3.1 Simple Data Types


Several simple data types are defined in the System Library:

Data type Description Bits Default value Remarks


bool Boolean 1 False, 0 True and False (1/0 and On/Off are
permitted alternatives)
Dint Double integer 32 0 range is -2 147 483 647 to +2 147 483 647
Int Integer 16 0 range is -32767 to +32767
Uint Unsigned integer 16 0 range is 0 to 63335.
String Character string * ‘’ (empty string) see below
DWord Bit string 32 0 Each of the 32 bits may take a value of True
or False (1 or 0)
Word Bit string 16 0 The equivalent of the 16 bit registers found
in some PLCs. Each of the 16 bits may take
a value of True or False (1 or 0)
Time Duration 0s Held in internal coded format. There are
data type conversion functions to extract the
actual hours, minutes and seconds from a
time variable. Used for preset and elapsed
variables connected to timers.
Date_And_Time Date and time of day 1979-12-31-00:00:00 Stored in internal format, but may be
converted to other data types using
functions in the System library.
±38
Real Real number 32 0.0 Range is ± 1.7014 x 10

When a variable of type string is declared it has a length of 40 characters by default,


however this can be changed by entering string[xx] as the data type, where xx is the
string length. The maximum length of a string variable is 140 characters.

FirstString will default to 40 characters, SecondString has a capacity for 80 characters


and ThirdString 10 characters.

Chapter 9 - 8
System 800xA Training

9.3.2 Initial Values for a Variable


The “Initial value” column in the declaration pane allows you to give a variable a
value which it will have when the application is first executed. The initial value will
be assigned to the variable before the first execution scan of the code following a
compilation and download of the application.
NOTE! Variables with the attribute ‘coldretain’ have a different
behavior once the application has been downloaded.
If a variable is not given an initial value then it will take the default value for that type
as shown in the table above.

9.3.3 Variable Attributes


The following attributes can be given to a variable:

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).

9.3.4 Further Information


I/O-address
If a variable is connected to an I/O channel in the hardware part of the Project
Explorer tree, the connected channel address will be listed in the I/O address column.
Access Variables
This column will be filled automatically after you declare the access variables and
map them to a particular variable. (See later chapter ”Communications”)
Description
The description allows the programmer to provide information about the variable. A
short descriptive text, for example, would include an explanation of the cause of a
condition or a simple event: Pump 1 is running.

Chapter 9 - 10
System 800xA Training

9.4 Declaration of Variables


The verb, declare, means to create a variable. A variable may be thought of as an
instance of a data type.

9.4.1 How to Declare a Variable in a Program


1. Mark the program in the Project Explorer
2. Click right and select “Editor”

3. Define a variable name and data type in the “Variables” tab

4. Give the variable any attribute required


5. Give the variable an initial value if required
6. Give the variable a description if required

9.4.2 How to Declare a Variable in an Application


1. Mark the application in the Project Explorer
2. Click right and select “Editor”

Chapter 9 - 11
T314-09 Variables and Data Types - RevC

3. Decide whether the variable should be global or local to the application by


selecting the appropriate tab.

4. Define a variable name and data type in the “Variables” tab


5. Give the variable any attribute required
6. Give the variable an initial value if required
7. Give the variable a description if required

9.4.3 How to Declare a Variable in a Function Block Type


1. Mark the function block type in the library where it is defined in the Project
Explorer
2. Click right and select “Editor”

3. Define a variable name and data type in the “Variables” tab

4. Give the variable any attribute required


5. Give the variable an initial value if required
6. Give the variable a description if required

Chapter 9 - 12
System 800xA Training

9.4.4 How to Declare a Variable in a Control Module Type


1. Mark the control module type in the library where it is defined in the Project
Explorer
2. Click right and select “Editor”

3. Define a variable name and data type in the “Variables” tab

4. Give the variable any attribute required


5. Give the variable an initial value if required
6. Give the variable a description if required

Chapter 9 - 13
T314-09 Variables and Data Types - RevC

9.5 Structured Data Types

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.

Data type Components

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

9.5.2 Data Types in Libraries and Applications


Data types may be defined in applications or more usually in libraries. It is possible to
make definitions of types in an application but then only that application has access to
the type.

Data type definitions in


libraries

Data type definitions in


applications

Data types defined in libraries become available to all applications (and libraries) that
have that library connected to them.

9.5.3 How to Define a User Data Type


1. Select the library in which the data type is to be defined.
2. Select Data Types, right click and select “New Data Type…”

3. Give the data type a name:

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:

6. Give the component any attribute required


7. Give the component an initial value if required
8. Give the component a description if required

9.5.4 Reference to Components in a Structured Variable


Once a type has been defined, you may declare variables having that type.
Suppose that a plant has three tanks, then you could declare three variables of type
‘TankType’ called say Tank1_Data, Tank2_Data and Tank3_Data.
NOTE! Dot notation is used to read and write to the components
within a structured variable.

You could read the volume component by referencing Tank1_Data.Volume


TankVolume := Tank1_Data.Volume;

If you want to set the Full component of the Tank variable to 1 (i.e. "True"), write:
Tank1_Data.Full := true ;

The rest of the subordinate variables are accessed in a similar way.

Chapter 9 - 16
System 800xA Training

9.6 Allocating Variables to I/O Channels

9.6.1 System defined I/O Data Types


Although it is allowed to connect simple variables of type Bool and Real to digital and
analogue I/O channels respectively, it is better to use the system defined I/O data types
called BoolIO and RealIO.
DintIO is used to connect to integer channels on, for example, a pulse counter module
DwordIO may be used to access all 16 channels on a DI or DO module as a word
rather than as individual IO points.

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:

Name Data type Description


Value Bool Value used by the application code
IOValue Bool Value of the I/O channel. IOValue and Value are equal if
the channel is not forced.
Forced Bool Indicates whether or not the channel is forced.
Status Dword Status as a hexadecimal integer

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.

Name Data type Description


Value Real Value used by the application.
IOValue Real Value of the I/O channel. IOValue and Value are equal
if the channel is not forced.
Forced Bool Specifies whether or not the channel is forced.
Status Dint If the channel status is not OK, Status can take any of
these values:
-4029 Underflow
-4030 Overflow
-4031 UnitError
-4032 ChannelError
Parameters SignalPar Measuring range

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:

Name Data type Description


Max Real Maximum value to which you can scale a maximum
input signal.
Min Real Minimum value to which you can scale a minimum
input signal.
Inverted Bool Specifies if the connection to the analog I/O is reversed
(0 mA->100%, 20 mA->0%).
Fraction Dint Specifies the number of decimals to be displayed.
Unit string Display the physical unit.

9.6.2 Allocation in the Hardware Editor


Variables in the applications or programs may be allocated to the appropriate I/O
channels in the hardware part of the tree.
Double click the I/O module in controller hardware and use the “Connections” tab to
make connections between variables and I/O channels. Press “Ctrl-T” in the variable
column and choose the right variable to connect from the tree.

NOTE! Connections can be edited only in Offline mode.

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

9.7 Project Constants

9.7.1 Purpose and Usage


Values which are fixed may be declared as project constants. Project constants may be
defined for the project as a whole or for any individual library.
• Constants defined for a library will be available in an application, whenever that
library is connected to the application. Constants that are needed when a particular
library is used should be defined in that library.
• Constants defined for a project will be available for all applications within the
project. Constants that are specific to a project as a whole should be defined at
project level.
NOTE! It is never possible to write values into project constants.
They are fixed at compile time.

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.

9.7.2 Defining Project Constants


Select the project or the library in the Project Explorer. Click right and select “Project
Constants”. This will call up the Project Constant Editor as described below.

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.

9.7.3 Dot Notation used with Project Constants


Project constants may be grouped in the editor. Constants within a group are in a sub-
level of the named group. The constants within a group are referenced using “dot
notation”.
In the example above, the constant Idle in the group cAlarmCondStateText would be
accessed using the syntax “cAlarmCondStateText.Idle”

Chapter 9 - 20

You might also like