You are on page 1of 38

Program Scan Cycle

 During execution of the program, PLC must know, in real-time, when the external
devices controlling the process changes their states
 For each operating cycle, the processor reads all inputs, takes these values then
energizes or de-energizes the outputs according to the user program
 The PLC operating cycle consists of the input scan, program scan, output scan,
and housekeeping duties
 Time taken to complete a scan cycle is called scan cycle time and indicates how
fast the controller can react to changes in the input

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 1


Program Scan Cycle Cont’
 The scan is normally a continuous and sequential of reading the input status,
evaluating the control states, and updating the outputs
 For each program line (rung) executed, the PLC processor:
− Examine the status of the input image table bits
− Solve the ladder logic in order to determine logical continuity
− Update the appropriate output image table bits, if necessary
− Copy the output image table status to all of the output terminals.
− Power is applied to the output device if the output image table bit has been
previously set to a 1.
− Copy the status of all of the input terminals to the input image table. If an input is
active (i.e., there is electrical continuity), the corresponding bit in the input image
table will be set to a 1.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 2


PLC Programming Languages: Overview
Programming Languages: Refers to ways by which the user communicates to PLC
 The standard IEC 61131 was established to standardize the multiple languages
associated with PLC programming.
 The advantage of the standards is to allow multiple languages to be used within
the same programmable controller
 It allows the program developer to select the language best suited for each
application
 PLC programming Languages are broadly categorized as Textural and Graphical
programming languages

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 3


PLC Programming Languages: IL
 Instruction List (IL)
− Similar to low-level assembly language
− A program organization unit (POU) consists of a sequence of instructions
− Each instruction is situated on a separate line
− Instructions can be modified by a set of modifiers such as negation,
conditionality, jumping, return, and priority.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 4


PLC Programming Languages: IL
Instruction code Mneumonics

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 5


PLC Programming Languages: Structured Text (ST)
 Structured Text (ST) programming
− The syntax is similar to that of high-level procedural programming languages
like C and PASCAL
− The syntax is defined by commands and expressions
− The commands are divided by semicolons
− There could be more than commands in one line
− The statements use predefined statements and subroutines to change variables,
these being defined values, internally stored values, or I/P or O/P
− Assignment statements are used to indicate how the value of a variable is to be
changed.
− The general format of an assignment is given as

where Y represents an expression that process a new value for variable X, and :=
is the assignment symbol.
− The variable retain the assigned value until another assignment change the value
− Other examples are

Indicating that the light will be switched ON either by switch A OR switch B

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 6


PLC Programming Languages: Structured text (ST)
Structured Text Operators

 Parentheses (brackets) are used to group expressions with expressions to


expressions to ensure that the expression is executed in the required sequence.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 7


PLC Programming Languages: Structured text (ST)
 Structured text is not case sensitive, thus lowercase and capital letters can be used
to aid clarity
 Spaces and indenting lines are not necessary, but can be used to aid clarity
 All the identities of directly represented variables start with the % character and are
followed by a one- or two-letter code to identify whether the memory location is
associated with inputs, outputs, or internal memory and whether it is bits, bytes, or
words, such as

 The first letter is I for input memory location, Q for output memory location, or M
for internal memory.
 The second letter is X for bit, B for byte (8 bit), W for word (16 bits), D for double
word (32 bits), or L for long word (64 bits).
 AT is used to fix the memory location for a variable. Thus,

 Conditional statements
− The IF statement:
indicate that if the fluid temp variable is ON, the actions following that line in the
program are to occur.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 8


PLC Programming Languages: Structured text (ST)
− IF……THEN…ELSE is used when selected statements are to be executed when
certain conditions are fulfilled

− Another example using PLC addresses

− if there is an input to I:000/00 to make it 1, output O:001/00 is 1; otherwise it’s


0.

− CASE is used to give the condition that selected statements are to be executed if
a particular integer value occurs else some other selected statements

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 9


PLC Programming Languages: Structured text (ST)
− As with all conditional statements, the end of the CASE statement has to be
indicated

 Iteration statements: are used where it is necessay to repeat one or more


statements a number of times, depending on the state of some variable
− The FOR … DO iteration statement allow a set of statements to be repeated
depending on the value of iteration integer variable.

− WHILE … DO allows one or more statements to be executed while a particular


Boolean expression remains true

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 10


PLC Programming Languages: Structured text (ST)
− Example of WHILE … DO loop

− REPEAT … UNTIL: Allows one or more statements to be executed and repeated


while a particular Boolean expression remains true

 Structured Text Program: Before writing the instruction statements of ST


program, the following must be defined:
− The data type required to represent data. eg.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 11


PLC Programming Languages: Structured text (ST)
− Data type

− The variables, i.e. signals from sensors and output signals to be used in a
program

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 12


PLC Programming Languages: Structured text (ST)
− Any initial value to be given to variables

A ladder program rung and two equivalent ST

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 13


PLC Programming Languages: ladder Diagram
 Ladder Diagram
− Also known as ladder logic
− One of the oldest programming language for PLCs
− Based on graphical representation of relay contact logics. Therefore it is well
suited to express Boolean circuits
− It also accommodates elements of block diagram language

 Ladder programming represents basic switching operations involving logic


functions of AND, OR, EXCLSIVE OR, NAND, and NOR as well as latching.
 Writing a ladder program is equivalent to drawing switching circuit
 Drawing a ladder diagram, certain conventions are adopted:
− Vertical lines represents power rail between which circuit are connected. Power
flow is taken to be from left-hand vertical across a rung
− The horizontal circuit linea are referred to as rungs and shows the control portion
of the circuit.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 14


PLC Programming Languages: Ladder Diagram
− Each rung on the ladder defines one operation in the control process
− A ladder diagram is read from left to right and top to bottom.

− Each rung must start with an input(s) and must end with atleast one output.
Input is with reference to control action such as closing the contacts of a switch,
while output is with reference to devices connected to the output of a PLC.
− Electrical devices are shown in their normal condition. i.e., normally closed or
normally closed.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 15


PLC Programming Languages: Ladder Diagram
− A particular device can appear in more than one rung of a ladder
− I/O are all identified by their addresses. Here the notation depends on the PLC
manufacturer.

 Basic ladder logic contact symbols

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 16


PLC Programming Languages: Ladder Diagram
 Basic ladder logic coil (Output) symbols

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 17


PLC Programming Languages: Ladder Diagram
 Basic ladder logic coil (Output) symbols cont’

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 18


PLC Programming Languages: Ladder Diagram
 Different manufacturers have different addressing for I/Os

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 19


PLC Programming Languages: Ladder Diagram
Logic Functions
 Control actions are effected when certain conditions are realized. Eg. If condition A
and B are realized an output ocurrs

 AND-gate
− Output is not energized unless two normally open switches are both closed

− Example of an AND gate is the interlock control system for machine tool: The
machine can only be operated if both the safety guard is in position and and
power switch is ON.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 20


PLC Programming Languages: Ladder Diagram
 OR-gate
− Output is energized when an input A or input B that is normally closed is put ON.

− Example of an OR-gate control system is the is a conveyor belt transporting


bottled products to packaging where a deflector plate is activated to deflect
bottles into a reject bin if either the weight is not within certain tolerances or
there is no cap on the bottle.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 21


PLC Programming Languages: Ladder Diagram
 NOT-gate
− There is an output when there is no input snd no output when there is an input.

− Example of an NOT-gate control system is a light that comes on when it


becomes dark. i.e., when there is no light input to the light sensor, there is an
output.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 22


PLC Programming Languages: Ladder Diagram
 NAND-gate
− If NOT-gate is placed at the output of AND-gate, all the outputs from AND-gate
are inverted. Similar results are obtained if NOT-gate is placed on each input,
then the resulting inputs ORed

− Example of an NAND-gate control system is a warning light that comes on in


machine tool if, safety guard switch and limit switch signaling the presence of
work piece have not been activated.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 23


PLC Programming Languages: Ladder Diagram
 NOR-gate
− If NOT-gate is placed at the output of OR-gate, all the outputs from OR-gate are
inverted. Similar results are obtained if NOT-gate is placed on each input, then
the inverted inputs ANDed

− Used in sequential circuits to make level and edge triggered flipflops, which are intern used in
memory devices (most kinds of ROM and RAM), shift registers etc.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 24


PLC Programming Languages: Ladder Diagram
 XOR-gate
− Also referred to as Exclusive OR. This gate gives the output when either of the
outputs is 1, but not when both are 1.
− One way of obtaining such a gate is by using NOT, AND, and OR gates

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 25


PLC Programming Languages: Ladder Diagram
Latching
 In some applications it is necessary to hold energized output even when the input
ceases. Example of such a situation is a motor that is started by pressing a push-
button switch.
 Latching is like keeping a flag/output coil ON using a parallel branch NO contact of
the same O/P status resulting to a continuous ON output.

 Explanation
− If input A contact closes, there will be an output.
− When the output is energized, other sets of contacts associated with O/P a closes
− These contacts forms OR logic gate system with the input contacts
− Then, even if input A opens, the circuit will still maintain the output energized
− The only way to release the output is by opening the NC closed contact B.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 26


PLC Programming Languages: FBD
Function block diagram (FBD)
 Basic elements of the FBD language
− Identifiers: Can be any string of letters, digits and underscores, provided that the
first character is not a digit and there are not two or more underscores
− Keywords: The FBD programming keywords like TYPE and TRUE, should not be
used as identifiers
− Comments: Comments are framed by characters (*……..*)
− Data types: There are six main groups of data types: Integers, floating point,
dates and time of the day, duration, strings, and bits
− Variables: Can be declared at the beginning of each definition for the different
program organization units (POU). There are different categories of variables:
Internal variables, input variables, output variables, I/O variables, global
variables, external variables, directly represented variables, access variables.

 Graphical elements of the FBD language


− Typical uses of FBD include describing control loops and logic
− Within FBD a function block is depicted as a block with inputs and outputs
− The function block type name is always shown within the block whereas the name
of the function block instance is always indicated above the block
− Formal names of inputs and outputs are shown within the block at the appropriate
input and output points.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 27


PLC Programming Languages: FBD
− The order in which the I/O are described in the function block should always be the
same
− In a FBD network, the signal are considered to flow from the output of the
functions and function block to the input of other functions and function block
− O/P of function blocks are updated as a result of function block evaluations
− Change of signal states propagates from left to right across the FBD network

 Declaration of a program organization unit consist of two parts


− I) External interface or variable declaration: Variables can be declared at the
beginning of each definition for different POUs. In the external interface not all
categories of variables can be declared, like global variables. These variables are
added in text. It is also impossible to initialize variables in graphic.
Textual variable declaration in a function block

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 28


PLC Programming Languages: FBD
− II) Body: The body shows the algorithm which the POU has to perform. The body
can be defined in the five languages of the IEC 1131-3 standard, in this case FBD

Graphical function block declaration  The function block TMR and SR are
standard IEC function blocks.
 DB_ON is the name of an instance of
the SR function block type
 The S input is driven by Q output from
the function block DB_ON which has
an instance of function block type TMR
 When using Boolean signals, negated
inputs of functions and function blocks
is shown using small circle at the input
point
 In an FBD network a cross-diagram
connector can be used to aid in
readability and avoidance of graphical
connections that are difficult to draw
 Connector has no significance as far as
program behavior is concerned

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 29


PLC Programming Languages: FBD
 Feedback paths  Function execution control
− Standards allows signal paths to be − Execution control of functions in an
fed back from function block output to FBD network is implicit from the
input of the preceding blocks on the position of the function in the network
left of network. − Control of function can be made
− An implicit feedback paths can be explicit by using the function enable
created using connectors that links the input EN and function enable output
output parameters from blocks on the ENO.
right of the network to input − EN input is a Boolean variable that
parameters of preceding blocks in allows a function to be selectively
order to reduce lines in the network. evaluated
− Behavior of networks with feedback − ENO output is a Boolean variable that
paths may vary subtly between indicates that the function has
different implementations completed its evaluation by the ENO
value changing from FALSE to TRUE.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 30


PLC Programming Languages: FBD
 Jumps − If the Boolean signal is always TRUE
− To facilitate the transfer of control as a constant, the jump is called
action from one part of FBD network a Unconditional
graphical jump facility is used − The Boolean signals that cause a jump
− Section of FBD network is identified in network evaluation order should be
using labels followed by a double arrow and the
− By assigning a Boolean signal to the label identifier.
label identifier, it is possible to transfer − Conditional returns from the functions
control action to another part of the and function blocks are implemented
network. using a RETURN construction

 Functions and function blocks


− For the same sets of input values,
function block will not necessarily
produce the same set of output values,
while function does.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 31


PLC Programming Languages: SFC
 Sequential function chart (SFC)
− The SFC programming is designed to
accommodate the programming of
more advanced process
− It consists of steps, transitions, and
action
− Step represents a state of controlled
system and has an assigned action
block
− Transition expresses condition to
deactivate the previous step and
activate the next step
− The process continues from one state
to the next until the complete
machine cycle is realized
− Actions/Outputs at any step are
denoted by horizontally linked boxes
and occur when that state has been
realized

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 32


PLC Programming Languages: SFC
SFC structure  Transitions
 Step − The transition indicates the execution
− Step indicates the unit of the process transition condition between
sequence control by connecting the steps
action − The transition condition is prepared
− If the step is active, the attached by IL or LD of PLC language
action is executed − If the result of transition is 1, current
− Initial step is initially active step step will be inactive and next step will
be active
− The transition will be arranged
between steps

−If transition condition is established


after initial step, current active step
(s1) is change to the inactive status
and next step (S2) is active

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 33


PLC Programming Languages: SFC
− If TRANS is ON, S1 will be inactive
and S2 will be active
− The transition condition will be output
by TRANS variable at all transition

 Actions
− Two actions can be connected to each
step
− The step without action is regarded as
the standby until the next transition
condition is 1
− The action consists of IL or LD of PLC
language and the action is executed
while the step is active
− The qualifier is used to control the
action
− If the action is changed from active to
inactive status, the contact output
executed at the action will be 0, but
R, S, function and function block
output retains the status before
inactive status

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 34


PLC Programming Languages: SFC
− ACTION1 is executed only when S1 is
active
− ACTION2 is executed when R qualifier
is meet after S1 is active. It will be
continuously executed though S1 is
inactivated
− At the moment of disabling the b) S (Set) : The action is executed as
action, the action is post scanned and soon as the step is active, till R qualifier
switched over to the next step is executed

 Action qualifier
− Action qualifier is used whenever the
action is used
− The execution point/time of the action
relating to the step is defined
according to the selected qualifier.
− The action qualifiers are classified as:

a) N (Non-stored): The action is


executed along as the step is active

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 35


PLC Programming Languages: SFC
c) R (Overriding Reset): The action e) D (Time delayed): The action is
executed by S, SD, DS, and SL is executed after a preset time T has
aborted elapsed and remains like that for as
long as the step is active
d) L (Time limited): The action is
executed for a preset length of time T,
as long as step is active

f) P (pulse): As soon as the step is


active, the action is executed for one
cycle

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 36


PLC Programming Languages: SFC
g) SD (Stored & Time delayed): The h) DS (Delayed and Stored): For SD
action is executed when a preset period qualifier, the action is also executed
of time T has elapsed after step with time delay. It differs from the SP
activation, even if the step becomes qualifier in that the step must remain
inactive. This condition persist until the active during the time delay
R qualifier is executed.

i) SL (Stored and time limited): This


action is executed for a preset duration
of time T as soon as the step is active
until the R qualifier is executed.

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 37


PLC Programming Languages: SFC
SL

Dr.-Ing. Jackson G. Njiri EMT 2549 L-4: PLCs Programming Languages 38

You might also like