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

D05 - PLC Programming

Uploaded by

duc.bui1142002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

D05 - PLC Programming

Uploaded by

duc.bui1142002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

PLC Programming

PLC Programming

• Programing languages
• Bit level instructions
• Timers, Counters, Comparison,
Math
• Word logic
• Data areas, memory areas, data
rules, and address access
Programing languages

• Ladder
• Boolean
• Grafcet
Ladder
The programmable controller was developed for ease of programming using existing relay
ladder symbols and expressions to represent the program logic needed to control the
machine or process. The resulting programming language, which used these original basic
relay ladder symbols, was given the name ladder language.

basic ladder language enhanced ladder language


Boolean
Some PLC manufacturers use Boolean language, also called Boolean mnemonics, to
program a controller. The Boolean language uses Boolean algebra syntax (see Chapter 3)
to enter and explain the control logic.
It uses the AND, OR, and NOT logic functions to implement the control circuits in the
control program.
Grafcet
Grafcet (Graphe Fonctionnel de Commande Étape Transition) is a symbolic, graphic
language, which originated in France, that represents the control program as steps or
stages in the machine or process. In fact, the English translation of Grafcet means “step
transition function charts.”
Bit Level Instructions

• NO/NC and OUT


• SET and RESET Instructions
• Positive and Negative Edge
Bit Logic Instructions in LAD - NO
Normally Open Contact
Symbol
The Normally Open contact is
closed (ON) when the assigned
bit value I0.0 is TRUE or equal
to 1 and is Open (OFF) when
I0.0 is FALSE or equal to 0

Siemens TIA - Normally Open contact

I
Example in Series – AND Logic Example in Parallel- OR Logic
Bit Logic Instructions in FBD - NO
Normally Open Contact

The block “&” is TRUE when the assigned bit value I0.0 is TRUE or
equal to 1 and is FALSE when the assigned bit value I0.0 is FALSE or
equal to 0 .

Siemens TIA - Normally Open contact

Example in Series – AND Logic Example in Parallel- OR Logic


Bit Logic Instructions in LAD - NC
Normally Close Contact
Symbol
The Normally Close contact is
closed (ON) when the assigned
bit value I0.0 is FALSE or equal
to 0 and it’s open (OFF) when
the assigned bit value I0.0 is
TRUE or equal to 1
Siemens TIA - Normally close contact

I
Example in Series – NOR Logic Example in Parallel- NAND Logic
Bit Logic Instructions in FBD - NC
Normally Open Contact

The block “&” is TRUE when the assigned bit value I0.0 is FALSE or
equal to 0 and is FALSE when the assigned bit value I0.0 is TRUE of
equal to 1

Siemens TIA - Normally close contact

Example in Series – NOR Logic Example in Parallel- NAND Logic


Bit Logic Instructions in LAD & FBD- OUT
Output Coil
LAD symbol
The coil output instruction
writes a value for an
output bit. The OUT
FBD symlbol instruction is TRUE when
state before in the branch
is TRUE

Siemens TIA – Output Coil

Example in Series – AND Logic Truth Table

LAD

FBD
Exercise Example 1
Design XOR gate such that output is TRUE if only one
of the two inputs is TRUE. - Assume you have two
toggle buttons connected to PLC input

Ladder Solution

FBD Solution
Bit Logic Instructions in LAD – SET and RESET
SET Instruction

When S (Set) is activated, then the data value at the OUT


address is set to 1. When S is not activated, OUT is not
changed.
RESET Instruction
When R (Reset) is activated, then the data value at the
OUT address is set to 0. When R is not activated, OUT is
not changed.

Example
Exercise Example 2
Write a Logic to latch two outputs Q0.0 & Q0.1 with I0.0 and unlatch it using I0.1

Required Condition

Ladder Solution
Bit Logic Instructions – SET and RESET (Field)
SET Instruction (Field)

When SET_BF is activated, a data value of 1 is assigned to


"n“ bits starting at address tag OUT. When SET_BF is not
activated, OUT is not changed

RESET Instruction (Field)


RESET_BF writes a data value of 0 to "n" bits starting at
address tag OUT. When RESET_BF is not activated, OUT is
not changed.

Example
Exercise Example 3
Write a Logic to latch three outputs Q0.0 ~ Q0.2 with I0.0 and unlatch all using I0.1

Required Condition

Ladder Solution
Bit Logic Instructions – SET Dominant & RESET Dominant
SET/ Reset Flip Flop

SR is a reset dominant latch


where the reset dominates. If the
set (S) and reset (R1) signals are
both true, the value at address
Q0.0 will be 0

Reset/ SET Flip Flop

RS is a set dominant latch where


the set dominates. If the set (S1)
and reset (R) signals are both
true, the value at address Q0.0
will be 1.
Exercise Example 4
Write a Logic to latch the Motor Q0.0 with I0.0 (PB) and include two emergency switches
I0.2 and I0.3 to unlatch it. Which Flip Flop you will use?
Required Condition

FBD Solution
Bit Logic Instructions in LAD – Positive & Negative Edge
Positive Edge – SCAN Operand

The state of this contact is TRUE when a positive transition (OFF to-
ON) is detected on the assigned bit I0.0. The bit M0.0 will be ON for
1 clock cycle.

Negative Edge - SCAN Operand

The state of this contact is TRUE when a positive transition (ON to-
OFF) is detected on the assigned bit I0.1. The bit M0.1 will be ON
for 1 clock cycle.

The P & N contact can be located anywhere in the network except the end of a branch.
Exercise Example 5
Write a Logic to latch the motor when I0.0 goes from OFF to ON and unlatch the
motor when I0.1 goes from ON to OFF.

Ladder Solution

FBD Solution
Bit Logic Instructions in LAD – Positive & Negative Edge
P_TRIG - SCAN RLO

The Q output power flow or logic state is TRUE when a positive


transition (OFF-to-ON) is detected on the CLK power flow in (LAD).

N_TRIG - SCAN RLO


The Q output power flow or logic state is TRUE when a negative
transition (ON-to-OFF) is detected on the CLK power flow in (LAD).

P_TRIG Example N_TRIG Example

P_TRIG & N_TRIG instruction cannot be located at the beginning or end of a network.
Exercise Example 6
Write a Logic to latch the motor when either I0.0 or I0.1 goes from OFF to ON and
unlatch the motor when either I0.2 or I0.3 goes from ON to OFF.

Ladder Solution

FBD Solution
Timer Operations

• Pulse Timer (TP)


• On-Delay Timer (TON)
• Off-Delay Timer(TOF)
• Retentive ON Delay Timer
(TORN)
Timer Operations in LAD – TP (Generate Pulse)
Pulse Timer The TP timer generates a pulse with a preset
width time.

Example If Preset Time is 1000ms = 1 second

NOTE
• Changing PT has no effect
while the timer runs.
• Changing IN has no effect
while the timer runs.
Exercise Example
Write a Logic to generate continuous pulse output at Q0.0. Consider pulse time to be 1
second.
Exercise Example
Write a Logic to generate continuous pulse output at Q0.0 and Q0.1 with I0.0. Consider pulse
time to be 1 second.
Timer Operations in LAD – TON (On-Delay Timer)
On-Delay Timer The TON timer sets the output (Q) to ON after a
preset time delay.

Example If Preset Time is 3000ms = 3 second

NOTE
• Changing PT has no effect
while the timer runs.
• Changing IN to FALSE, while
the timer runs, resets and
stops the timer.
Exercise Example
Write a Logic to generate output at Q0.0, Q0.1 and Q0.2 in sequence with delay of 3 seconds
each.
Timer Operations in LAD – TOF (OFF Delay Timer)
OFF-Delay Timer The TOF timer sets the output (Q) to ON and
then resets the output to OFF after a preset time
delay.

Example If Preset Time is 3000ms = 3 second

NOTE
• Changing PT has no effect while the
timer runs.
• Changing IN to TRUE, while the
timer runs, resets and inits the
timer
Exercise Example
Write a logic to achieve the following objective:
• Start a Motor 1 (Q0.0) with I0.0 (0 - 1) and after 10s delay start a Motor 2 (Q0.1)
• Stop the Motor 1 (Q0.0) with I0.0 (1 – 0) and after 10s delay stop the Motor 2 (Q0.1)
Timer Operations in LAD – TOF (OFF Delay Timer)
Retentive The TONR timer sets the output (Q) to ON after a
ON Delay Timer preset time delay. The elapsed time is accumulated
over multiple timing periods until the reset (R)
input reset the elapsed time.

Example If Preset Time is 5000ms = 5 second


NOTE
• Changing PT has no effect while the
timer runs, but has an effect when the
timer resumes.
• Changing IN to FALSE, while the timer
runs, stops the timer but does not reset
the timer. Changing IN back to TRUE
will cause the timer to start timing from
the accumulated time value.
Exercise Example
Write a Logic to energize an output Q0.0 with retentive timer considering PT to be 10
seconds.
Timer Operations in LAD – Changing PT of TONR
Retentive The TONR timer sets the output (Q) to ON after a
ON Delay Timer preset time delay. The elapsed time is accumulated
over multiple timing periods until the reset (R)
input reset the elapsed time.
Exercise Example
Write a Logic to energize an output via retentive timer. Use the following elements:
• I0.0 to energize the output
• I0.1 to reset the ET
• I0.3 to change the PT to 5s
• I0.4 to change the PT to 10s
Counter Operations

• Count Down
• Count Up
• Count Up-Down
Counter Operations – CTD (Count Down)/CTU (Count Up)
Count Down The "count down" counter (CTD) counts down by 1 when the value of input
parameter CD changes from 0 to 1.

Count Up The "count up" counter (CTU) counts up by 1 when the value of the input
parameter CU changes from 0 to 1.

The number of counters that you can use in your user program is
limited only by the amount of memory in the CPU. Individual
counters use 3 bytes (for SInt or USInt), 6 bytes (for Int or UInt), or
12 bytes (for DInt or UDInt).
Counter Operations – CTUD (Count Up Down)
Count Up-Down The "count up and down" counter (CTUD) counts up or down by 1 on the
0 to 1 transition of the count up (CU) or count down (CD) inputs.
Math Operations

• Data types
• Various Math operations
Data Types (1) – S7 1200
Data Types The data type define the properties of the data, for example, the
representation of the contents and the valid memory areas.

the user program, you can use predefined data type or also data types that
you have defined.

Pre-defined Data Type


Data Types (2) – S7 1200
Pre-defined Data Type
Operands of the data type REAL have a length of 32 bits and are used to represent floating-
point numbers. An operand of the REAL data type consists of the following three components:

• Sign: The sign is determined by the signal state of bit 31. The bit 31 assume the value "0"
(positive) or "1" (negative).
• 8-bit exponents to basis 2: The exponent is increased by a constant (base, +127), so that it
has a value range of 0 to 255.
• 23-bit mantissa: Only the fraction part of the mantissa is shown. The integer part of the
mantissa is always 1.
Math Operations
ADDITION – for addition of two or more inputs
Status of OUT1 before addition Status of OUT1 after addition

SUBTRACT for subtraction of two inputs


Status of OUT1 before subtraction Status of OUT1 after subtraction
Math Operations
MULTIPLICATION- for multiplication of two or more inputs
Status of OUT1 before multiplication Status of OUT1 after multiplication

DIVISION for division of two inputs


Status of OUT1 before Division Status of OUT1 after Division
Math Operations
MOD – return remainder of division
CALCULATE – to calculate the pre-defined equation
INC/DEC – used to increment/decrement data by +1
GET MINIMUM/ MAXIMUM – compares the value
at the input and write the lowest/ highest value to
the output
SET LIMIT – limit the value at the input to the values
at MN and MX input.
Several other maths instruction
Math Operations

• MOV
• MOV_BLK
• FILL_BLK
• SWAP
Move Operations - MOVE
Move Instructions

The MOVE instruction copies a single data element from the source address specified by the
IN parameter to the destination addresses specified by the OUT parameter.

Example:
Copying the value from MW10 to MW12

Indicates that you can move the input to


multiple outputs
Move Operations - MOVE_BLK
Move Block Instruction

The MOVE_BLK instructions have an additional COUNT parameter. The COUNT specifies how
many data elements are copied. The number of bytes per element copied depends on the
data type assigned to the IN and OUT parameter tag names in the PLC tag table.

Example:
Copying the array element from source to destination

Output Array
Input Array
Count
Move Operations - MOVE_BLK
Fill Block Instruction

Use the "Fill block" instruction to fill a memory area (destination area) with the
value of the IN input. The destination area is filled beginning with the address
specified at the OUT output.

Example:
Copying the constant value (45) to Block_1 Array_1[2]
Move Operations - SWAP
SWAP Instruction

Use the "Swap" instruction to change the order of the bytes at input IN and query the result
at output OUT. The following figure shows how the bytes of an operand of the DWORD data
type are swapped using the "Swap" instruction.
Exercise Example
SWAP the values of MW0 and store it in MW10
Before Execution After Executio

Example: Make a ladder logic to continuously update the date from one block to another
block after every 10 seconds

You might also like