Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 7 of 27

SYSMAC C20P/C28P/C40P/C60P P-type Programmable Controllers Operation Manual: SECTION 4, pages 37 to 44

Pages 37 to 44 of 211, from SYSMAC C20P/C28P/C40P/C60P P-type Programmable Controllers Operation Manual

The original document is the PDF (2.2 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Omron C28P

Page 37

SECTION 4 Programming 4–1 4–2 4–3

4–4

4–5 4–6 4–7

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Instruction Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Ladder Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–3–1 Basic Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–3–2 Ladder Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–3–3 Logic Block Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–3–4 Branching Instruction Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–3–5 Jumps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Controlling Bit Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–4–1 OUT and OUT NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–4–2 Differentiate Up and Differentiate Down . . . . . . . . . . . . . . . . . . . . . . . 4–4–3 Keep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–4–4 Self-maintaining Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The End Instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Programming Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

30 30 30 31 32 33 34 39 40 40 41 41 42 42 43 44

29

Page 38

Section 4–3

The Ladder Diagram

4–1

Introduction This section explains the basic steps and concepts involved in programming and introduces the instructions used to build the basic structure of the ladder diagram and control its execution. The entire set of instructions used in programming is described in Section 5 Instruction Set. There are several basic steps involved in writing a program. 1, 2, 3... 1. Obtain a list of all I/O devices and the I/O points that have been assigned to them and prepare a table that shows the I/O bit allocated to each I/O device. 2. If the PC has any Units, i.e. Analog Timer Units, Host Link Units , and I/O Link Units that are allocated words in data areas other than the IR area or are allocated IR words in which the function of each bit is specified by the Unit, prepare similar tables to show what words are used for which Units and what function is served by each bit within the words. 3. Determine what words are available for work bits and prepare a table in which you can allocate these as you use them. 4. Also prepare tables of TC numbers so that you can allocate these as you use them. Remember, the function of a TC number can be defined only once within the program. (TC number are described in 5–11 Timer and Counter Instructions.) 5. Draw the ladder diagram. 6. Input the program into the CPU. When using the Programming Console, this will involve converting the program to mnemonic form. 7. Check the program for syntax errors and correct these. 8. Execute the program to check for execution errors and correct these. 9. After the entire Control System has been installed and is ready for use, execute the program and fine tune it if required. The basics of ladder diagramming are described in the rest of this section. Converting the program to mnemonic form and debugging are described in Section 7 Program Input, Debugging, and Execution. Section 8 Troubleshooting also provides information required for debugging.

4–2

Instruction Terminology There are basically two types of instructions used in ladder-diagram programming: instructions that correspond to conditions on the ladder diagram and are used in instruction form only when converting a program to mnemonic code and instructions that are used on the right side of the ladder diagram and are executed according to the conditions on the instruction lines leading to them. Most instructions have at least one or more operands associated with them. Operands indicate or provide the data on which an instruction is to be performed. These are sometimes input as the actual numeric values, but are usually the addresses of data area words or bits that contain the data to be used. For instance, a Move instruction that has IR 00 designated as the source operand will move the contents of IR 00 to some other location. The other location is also designated as an operand. A bit whose address is designated as an operand is called an operand bit; a word whose address is designated as an operand is called an operand word. Other terms used in describing instructions are introduced in Section 5 Instruction Set.

4–3

The Ladder Diagram A ladder diagram consists of one line running down the left side with lines branching off to the right. The line on the left is called the bus bar; the

30

Page 39

Section 4–3

The Ladder Diagram branching lines, instruction lines. Along the instruction lines are placed conditions that lead to other instructions on the right side. The logical combinations of these conditions determine when and how the instructions at the right are executed. A simple ladder diagram is shown below. 0000

0315

1208

HR 109

1203

1200

1201 Instruction

0001

0100

0501

0002

0003 HR 510

0007

0502

TC 01

0503

0515

0403

0504

0405 Instruction

0010

1001

1002

0011

1005

1007

As shown in the diagram above, instruction lines can branch apart and they can join back together. The vertical pairs of lines are called conditions. Conditions without diagonal lines through them are called normal conditions and correspond to a LOAD, AND, or OR instruction. The conditions with diagonal lines through them are called inverse or NOT conditions and correspond to a LOAD NOT, AND NOT, or OR NOT instruction. The number above each condition indicates the operand bit for the instruction. It is the status of the bit associated with each condition that determine the execution condition for following instructions. The function of each of the instructions that correspond to a condition is described below. Before we consider these, however, there are some basic terms that must be explained. Note When displaying ladder diagrams with a GPC, a FIT, or LSS, a second bus bar will be shown on the right side of the ladder diagram and will be connected to all instructions on the right side. This does not change the ladder-diagram program in any functional sense. No conditions can be placed between the instructions on the right side and the right bus bar, i.e., all instructions on the right must be connected directly to the right bus bar. Refer to the GPC, FIT, or LSS Operation Manual for details.

4–3–1

Basic Terms

Normal and NOT Conditions

Each condition in a ladder diagram is either ON or OFF depending on the status of the operand bit that has been assigned to it. A normal condition is ON if the operand bit is ON; OFF if the operand bit is OFF. An inverse or NOT condition is ON if the operand bit is OFF; OFF if the operand bit is ON. Generally speaking, you use a normal condition when you want something to happen when a bit is ON and an inverse condition when you want something to happen when a bit is OFF. 0000 Instruction

Instruction is executed when IR bit 0000 is ON.

Instruction

Instruction is executed when IR bit 0000 is OFF.

Normal condition 0000

NOT condition

Execution Conditions

In ladder diagram programming, the logical combination of ON and OFF conditions before an instruction determines the compound condition under which

31

Page 40

Section 4–3

The Ladder Diagram the instruction is executed. This condition, which is either ON or OFF, is called the execution condition for the instruction. All instructions except for LOAD instructions have execution conditions. Operand Bits

The operands designated for any of the ladder instructions can be any bit in the IR, SR, HR or TC area. This means that the conditions in a ladder diagram can be determined by I/O bits, flags, work bits, timers/counters, etc. Load and Output instructions can also use TR area bits, but they do so only in special applications. Refer to 4–3–4 Branching Instruction Lines for details.

Logic Blocks

What conditions correspond to what instructions is determined by the relationship between the conditions established by the instruction lines that connect them. Any group of conditions that go together to create a logic result is called a logic block. Although ladder diagrams can be written without actually analyzing individual logic blocks, understanding logic blocks is necessary for efficient programming and is essential when programs are to be input in mnemonic code. Analyzing logic blocks in ladder diagrams and converting ladder diagrams to mnemonic code is covered in 7–2 Converting to Mnemonic Code.

4–3–2

Ladder Instructions The ladder instructions are those that correspond to the conditions on the ladder diagram. Ladder instructions, either independently or in combination with the logic block instructions described next, form the execution conditions upon which all other instructions are executed.

Load and Load NOT

The first condition that starts any logic block within a ladder diagram corresponds to a Load or Load NOT instruction. 0000

A Load instruction. 0000

A Load NOT instruction.

When this is the only condition on the instruction line, the execution condition for the instruction at the right is ON when the condition is ON. For the Load instruction (i.e., a normal condition), the execution condition would be ON when IR 0000 was ON; for the Load NOT instruction (i.e., an inverse condition), it would be ON when IR 0000 was OFF. AND and AND NOT

When two or more conditions lie in series on the same instruction line, the first one corresponds to a Load or Load NOT instruction; the rest of the conditions, to AND or AND NOT instructions. The following example shows three conditions which correspond in order from the left to a Load, an AND NOT, and an AND instruction. 0000

0100

HR 000 Instruction

The instruction at the right would have an ON execution condition only when all three conditions are ON, i.e., when IR 0000 was ON, IR 0100 was OFF, and HR 000 was ON.

32

Page 41

Section 4–3

The Ladder Diagram

Actually, AND instructions can be considered individually in series, each of which would take the logical AND between the execution condition (i.e., the sum of all conditions up to that point) and the status of the AND instruction’s operand bit. If both of these were ON, an ON execution condition would be produced for the next instruction. The execution condition for the first AND instruction in a series would be the first condition on the instruction line. Each AND NOT instruction in a series would take the logical AND between its execution condition and the inverse of its operand bit. OR and OR NOT

When two or more conditions lie on separate instruction lines running in parallel and then joining together, the first condition corresponds to a Load or Load NOT instruction; the rest of the conditions correspond to OR or OR NOT instructions. The following example shows three conditions which correspond in order from the top to a Load NOT, an OR NOT, and an OR instruction. 0000 Instruction 0100

HR 000

The instruction at the right would have an ON execution condition when any one of the three conditions was ON, i.e., when IR 0000 was OFF, when IR 0100 was OFF, or when HR 000 was ON. OR and OR NOT instructions can also be considered individually, each taking the logical OR between its execution condition and the status of the OR instruction’s operand bit. If either one of these were ON, an ON execution condition would be produced for the next instruction. Combining AND and OR Instructions

When AND and OR instructions are combined in more complicated diagrams, they can sometimes be considered individually, with each instruction performing a logic operation on the execution condition and the status of the operand bit. The following is one example. 0000

0001

0002

0003 Instruction

0200

Here, an AND is taken between the status of 0000 and that of 0001 to determine the execution condition for an OR with the status of 0200. The result of this operation determines the execution condition for an AND with the status of 0002, which in turn determines the execution condition for an AND with the inverse of the status of 0003. In more complicated diagrams, however, it is necessary to consider logic blocks before an execution condition can be determined for the final instruction, and that’s where AND Load and OR Load instructions are used.

4–3–3

Logic Block Instructions Logic block instructions do not correspond to specific conditions on the ladder diagram; rather, they describe relationships between logic blocks. The

33

Page 42

Section 4–3

The Ladder Diagram

AND Load instruction logically ANDs the execution conditions produced by two logic blocks. The OR Load instruction logically ORs the execution conditions produced by two logic blocks. AND Load

Although simple in appearance, the diagram below requires an AND Load instruction. 0000

0002

0001

0003

Instruction

The two logic blocks are indicated by dotted lines. Studying this example shows that an ON execution condition would be produced when both 1) either of the conditions in the left logic block was ON (i.e., when either 0000 or 0001 was ON) and 2) either of the conditions in the right logic block was ON (i.e., when either 0002 was ON or 0003 was OFF). Analyzing the diagram in terms of instructions, the condition at 0000 would be a Load instruction and the condition below it would be an OR instruction between the status of 0000 and that of 0001. The condition at 0002 would be another Load instruction and the condition below this would be an OR NOT instruction, i.e., an OR between the status or 0002 and the inverse of the status of 0003. To arrive at the execution condition for the instruction at the right, the logical AND of the execution conditions resulting from these two blocks would have to be taken. AND Load allows us to do this. AND Load always takes an AND between the current execution condition and the last unused execution condition. An unused execution condition is produced by using the Load or Load NOT instruction for any but the first condition on an instruction line. OR Load

Although we’ll not describe it in detail, the following diagram would require an OR Load instruction between the top logic block and the bottom logic block. An ON execution condition would be produced for the instruction at the right either when 0000 was ON and 0001 was OFF or when 0002 and 0003 were both ON.

0000

0001 Instruction

0002

0003

Naturally, some diagrams will require both AND Load and OR Load instructions.

4–3–4

Branching Instruction Lines When an instruction line branches into two or more lines, it is sometimes necessary to use either interlocks or TR bits to maintain the execution condition that existed at a branching point. This is because instruction lines are executed across to a terminal instruction on the right before returning to branching points to execute instructions on the branch lines. If the execution condition has changed during this time, the previous execution condition is lost and proper execution will not be possible without some means of pre-

34

Page 43

Section 4–3

The Ladder Diagram serving the previous condition. The following diagrams illustrate this. In both diagrams, instruction 1 is executed before returning to the branching point and moving on to the branch line leading to instruction 2.

0000

Branching point Instruction 1 0002 Instruction 2

Diagram A: OK 0000

Branching point

0001 Instruction 1 0002 Instruction 2

Diagram B: Needs Correction

If, as shown in diagram A, the execution condition that existed at the branching point is not changed before returning to the branch line (instructions at the far right do not change the execution condition), then the branch line will be executed correctly and no special programming measure is required. If, as shown in diagram B, a condition exists between the branching point and the last instruction on the top instruction line, the execution condition at the branching point and the execution condition at the end of the top line will sometimes be different, making it impossible to ensure correct execution of the branch line. The system remembers only the current execution condition (i.e., the logical sum for an entire line) and does not remember partial logical sums at points within a line. There are two means of programming branching programs to preserve the execution conditions. One is to use TR bits; the other, to use interlocks. TR Bits

The TR area provides eight bits, TR 0 through TR 7, that can be used to temporarily preserve execution conditions. If a TR bit is used as the operand of the Output instruction placed at a branching point, the current execution condition will be stored at the designated TR bit. Storing execution conditions is a special application of the Output instruction. When returning to the branching point, the same TR bit is then used as the operand of the Load instruction to restore the execution condition that existed when the branching point was first reached in program execution. The above diagram B can be written as shown below to ensure correct execution.

TR 0 0000

0001 Instruction 1 0002 Instruction 2

Diagram B: Corrected Using a TR bit

In terms of actual instructions the above diagram would be as follows: The status of 0000 is loaded (a Load instruction) to establish the initial execution condition. This execution condition is then output using an Output instruction to TR 0 to store the execution condition at the branching point. The execution condition is then ANDed with the status of 0001 and instruction 1 is executed

35

Page 44

Section 4–3

The Ladder Diagram accordingly. The execution condition that was stored at the branching point is then loaded back in (a Load instruction with TR 0 as the operand) and instruction 2 is executed accordingly. The following example shows an application using two TR bits.

TR 0 0000

TR 1 0001

0002 Instruction 1 0003 Instruction 2

0004 Instruction 3 0005 Instruction 4

In this example, TR 0 and TR 1 are used to store the execution conditions at the branching points. After executing instruction 1, the execution condition stored in TR 1 is loaded for an AND with the status 0003. The execution condition stored in TR 0 is loaded twice, the first time for an AND with the status of 0004 and the second time for an AND with the inverse of the status of 0005. TR bits can be used as many times as required as long as the same TR bit is not used more than once in the same instruction block. Here, a new instruction block is begun each time execution returns to the bus bar. If more than eight branching points requiring that the execution condition be saved are necessary in a single instruction block, interlocks, which are described next, must be used. When drawing a ladder diagram, be careful not to use TR bits unless necessary. Often the number of instructions required for a program can be reduced and ease of understanding a program increased by redrawing a diagram that would otherwise required TR bits. With both of the following pairs of diagrams, the versions on the top require fewer instructions and do not require TR bits. The first example achieves this by merely reorganizing the parts of the instruction block; the second, by separating the second Output instruction and using another Load instruction to create the proper execution condition for it.

TR 0 0000

0001 Instruction 1

Instruction 2

0000 Instruction 2 0001 Instruction 1

36