You are on page 1of 23

VARIABLES

AND DATA
TYPES
Presentor: Joshua Postrero
ARE VARIABLES ENOUGH TO RUN
A CONTROL PROGRAM?
VARIABLES AND DATA TYPES
◦ The use of exclusively directly represented variables is not enough to
create control programs.
 Resources
 Inputs
Outputs
 Memory
◦ Data is frequently required which contains specific information and a more
complex nature.
◦ It can be a specified direct or accessible only via variables.
SYMBOLIC ADDRESSING

◦ Symbolic Identifier – consists of capital or lower case letters, digits and


an underline.
◦ Always begin with a letter or an underline.
◦ The underline can also be used to render an identifier more readable.
◦ Same or different? Motor_on and Motoron
◦ MOTORON and Motoron interpreted identically and designate the same
object.
◦ The following identifiers are impermissible:

 Note: Symbolic identifiers must not be identical with key words.


REPRESENTATION OF DATA
◦ In a program, it is possible for time values, counter values and more to be
specified.
◦ EN 61131-3 (IEC 61131-3) laid down the definitions for the representation
of data to specify:
Counter Values
Time Values
 Strings
REPRESENTATION OF NUMERICAL DATA
REPRESENTATION OF TIME DATA
◦ EN 61131-3 (IEC 61131-3) provides different types of time data:
 Duration
 Date
 Time of day (synchronization from start or end of an event)
◦ Capitals may also be used instead of lower case letters and individual
underlines inserted for the purpose of better readability.
◦ Use of sequence of characters known as strings which may be required for
exchange of information.
◦ A string consists of zero or several characters, introduced and ended by a
simple inverted comma.
DATA TYPES
◦ EN 61131-3 (IEC 61131-3) defines a large number of data types for
different tasks.
◦ Apart from these predefined elementary data types, the user has the
possibility of defining own data types.
◦ Useful in the cases where the problem definition goes beyond the realms
of pure control technology.
◦ Derived data types are declared within a TYPE…END_TYPE construct.
Significance of individual data types:

◦ A data element of the type Colour may only assume one of the values
RED, BLUE, YELLOW or BLACK.
◦ A data element of the data type Reference_range may only assume values
between 80 and 110 including the lower and upper limit.
◦ A Position type data element represents a list with 10 entries. Each entry
has the value of REAL number.
◦ A Coordinates type data element contains two REAL numbers which can
be accessed through their names X and Y.
VARIABLE DECLARATION
◦ With the use of data, the right of access to this data must be clearly
defined.
◦ Constructed into individual organization units:
 Configuration
 Resource
 Programs
 Function Blocks
 Functions
◦ In the case of programming languages in text form (IL and ST), variable
declarations are roughly the same as those used in the programming
language Pascal.
◦ For graphic forms of representation, a tabular form with equivalent
contents would be feasible.
◦ All variable declarations always start with a keyword which designates the
position of the variable in the organization unit of the controller and end
with the keyword END_VAR
◦ The data type named after a colon and the declaration closed with a
semicolon.
◦ Each declaration is written in a separate line.
◦ EN 61131-3 (IEC 61131-3) differentiates between six different types of
access to variables. Each type has a keyword which introduces the
variable declaration.
DECLARATION OF INPUT AND OUTPUT
VARIABLE
◦ Input variables are declared with the keywords VAR_INPUT and
END_VAR.
◦ Variables specified in this way represent input variables fed externally to
an organization unit. These can be read only within the organization unit.

◦ Output variables are defined with the keywords VAR_OUTPUT and


END_VAR
◦ All organisation unit results are transferred beyond the organisation units
via variable declaration.
DECLARATION OF INPUT AND OUTPUT
VARIABLE
DECLARATION OF A IN-/OUTPUT
VARIABLE
◦ Variables containing input and output values are permitted through the use
of this keywords VAR_IN_OUT and END_VAR
◦ This represents a third option and permits the declaration of variables,
which may be read and used within the organisation unit.
◦ Variable declared as VAR_IN_OUT is assumed that values will be supplied
both to and from the organization unit.
DECLARATION OF LOCAL VARIABLE
◦ The variables specified here are local to an organisation unit and can only
be used within. The are unknown in all other organisation units.
◦ In the case of these variables, they may also exist several times in
different organisation units. However, these local variables are totally
related and differ from one another.
◦ Variables are required for intermediate results which are to remain
unknown externally.
DECLARATION OF GLOBAL VARIABLE
◦ A variable may be globally declared, in which it may be accessed
universally.
◦ The necessary declaration is carried out in a similar way using the
keywords: VAR_GLOBAL and VAR_EXTERNAL.
◦ This declaration can only be found in the organisation units configuration
and resource.
DECLARATION OF ACCESS OF A
GLOBAL VARIABLE
◦ Inorder to facilitate access of global datato an organisation unit, this
declaration is to be recorded in the organisation unit.
◦ Failed to declared this variable, access to global data would not be
permissible.
◦ Strict declaration of unit for all variables uniquely defines which variables
are recognized by an organisation unit and how it may be used.
INITIALISATION
◦ It is essential for a variable to be given an initial value. This value may
change several times during the processing of a program though it is
defined at the start.
◦ Such initial values are specified jointly with the declaration of the variables.
A global variable of this type named Dozen is to be declared which
assumes the value of 12 at the start of the program.

You might also like