- •16. ADVANCED LADDER LOGIC FUNCTIONS
- •16.1 INTRODUCTION
- •16.2 LIST FUNCTIONS
- •16.2.1 Shift Registers
- •16.2.2 Stacks
- •16.2.3 Sequencers
- •16.3 PROGRAM CONTROL
- •16.3.1 Branching and Looping
- •16.3.2 Fault Detection and Interrupts
- •16.4 INPUT AND OUTPUT FUNCTIONS
- •16.4.1 Immediate I/O Instructions
- •16.4.2 Block Transfer Functions
- •16.5 DESIGN TECHNIQUES
- •16.5.1 State Diagrams
- •16.6 DESIGN CASES
- •16.6.1 If-Then
- •16.6.2 Traffic Light
- •16.7 SUMMARY
- •16.8 PRACTICE PROBLEMS
- •16.9 PRACTICE PROBLEM SOLUTIONS
- •16.10 ASSIGNMENT PROBLEMS
- •17. OPEN CONTROLLERS
- •17.1 INTRODUCTION
- •17.3 OPEN ARCHITECTURE CONTROLLERS
- •17.4 SUMMARY
- •17.5 PRACTICE PROBLEMS
- •17.6 PRACTICE PROBLEM SOLUTIONS
- •17.7 ASSIGNMENT PROBLEMS
- •18. INSTRUCTION LIST PROGRAMMING
- •18.1 INTRODUCTION
- •18.2 THE IEC 61131 VERSION
- •18.3 THE ALLEN-BRADLEY VERSION
- •18.4 SUMMARY
- •18.5 PRACTICE PROBLEMS
- •18.6 PRACTICE PROBLEM SOLUTIONS
- •18.7 ASSIGNMENT PROBLEMS
- •19. STRUCTURED TEXT PROGRAMMING
- •19.1 INTRODUCTION
- •19.2 THE LANGUAGE
- •19.3 SUMMARY
- •19.4 PRACTICE PROBLEMS
- •19.5 PRACTICE PROBLEM SOLUTIONS
- •19.6 ASSIGNMENT PROBLEMS
- •20. SEQUENTIAL FUNCTION CHARTS
- •20.1 INTRODUCTION
- •20.2 A COMPARISON OF METHODS
- •20.3 SUMMARY
- •20.4 PRACTICE PROBLEMS
- •20.5 PRACTICE PROBLEM SOLUTIONS
- •20.6 ASSIGNMENT PROBLEMS
- •21. FUNCTION BLOCK PROGRAMMING
- •21.1 INTRODUCTION
- •21.2 CREATING FUNCTION BLOCKS
- •21.3 DESIGN CASE
- •21.4 SUMMARY
- •21.5 PRACTICE PROBLEMS
- •21.6 PRACTICE PROBLEM SOLUTIONS
- •21.7 ASSIGNMENT PROBLEMS
- •22. ANALOG INPUTS AND OUTPUTS
- •22.1 INTRODUCTION
- •22.2 ANALOG INPUTS
- •22.2.1 Analog Inputs With a PLC
- •22.3 ANALOG OUTPUTS
- •22.3.1 Analog Outputs With A PLC
- •22.3.2 Pulse Width Modulation (PWM) Outputs
- •22.3.3 Shielding
- •22.4 DESIGN CASES
- •22.4.1 Process Monitor
- •22.5 SUMMARY
- •22.6 PRACTICE PROBLEMS
- •22.7 PRACTICE PROBLEM SOLUTIONS
- •22.8 ASSIGNMENT PROBLEMS
- •23. CONTINUOUS SENSORS
- •23.1 INTRODUCTION
- •23.2 INDUSTRIAL SENSORS
- •23.2.1 Angular Displacement
- •23.2.1.1 - Potentiometers
- •23.2.2 Encoders
- •23.2.2.1 - Tachometers
- •23.2.3 Linear Position
- •23.2.3.1 - Potentiometers
- •23.2.3.2 - Linear Variable Differential Transformers (LVDT)
- •23.2.3.3 - Moire Fringes
- •23.2.3.4 - Accelerometers
- •23.2.4 Forces and Moments
- •23.2.4.1 - Strain Gages
- •23.2.4.2 - Piezoelectric
- •23.2.5 Liquids and Gases
- •23.2.5.1 - Pressure
- •23.2.5.2 - Venturi Valves
- •23.2.5.3 - Coriolis Flow Meter
- •23.2.5.4 - Magnetic Flow Meter
- •23.2.5.5 - Ultrasonic Flow Meter
- •23.2.5.6 - Vortex Flow Meter
- •23.2.5.7 - Positive Displacement Meters
- •23.2.5.8 - Pitot Tubes
- •23.2.6 Temperature
- •23.2.6.1 - Resistive Temperature Detectors (RTDs)
- •23.2.6.2 - Thermocouples
- •23.2.6.3 - Thermistors
- •23.2.6.4 - Other Sensors
- •23.2.7 Light
- •23.2.7.1 - Light Dependant Resistors (LDR)
- •23.2.8 Chemical
- •23.2.8.2 - Conductivity
- •23.2.9 Others
- •23.3 INPUT ISSUES
- •23.4 SENSOR GLOSSARY
- •23.5 SUMMARY
- •23.6 REFERENCES
- •23.7 PRACTICE PROBLEMS
- •23.8 PRACTICE PROBLEM SOLUTIONS
- •23.9 ASSIGNMENT PROBLEMS
- •24. CONTINUOUS ACTUATORS
- •24.1 INTRODUCTION
- •24.2 ELECTRIC MOTORS
- •24.2.1 Basic Brushed DC Motors
- •24.2.2 AC Motors
- •24.2.3 Brushless DC Motors
- •24.2.4 Stepper Motors
- •24.2.5 Wound Field Motors
plc il - 18.1
18. INSTRUCTION LIST PROGRAMMING
Topics:
•Instruction list (IL) opcodes and operations
•Converting from ladder logic to IL
•Stack oriented instruction delay
•The Allen Bradley version of IL
Objectives:
•To learn the fundamentals of IL programming.
•To understand the relationship between ladder logic and IL programs
18.1INTRODUCTION
Instruction list (IL) programming is defined as part of the IEC 61131 standard. It uses very simple instructions similar to the original mnemonic programming languages developed for PLCs. (Note: some readers will recognize the similarity to assembly language programming.) It is the most fundamental level of programming language - all other programming languages can be converted to IL programs. Most programmers do not use IL programming on a daily basis, unless they are using hand held programmers.
18.2 THE IEC 61131 VERSION
To ease understanding, this chapter will focus on the process of converting ladder logic to IL programs. A simple example is shown in Figure 18.1 using the definitions found in the IEC standard. The rung of ladder logic contains four inputs, and one output. It can be expressed in a Boolean equation using parentheses. The equation can then be directly converted to instructions. The beginning of the program begins at the START: label. At this point the first value is loaded, and the rest of the expression is broken up into small segments. The only significant change is that AND NOT becomes ANDN.
plc il - 18.2
|
I:000/00 |
I:000/01 |
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
O:001/00 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I:000/02 |
I:000/03 |
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
read as O:001/00 = I:000/00 AND ( I:000/01 OR ( I:000/02 AND NOT I:000/03) )
Label |
Opcode |
Operand |
Comment |
|
|
|
|
START: |
LD |
%I:000/00 |
(* Load input bit 00 *) |
|
AND( |
%I:000/01 |
(* Start a branch and load input bit 01 *) |
|
OR( |
%I:000/02 |
(* Load input bit 02 *) |
|
ANDN |
%I:000/03 |
(* Load input bit 03 and invert *) |
|
) |
|
|
|
) |
|
|
|
ST |
%O:001/00 |
(* SET the output bit 00 *) |
|
|
|
|
Figure 18.1 An Instruction List Example
An important concept in this programming language is the stack. (Note: if you use a calculator with RPN you are already familiar with this.) You can think of it as a do later list. With the equation in Figure 18.1 the first term in the expression is LD I:000/00, but the first calculation should be ( I:000/02 AND NOT I:000/03). The instruction values are pushed on the stack until the most deeply nested term is found. Figure 18.2 illustrates how the expression is pushed on the stack. The LD instruction pushes the first value on the stack. The next instruction is an AND, but it is followed by a ’(’ so the stack must drop down. The OR( that follows also has the same effect. The ANDN instruction does not need to wait, so the calculation is done immediately and a result_1 remains. The next two ’)’ instructions remove the blocking ’(’ instruction from the stack, and allow the remaining OR I:000/1 and AND I:000/0 instructions to be done. The final result should be a single bit result_3. Two examples follow given different input conditions. If the final result in the stack is 0, then the output ST O:001/0 will set the output, otherwise it will turn it off.
plc il - 18.3
LD I:000/0 |
AND( I:000/1 |
OR( I:000/2 |
ANDN I:000/3 |
) |
) |
I:000/0 |
I:000/1 |
I:000/2 |
result_1 |
result_2 |
result_3 |
|
( |
( |
( |
( |
|
|
AND I:000/0 |
OR I:000/1 |
OR I:000/1 |
AND I:000/0 |
|
|
|
( |
( |
|
|
|
|
AND I:000/0 |
AND I:000/0 |
|
|
|
|
|
|
|
|
Given: |
|
|
|
|
|
|
I:000/0 = 1 1 |
0 |
1 |
1 |
1 |
1 |
1 |
I:000/1 = 0 |
( |
( |
( |
( |
AND 1 |
|
I:000/2 = 1 |
AND 1 |
OR 0 |
OR 0 |
AND 1 |
|
|
I:000/3 = 0 |
|
( |
( |
|
|
|
|
|
AND 1 |
AND 1 |
|
|
|
Given: |
|
|
|
|
|
|
I:000/0 = 0 0 |
1 |
0 |
0 |
0 |
0 |
0 |
I:000/1 = 1 |
( |
( |
( |
( |
AND 1 |
|
I:000/2 = 0 |
AND 0 |
OR 1 |
OR 1 |
AND 1 |
|
|
I:000/3 = 1 |
|
( |
( |
|
|
|
|
|
AND 0 |
AND 0 |
|
|
|
Figure 18.2 Using a Stack for Instruction Lists
A list of operations is given in Figure 18.3. The modifiers are;
N - negates an input or output
( - nests an operation and puts it on a stack to be pulled off by ’)’
C - forces a check for the currently evaluated results at the top of the stack
These operators can use multiple data types, as indicated in the data types column. This list should be supported by all vendors, but additional functions can be called using the CAL function.
plc il - 18.4
Operator |
Modifiers |
Data Types |
Description |
|
|
|
|
LD |
N |
many |
set current result to value |
ST |
N |
many |
store current result to location |
S, R |
|
BOOL |
set or reset a value (latches or flip-flops) |
AND, & |
N, ( |
BOOL |
boolean and |
OR |
N, ( |
BOOL |
boolean or |
XOR |
N, ( |
BOOL |
boolean exclusive or |
ADD |
( |
many |
mathematical add |
SUB |
( |
many |
mathematical subtraction |
MUL |
( |
many |
mathematical multiplication |
DIV |
( |
many |
mathematical division |
GT |
( |
many |
comparison greater than > |
GE |
( |
many |
comparison greater than or equal >= |
EQ |
( |
many |
comparison equals = |
NE |
( |
many |
comparison not equal <> |
LE |
( |
many |
comparison less than or equals <= |
LT |
( |
many |
comparison less than < |
JMP |
C, N |
LABEL |
jump to LABEL |
CAL |
C, N |
NAME |
call subroutine NAME |
RET |
C, N |
|
return from subroutine call |
) |
|
|
get value from stack |
|
|
|
|
Figure 18.3 IL Operations
18.3 THE ALLEN-BRADLEY VERSION
Allen Bradley only supports IL programming on the Micrologix 1000, and does not plan to support it in the future. Examples of the equivalent ladder logic and IL programs are shown in Figure 18.4 and Figure 18.5. The programs in Figure 18.4 show different variations when there is only a single output. Multiple IL programs are given where available. When looking at these examples recall the stack concept. When a LD or LDN instruction is encountered it will put a value on the top of the stack. The ANB and ORB instructions will remove the top two values from the stack, and replace them with a single value that is the result of an Boolean operation. The AND and OR functions take one value off the top of the stack, perform a Boolean operation and put the result on the top of the stack. The equivalent programs (to the right) are shorter and will run faster.
plc il - 18.5
|
Ladder |
|
|
|
|
|
|
|
Instruction List (IL) |
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A |
|
|
|
|
|
|
X |
LD A |
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
ST X |
|
|
|
|
A |
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
X |
LDN A |
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
ST X |
|
|
|
|
A |
|
B |
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
X |
LD A |
LD A |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
LD B |
AND B |
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
ANB |
ST X |
|
|
|
|
|
|
|
|
|
|
|
|
|
ST X |
|
|
|
|
A |
|
B |
|
|
|
|
X |
LD A |
LD A |
||
|
|
|
|
|
|
|
|
|
|
|
|
|
LDN B |
ANDN B |
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
ANB |
ST X |
|
|
|
|
|
|
|
|
|
|
|
|
|
ST X |
|
|
|
|
A |
|
|
|
|
C |
X |
LD A |
LD A |
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
LD B |
OR B |
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
B |
|
|
|
|
|
|
|
ORB |
AND C |
||
|
|
|
|
|
|
|
|
|
|
LD C |
ST X |
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
ANB |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST X |
|
|
|
|
A |
|
|
B |
X |
LD A |
LD A |
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
LD B |
LD B |
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
C |
|
|
LD C |
OR C |
||
|
|
|
|
|
|
|
|
|
|
ORB |
ANB |
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
ANB |
ST X |
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
ST X |
|
|
|
|
A |
|
|
C |
X |
LD A |
LD A |
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
LD B |
OR B |
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
B |
|
|
|
|
D |
|
|
ORB |
LD C |
||
|
|
|
|
|
|
|
|
|
|
|
|
|
LD C |
OR D |
|
|
|
|
|
|
|
|
|
|
|
|
|
LD D |
ANB |
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
ORB |
ST X |
|
|
|
|
|
|
|
|
|
|
|
|
|
ANB |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ST X |
|
Figure 18.4 IL Equivalents for Ladder Logic
Figure 18.5 shows the IL programs that are generated when there are multiple outputs. This often requires that the stack be used to preserve values that would be lost nor-
plc il - 18.6
mally using the MPS, MPP and MRD functions. The MPS instruction will store the current value of the top of the stack. Consider the first example with two outputs, the value of A is loaded on the stack with LD A. The instruction ST X examines the top of the stack, but does not remove the value, so it is still available for ST Y. In the third example the value of the top of the stack would not be correct when the second output rung was examined. So, when the output branch occurs the value at the top of the stack is copied using MPS, and pushed on the top of the stack. The copy is then ANDed with B and used to set X. After this the value at the top is pulled off with the MPP instruction, leaving the value at the top what is was before the first output rung. The last example shows multiple output rungs. Before the first rung the value is copied on the stack using MPS. Before the last rung the value at the top of the stack is discarded with the MPP instruction. But, the two center instructions use MRD to copy the right value to the top of the stack - it could be replaced with MPP then MPS.
plc il - 18.7
|
Ladder |
|
|
|
Instruction List (IL) |
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A |
|
|
X |
LD A |
|
||
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Y |
ST X |
|
|
|
|
|
|
|
|
|
|
||
|
|
|
A |
|
|
ST Y |
|
|||
|
|
|
|
|
X |
LD A |
LD A |
|||
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
ST X |
ST X |
|
|
|
|
|
|
|
B |
|
||
|
|
|
|
|
|
|
Y |
LD B |
AND B |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
ANB |
ST Y |
|
|
|
|
|
|
|
|
|
ST Y |
|
|
|
|
A |
B |
X |
LD A |
LD A |
|||
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
MPS |
MPS |
|
|
|
|
|
|
|
C |
|
||
|
|
|
|
|
|
|
Y |
LD B |
AND B |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
ANB |
ST X |
|
|
|
|
|
|
|
|
|
ST X |
MPP |
|
|
|
|
|
|
|
|
|
MPP |
AND C |
|
|
|
|
|
|
|
|
|
LD C |
ST Y |
|
|
|
|
|
|
|
|
|
ANB |
|
|
|
|
|
|
|
|
|
|
ST Y |
|
|
|
|
A |
B |
W |
LD A |
LD A |
|||
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
MPS |
MPS |
|
|
|
|
|
|
|
C |
|
||
|
|
|
|
|
|
|
X |
LD B |
AND B |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
ANB |
ST W |
|
|
|
|
|
|
|
|
Y |
ST W |
MRD |
|
|
|
|
|
|
|
E |
|
MRD |
AND C |
|
|
|
|
|
|
|
Z |
LD C |
ST X |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
ANB |
MRD |
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
ST X |
ST Y |
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
MRD |
MPP |
|
|
|
|
|
|
|
|
|
STY |
AND E |
|
|
|
|
|
|
|
|
|
MPP |
ST Z |
|
|
|
|
|
|
|
|
|
LD E |
|
ANB
ST Z
Figure 18.5 IL Programs for Multiple Outputs
Complex instructions can be represented in IL, as shown in Figure 18.6. Here the function are listed by their mnemonics, and this is followed by the arguments for the functions. The second line does not have any input contacts, so the stack is loaded with a true
plc il - 18.8
value.
I:001/0
TON
Timer T4:0
Delay 5s
ADD
SourceA 3
SourceB T4:0.ACC
Dest N7:0
START:LD I:001/0
TON(T4:0, 1.0, 5, 0)
LD 1
ADD (3, T4:0.ACC, N7:0)
END
Figure 18.6 A Complex Ladder Rung and Equivalent IL
An example of an instruction language subroutine is shown in Figure 18.7. This program will examine a BCD input on card I:000, and if it becomes higher than 100 then 2 seconds later output O:001/00 will turn on.