You are on page 1of 13

Peralta, Jan Dominic October 1, 2020

ME 522M Engr. Earl Ray Aniñon


Reporting 3 (Chapter 6.3 Program for a Controller)

PROGRAM FOR A CONTROLLER

UNITS OF THE PROGRAM


The program for a controller is divided into separate organisation units.
 Functions
 Function blocks
 Programs

IEC 61131-3 - Defines a wide range of standardized functions and function blocks, and also contains the
definitions of custom made functions and function blocks for manufacturers to follow.

FUNCTIONS
 Are software modules which, when used only provide one result or output
 Cannot contain status information, which means that the usage of a function with the same
inputs, must provide the same result or output.
 Examples (Addition of Integer Values, Logic OR Functions)

GRAPHICAL REPRESENTATION OF A FUNCTION


4 Parts of the graphical representation

Function Name

Output Parameters

Input Parameters
Parameter Names
USE OF PARAMETER NAMES WITH FUNCTIONS

 Function with identical Inputs

• Example shown: Addition

 Function with unidentical inputs

• Example shown: Bit Shift

REPRESENTATION OF BOOLEAN NEGOTIATIONS

 The Boolean inputs or outputs of a function may be negated, by placing a circle directly outside
the rectangle.

OVERLOADED FUNCTIONS - Are functions which operate to input parameters of a different data type.

TYPE-INDEPENDENT FUNCTIONS - Are functions which operate using variables which are declared to
one data type.

TYPED FUNCTIONS - Are functions which are limited to a particular data type by the controller, Are
recognizable by their function name, where there is addition of an underline, followed by the desired
date type.
GENERIC DATA TYPES

 Since there are different data types that can be used as input parameters, they have been
grouped together, a few are as shown in the table below:

Group
Definition
Name

ANY_NUM All data integer types for floating numbers such as REAL and for integer numbers such as
INT, UINT, etc.

ANY_INT All data types for integers such as INT, UINT, etc.

ANY_REAL All data types, defining floating-point numbers such as REAL or LREAL

ANY_BIT All bit sequence data types such as BOOL, BYTE, WORD, etc.

STANDARD FUNCTIONS

Bit-by-bit Boolean Functions

Name Symbol Description

AND & AND Operation of all inputs

OR >=1 OR Operation of all inputs

XOR =2k+1 Exclusive OR operation of all inputs

NOT Negating Input


DIFFERENCES OF BOOLEAN FUNCTIONS

AND OR

XOR NOT

BIT SHIFT FUNCTIONS

Name Description

SHL Shift IN by N bits to the left, fill with zeros to the right

SHR Shift IN by N bits to the right, fill with zeros to the left

ROR Shift IN cyclically by N bits to the right

ROL Shift IN cyclically by N bits to the left


SHL (SHIFT LEFT)

 This instruction shifts the IN bits to the left by N number of times, this instruction multiplies the
value of the input by 2N in Decimal Form

 Equation: Previous Number x 2N = Output

SHR (SHIFT RIGHT)

 This instruction shifts the IN bits to the right by N number of times, this instruction divides the
value of the input by 2N in Decimal Form

 Equation: Previous Number / 2N = Output

ROR (ROTATE RIGHT)

 This instruction rotates the IN bits to the right by N number of times.

ROL (ROTATE LEFT)

 This instruction rotates the IN bits to the left by N number of times.

COMPARISON FUNCTIONS

Name Symbol Description

GT > Greater

GE >= Greater or equal

EQ = Equal

LE <= Less or Equal

LT < Less

NE <> Not Equal


ARITHMETIC FUNCTIONS

Name Symbol Description

ADD + Add all inputs

MUL * Multiply all inputs

SUB - Subtract 2nd input from 1st input

DIV / Divide 1st input by 2nd input

MOVE := Assign input to output

TYPE CONVERSION FUNCTIONS

 Binary to Decimal – converts variables of type Byte, Word, etc., into variables of type INT

 Decimal to Binary – converts variables of type INT into variables of type Byte, Word, etc.

FUNCTION BLOCKS

 Are software modules, which supply one or several result parameters

 If a function block in a control program is to be used, a copy or instance must be created. This is
effected via the assignment of an instance name/identifier. Linked to this is a data structure
which stores the statuses of this function block copy (values of input parameters, output
parameters and internal variables). The status information of this copy remains intact from one
processing to the next.

 Examples (Counters, Switch Signal Delays, Pulse Timers)


The Resources of a PLC are the constituents that are used by a control program, which are
basically and most importantly the inputs, outputs, and the memory.
The most important controller constituents are as stated, the inputs, outputs, and the memory.
The inputs serve as, well basically, the input, through which a controller can receive information
from the connections or processes. With that, the outputs serve as the constituents that allow
these inputs to influence the controller or store information for further processing.

These designations in Fig. B6.1 are for directly represented variables which means they are
referred directly to the hardware-related available inputs, outputs, and memory of the controller.
Different allocation of inputs, outputs, etc. are defined by their respective controller
manufacturer.
So long as the respective controller can support it, these resources can be addressed, and are
defined in an excess of one bit. EN 61131-3 designates the data types shown in Fig. B6.2 below
together with inputs, outputs, and flags. As a quick note, flags are one or more data bits used to
store binary values as specific program structure indicators, or in other words, are a component
of a programming language’s data structure.

BOOL (or Boolean) can only assume values 0 or 1, in length 1.


BYTE can assume values of 0 or 1, in length 8.
WORD can assume values of 0 or 1, in length 16.
Below in Fig. B6.3 are the mandatory designation methods for inputs, outputs, and flags of
different bit length.
Due to the nature of a controller having large numbers of inputs, outputs, and flags available,
these shall then be specifically identified for the purpose of differentiation, with the example
being:

Now, there is no way other than through the controller manufacturer, to know the specific
number range, which is permissible for this numbering and whether it should start with 0 or 1.
A hierarchical number of inputs, outputs and flags may be used, so long as the controller has
been suitably configured for it.
A point or dot shall be used to separate individual levels of the hierarchy.
The highest position in the number on the left must be coded.
The lower positions of the hierarchy on the right represent consecutive lower positions.
Let’s take for example I3.8.8, which can therefore be understood as follows:
5 PARTS OF THE GRAPHICAL REPRESENTATION OF A FUNCTION BLOCK

Function Block Identifier


Type Label

Input Output
Parameters Parameters

Parameter
Names

THE MOST IMPORTANT FUNCTION BLOCKS STANDARDIZED BY IEC 61131-3

Function Block Type Description


SR Bistable Function Block (Primarily Setting)
RS Bistable Function Block (Primarily Resetting)
CTU Incremental Counter
CTD Decremental Counter
TP Pulse
TON Switch-on signal delay
TOF Switch-off signal delay
R_TRIG Edge Detection: rising edge
F_TRIG Edge Detection: falling edge
USER-DEFINED FUNCTIONS

IEC 61131-3 permits the definition of own functions ff. the rules for graphic declaration:

 Declaration of the function within a FUNCTION… END_FUNCTION construct

 Includes specification of all parts of the function (function name, parameter names,
input/output data types)

 Includes specification of the names and data types of internal variables used in the function,
declared using a VAR… END_VAR construct may be used for this.

 Programming of the function body in one of the languages: LD, FBD, IL, or ST.

USER-DEFINED FUNCTION BLOCKS

IEC 61131-3 permits the definition of own function blocks ff. the rules for graphic declaration:

 Declaration of the function within a FUNCTION_BLOCK… END_FUNCTION_BLOCK construct

 Includes specification of all parts of the function (function name, parameter names,
input/output data types)

 Includes specification of the names and data types of internal variables used in the function,
declared using a VAR… END_VAR construct may be used for this.

 Programming of the function body in one of the languages: LD, FBD, IL, or ST.

PROGRAMS

 Consists of any language elements and constructs necessary to achieve the desired machine or
process behaviour via the PLC

 Constructed in the main for functions, function blocks, and the elements of the sequential
function chart.

 Program features are largely identical to those of function blocks, with some key differences:

1. The delimiting keywords for program declarations are PROGRAM…END_PROGRAM.

2. Use of Directly addressable variables are permitted within programs only.


It is the use of exclusively directly represented variables is not enough to create control
programs such as resources, inputs, outputs and 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 always consists of capital or lower case letters, digits and an underline. •
An identifier must always begin with a letter or an underline.

• The underline can also be used to render an identifier more readable.

• Several underlines are also impermissible. If the controller supports capital and lower case
letters, then the use of these letters are not significance.

• Symbolic identifiers must not be identical with keywords

• Keywords are words reserved for specific tasks.

Representation of Data • Within a control program, it must be possible for time values and
counter values 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

• The use of individual underlines between the digits is permissible to improve readability.
However, the underline is not significant.

EN 61131-3 (IEC 61131-3) provides different types of time data:

✓ Duration (for measuring results) ✓ Date ✓ Time of Day

• The specification of a time duration consists of an introductory part and a sequence of time
related sections.

• Capitals may also be used instead of lower case letters and individual underlines inserted for
the purpose of better readability. • Another method of representing data is the use of sequence
of characters known as strings. 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.

• A BOOL type variable either assumes the value 0 or 1.

• INT and UINT define integer numbers. • The range of values of data type INT covers both
negative and positive numbers. • Type UINT variables permit positive values only. • SINT (Short
integer) and DINT (double integer) have smaller or greater range of values than type INT. • Data
type TIME used to specify time and may contain a time duration.

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

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

• EN 61131-3 (IEC 61131-3) differentiates between six different types of access to variables
namely:

✓ Input Variables ✓ Output Variables ✓ In-/Output Variables ✓ Local Variables ✓ Global


Variables ✓ External Variables
• Input variables are declared with the keywords VAR_INPUT and END_VAR.

• Input Variable - 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

• In-/Output Variable - variables containing input and output values are permitted through the
use of this keywords VAR_IN_OUT and END_VAR.

• In-/Output Variable - this represents a third option and permits the declaration of variables,
which may be read and used within the organisation unit.

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

• Global Variable – a variable may be globally declared, in which it may be accessed

You might also like