il



18. INSTRUCTION LIST PROGRAMMING

 

18.1 INTRODUCTION

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 254 An Instruction List Example 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.

 

Figure 254 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 254 An Instruction List Example 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 255 Using a Stack for Instruction Lists 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.

 

Figure 255 Using a Stack for Instruction Lists

A list of operations is given in Figure 256 IL Operations. 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.

 

Figure 256 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 257 IL Equivalents for Ladder Logic and Figure 258 IL Programs for Multiple Outputs. The programs in Figure 257 IL Equivalents for Ladder Logic 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.

 

Figure 257 IL Equivalents for Ladder Logic

Figure 258 IL Programs for Multiple Outputs 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 normally 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.

 

Figure 258 IL Programs for Multiple Outputs

Complex instructions can be represented in IL, as shown in Figure 259 A Complex Ladder Rung and Equivalent IL. 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 value.

 

Figure 259 A Complex Ladder Rung and Equivalent IL

An example of an instruction language subroutine is shown in Figure 260 An Example of an IL Program. 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.

 

Figure 260 An Example of an IL Program

18.4 SUMMARY

· Ladder logic can be converted to IL programs, but IL programs cannot always be converted to ladder logic.

· IL programs use a stack to delay operations indicated by parentheses.

· The Allen Bradley version is similar, but not identical to the IEC 61131 version of IL.

18.5 PRACTICE PROBLEMS

(Note: Problem solutions are available at http://sites.google.com/site/automatedmanufacturingsystems/)

18.6 ASSIGNMENT PROBLEMS

1. Explain the operation of the stack.

2. Convert the following ladder logic to IL programs.

3. Write the ladder diagram programs that correspond to the following Boolean programs.

 

Site Links


Engineer On A Disk Main Page

- PLC Book Book Page