Ladder Diagram
Ladder Diagram
Ladder Diagram
The Ladder Diagram (LD) programming language originated from the graphical representation used to design an electrical control system
Finally CPUs were added to take over the function of the logic circuits
I/O Devices wired to buffer transistors Control decisions accomplished through programming
CPU
Relay Logic representation (or LD) was developed to make program creation and maintenance easier
Computer based graphical representation of wiring diagrams that was easy to understand Reduced training and support cost
What is a Rung?
A rung of ladder diagram code can contain both input and output instructions
Input
instructions perform a comparison or test and set the rung state based on the outcome
Normally left justified on the rung
Output
instructions examine the rung state and execute some operation or function
In some cases output instructions can set the rung state Normally right justified on the rung
Input Instruction Output Instruction
Ladder Diagram input instructions perform logical AND and OR operations in and easy to understand format If all Input Instructions in series must all be true for outputs to execute (AND) If any input instruction in parallel is true, the outputs will execute (OR) Paralleling outputs allows multiple operations to occur based on the same input criteria A C D E
AND Branches
OR
Branch
S
K
-( )-
Sets a bit when the rung is true(1) and resets the bit when the rung is false (0) PLC5 calls this an OTE Output Enable
Negative
coil -( / )-
Sets a bit when the rung is false(0) and resets the bit when the rung is True(1) Not commonly supported because of potential for confusion
Set
Sets a bit (1) when the rung is true and does nothing when the rung is false Resets a bit (0) when the rung is true and does nothing when the rung is false
Reset
Contacts
the rung to the right of the instruction if the rung to the left is enabled and underlining bit is set (1) the rung to the right of the instruction if the rung to the left is enabled and underlining bit is reset (0)
the right side of the rung for one scan when the rung on left side of the instruction is true Allen Bradley PLC5 uses -[ONS]-
Definitions
Retentive
values or instructions maintain their last state during a power cycle Non-retentive values or instructions are reset to some default state (usually 0) after a power cycle
contradiction to this is ladder diagram where 3 instructions are classified as retentive In most PLCs only timer and coil instructions operate as non-retentive
Retentive Coils
coil -(M)-
Sets a bit when the rung is true(1) and resets the bit when the rung is false (0)
Set
Sets a bit (1) when the rung is true and does nothing when the rung is false PLC5 uses OTL Output Latch
Reset
Resets a bit (0) when the rung is true and does nothing when the rung is false PLC5 uses OUT Output Unlatch
the bit bit (1) when rung to the left of the instruction transitions from off(0) to on(1) The bit is left in this state PLC5 use OSR (One Shot Rising)
the bit (0) when rung to the left of the instruction transitions from on(1) to off(0) The bit is left in this state PLC5 uses OSF (One Shot Falling)
If the rung input (EN) is enabled, the instruction performs the operation and sets the rung output (ENO) based on the comparison
Example:
when EN is true, EQ (=) function compares In1 and to In2 and sets ENO GT (>), GE (>=), LT (<), LE (<=), NE (<>)
EQ EN Tank1_Level IN1 100.000 Tank_max IN2 78.251 ENO
TP - Pulse timer TON - Timer On Delay TOF - Timer Off Delay Time base is 1msec (1/1000 of a sec) Values entered using duration literal format
T#200ms
Pump_Tmr TON IN Q
Time values
PT
ET
178
Pump_Tmr
TON IN ENO Q T#200ms Pump_Tmr_DN
1st method requires extra programming if timer done status needs to be referenced on other rungs 2nd method sets a bit with Q which can be referenced by other logic, ENO=EN
PT
ET
178
Timer Operation
Pulse (TP) Timing IN Q
ET
PT | 0
CTU - Count Up Counter CTD - Count Down Counter CTUD - Count Up/Down Counter
178
All three count rung transitions Two possible visualizations Depending on use of EN/ENO
1st method requires extra programming if timer done status needs to be referenced on other rungs 2nd method sets a bit with Q which can be referenced by other logic, ENO=EN
Counter Operation
IN Q
PV | CV 0
...
...
Parameters
CU/CD = Count up/Down Q/QU/QD = Comparison Output R = Reset to Zero LD = Load CV with PV PV = Preset Value CV = Count Value
...
...
LD
CU QU CD
QD
PV
... ...
| CV 0
R LD
Jump to a label skips a block of code without it being scanned LBL - Named target for a jump operation JMP - Performs a jump when the rung conditions are true
Used to encapsulate logic and call it as a subroutine Causes execution to change between functions or subroutines CAL - Passes control to another named function
RET - Exits a function and returns control back to the calling routine
The look and feel of IEC 1131-3 is somewhat different from the 1Million+ PLCs that Allen Bradley has running in factories throughout the world
ADD Source A Tank1_In TON Timer Pump_Tmr (EN)
Source B
Destination
100.000 Offsetr
78.251 Tank_Level 178.251
Preset
Accum
200.000
178.251
(DN)
Pump_Tmr TON
EN Tank1_In 100.000
IN
ENO
Q PT ET
Pump_Tmr_DN
Offsetr 78.251
178
IEC places the input parameters on the outside of the instruction block vs the PLC5 where they are presented inside of the block
IEC1131-3 Provides a very basic set of instructions to do simple operations (81 Ladder Diagram Instructions)
Data Type Conversion - Trunc, Int_to_Sint, Dint_to_Real, Bcd_To_Int Boolean Operations - Bit Test, Bit Set, One Shot, Semaphores Timers / Counters - Ton, Tp, Ctu, Ctd, Ctud Simple Math - Add, Sub, Mul, Div, Mod, Move, Expt Misc. Math - Abs, Sqrt, Ln, Log, Exp, Sin, Cos, Tan, Asin, Acos, Atan Bit Shift - Shl, Shr, Ror, Rol Logic - And, Or, Xor, Not Selection - Sel, Max, Min, Limit, Mux Compare - GT, GE, EQ, LE, LT, NE String - Len, Left, Right, Mid, Concat, Insert, Delete, Replace, Find Control - JMP, LBL, JSR, RET File Operations, PID, Diagnostic, For/Nxt Loop, Search, Sort are not in IEC1131-3 Extensions to the instruction set are permitted so that vendors can add instructions that their customers need All vendors have defined their own set of extensions Rockwell Automation controllers have significantly more capability with over 130 Ladder Instructions
=
11 Rungs of Logic 17 Instructions Hours to code and debug 1 Rung of Logic 1 Instruction Minutes to code and debug
FIFO & LIFO - FFL, FFU, LFL, LFU File math and search - FAL, FSC Table operations - SRT, STD, AVE Sequencers - SQI, SQL, SQO, SDS Diagnostics - DDT, DFA, FBC Compare - CMP, MEQ Compute - CPT, NEG Data moves - MVM, COP, BTD Program Control - AFI, NOP, MCR, TND Interrupt Services - UID, UIE Retentive Timer - RTO Ladder Loop Instruction - FOR, NXT Process - PID Motion - 30+ instructions to perform closed loop servo control