指令表毕业论文外文翻译.doc
外文翻译第 6章指令表、顺序结构图和结构 文本的程序设计方法 本章继续接着上一章讨论另外几种标准编程语言,例如,指令表(IL)、顺序结构图(SFC)和结构文本(ST)。 6.1指令表 指令表是一种采用文本形式进行梯形图程序设计的编程方法。指令表的程序由一系列的指令组成,每条指令占一行。程序指令由操作码及的一个至多个操作数组成,执行对象是操作码。梯形图中操作码被看作梯形图的构元素。每条指令都可以使用或更改存在记忆寄存器中的信息。为此,使用了助记符代码,每个代码对应一个操作码梯形图元素。尽管标准 IEC 1131-3 已经被提出并广泛使用,但是不同制造商使用的指令一定程度上并不一样。表6.1 给出一些厂家所使用的指令,及本章所提议的标准指令(后面章节将讲述指令的其他功能。) 下面给出使用IEC 113-1 标准操作码的例子: LD A(*加载A*) AND B (*与B*) ST Q (*存储结果Q,输出Q*) 在程序的第一行,LD 是操作码,A 是操作数,在程序末尾括号中*之间的内容是评论,解释这行指令的作用,它是 PLC 指令的一部分。LD A 这条指令表示将A 加载至寄存器中在之后的操作中可以调用它。第二行是 A 与B 的布尔运算中的与操作。最后一行是将结果存储在 Q 中,即向Q 输出。 标号可以用来标识不同的进入程序的入口,在程序跳转时十分有用。标号在指令的前面被冒号分隔开。因此有: PUMP_OK : LD C (*加载C*) 在程序之前面有一条指令,如果某个特殊的条件满足,那么程序就跳转执行PUMP_OK。 采用IEC 113-1 标准的操作码,在值后面加上字符N 表示取反。例如: LD A (*加载A*) ANDN B (*AND NOT B*) 其中,ANDN 操作把梯形图触点先“与”后“取反”。 6.1.1梯形图程序设计及指令表 下面看看梯形图的条件,当一个梯级开始工作,必须要使用一个“开始梯级代码' 它以是LD 或L,用于指示梯级以常开触点开始。或者是LDI、LDN、LD NOT、AN 或 LN,用来指示梯级以常闭触点开始。所有梯级必须以一个输出或存储结果的编码结束。它可以是 OUT、=或 ST。下图描述了一个梯形图中各独立梯级是如何输入的,其中与门使用三菱的记忆,如图6.1a 所示。 此梯形图以操作码LD开始,因为它开始于常开触点。由于输入地址是X400,所以加载指令为 LDX400,其后还有一个常开触点作为输入,所以下一行程序指令用AND 指令对元件地址逻辑与操作,相应语句为:AND X401。因为,这个梯级要以输出终止,所以用输出指令 OUT 产生输出,即 OUT Y430。因此,梯形图的单个梯级可以用程序指 令描述为: LD X400 AND X401 OUT Y430 同样的功能,采用西门子符号,如图 6.1b 所示。 A I0.1 A I0.2 = Q2.0 再看另一个与门的例子,如图 6.2a 所示,采用的是三菱的符号。 梯形图以常开触点开始,指令为LD X400, 与X401并联,因此下一条指令为OR X401。最后一条是输出,所以输出为 OUT Y430。指令表如下: LD X400 OR X401 OUT Y430 如图6.2b 所示的是西门子符号的或门,指令表如下: A I0.1 O I0.2 = Q2.0 字母 I 用来表示对这条指令的取反。紧接着串联一个常闭触点,其指令为 ANI,I 再次表示对这条与指令的取反,当然 I 也是一个非门的指令。所梯形图中或非门的指令可以写成: LDI X400 ANI X401 OUT Y430 图 6.3b 是西门子的或非门符号。注意指令后面的字母 N 的作用是取反。指令表如下: LN I0.1 AN I0.2 = Q2.0 图6.4a 为三菱符号表示的与非门。 梯形图以常触点 X400 开始,指令语句为 LDI X400。下一条对应于一个并联的常闭触点,其指令为 OR1 X401。最后一步是输出,指令为 OUT Y430。因此,指令表如下: LDI X400 ORI X401 OUT Y430 图6.4b 为采用西门子符号的异或门。指令表如下: AN I0.1 ON I0.2 = Y430 6.1.2分支代码 如图 6.5a 所示的采用三菱符号的异或门,它有两条并联的分支,每条分支分别由与关系构成 图中三菱公司使用ORB 指令来表示或和并联分支的关系。第一条指令对应一个常开触点X400。下一条指令对应与之串联的常闭触点 X401,指令为ANI X401。在读取前两条指令之后,第三条指令开始于新的一行。另起一行是因为它开始于指令 LDI,所有新的一行指令语句都是以 LD 或 LDI 开始。但是第一行不能以输出结束,所以PLC 把与其并联的那行包含在第二行,这样读取以上所列内容直到ORB 指令。助记码 ORB(分支或模块间的或运算)用于将前两行及第三、四行的指令执行结果进行逻辑或运算。指令表以输出 OUT Y430 终止。指令表如下: LD X400 ANI X401 LDI X400 AND X401 ORB OUT Y430 图 6.5b 是西门子的异或门。括弧用来表示将特殊指令结合在一起作为一个区块执行。 这种用法和数学方程中的括弧用法相同。例如,(2+3)/4表示2 和3相加的结果再除以 4。 因此,西门子指令表中从第 0 步的指令 A 开始,括弧到第三步结束,表示第 0 步的A 只能允许在第一步和第二步指令执行结束后才能够执行。 IEC 1131-3 标准应用于此段程序就是使用上述西门子例子中的括弧来实现的。 图 6.6a 的电路图,采用三菱符号,可看成是两个分支模进行与操作。所采用的指令是ANB。指令表如下: 图 6.6b 是用西门子符号来表示的同一个电路。本程序中的指令表使用了括弧。第0 步的指令A 应用到第1、2 步的结果中。第4 步中的指令A 应用到第5、6 步的结果中。所以程序的指令表如下: 6.1.3多个梯级 图 6.7a 是用三菱符号表示的梯形图,它有两层梯级。在编写指令表时,按顺序写出每行的指令。指令 LD 或LDI 表示PLC 新的一层梯级开始。指令表如下: LD X400 OUT Y430 LDI X400 OUT Y431 此系统表明,当X400 没有被触发时,Y431 有输出,Y430 没有输出。当 X400被触发时,Y430 有输 出,Y431 没有输出。 图 6.7b 用西门子符号描述了同样的程序。=指令表示一行结束。A 或 AN 指令可以表示一层梯级的开始。但不是必需的,因为还可以用 AND 和AND NOT 表示该指令。则指令表如下: A I0.0 = Q2.0 AN I0.0 = Q2.1 6.1.4程序举例 下面介绍本节所述程序设计方法的具体应用,以 5.7 节的梯形图和功能块为例。对照5.7 节中梯形图的解释,在此只讲述和程序相关的指令表。 如果水泵在运行状态,且满足一定压力条件或指示灯开关闭合,那么信号灯亮。图6.8 给出了梯形图和相关的指令表。 对于一个用来提升负载的阀,当泵在运行并且提升开关闭合或有开关指示负载在底部提升槽中而没有被提升,那么阀工作。图 6.9 是其梯形图及与之对应的指令表 当四个传感器中的任意一个有输出时,系统都没有输出产生,否则有输出产生,图6.10 给出了梯形图程序及与之对应的指令表。 6.2 顺序功能图 如果想描述一个交通灯序列。一种方法就是把它看成是一系列的功能或状态,例如红灯 状态、绿灯状态,然后考虑每个状态的输人和输出。 如图 6.11 就是对此的描述。状态 0 的输人在绿灯持续亮一分钟后触发,然后以红灯亮 作为输出。状态 I 的输人在红灯持续亮一分钟后触发,然后以绿灯亮作为输出。 顺序功能图是一种系统操作的图形表示,它描述了一系列操作中的事件顺序。顺序功能图遵循以下规则: 1.这种操作用互相独立、相继连接的状态或动作来描述,用矩形方框来表示状态,每 个方框代表被控系统的某个状态。程序的初始化动作与其他动作的表示方法有所不同。图 6.12 给出了它的表示法。 2.在两个状态之间的连接线上有一条水平的短线,表示系统从一个状态到下一个状态 需要满足的转换条件。两个动作之间不能直接连接,它们中间必须加转换条件。两个转换条 件之间也不能直连,中间必须有动作状态。 3.下一状态的转换条件满足时,程序中的下一个状态或动作就开始执行。 4.从一个状态到下一个状态的程序进程将会持续执行直到一个完整的机器周期结束。 5.任一状态的输出/动作都由水平连接的方框表示,当状态转换条件满足时,产生输出。 图6.13 描述了部分顺序功能图及其等价的梯形图。 为了说明顺序功能图的规则,以庭洗衣机的部分洗漆周期为例。洗衣机滚桶内注满水 后便打开加热器开关,直到温度达到求的标准,然后滚桶转动一段特定时间。用一系列顺 序状态表示,如图6.14 所示 6.2.1分支和汇聚 如图6.15 所示,当跳转条件满足时,选择性分支便转移至相应的状态。 并联分支如图 6.16 所示,由一对平行线表示,可同时执行两个或多个不同的状态。 图 6.17 和图 6.18 给出了顺序功能图中汇聚的表示方法。在图 6.17 中,若IN4 发生, 执行顺序从状态2 转移到状态4,或若IN5 发生,可从状态3 转移到状态4。在图6.18 中, 若IN4 发生,执行顺序可同时从状态 2、3 转移到状态4 6.2.2动作 对于某个状态来说,可以执行一个或多个动作。所谓“动作”就像上面例子中的输出,用方框表示。 动作的行为可以用梯形图、功能块、指令表和结构文本来描述。所以,当使用梯形图 时,动作的行为由方框中的梯形图表示。当有电流输人“动作框图”中时,方所表示的 动作就会被激活。如图 6.20 所示。 在动作框图前通常附一个限定符,用以说明动作执行的条件。若有限定符或限定符 在相关状态激活时,所要求动作就不能被存储及连续执行。限定符 P用于脉冲动作,当某一程序步骤激活时它只执行一次。限定符 D 用于延时动作,在一段时间之后相应动作才会激发。限定符 L 用于限时动作,在执行一段时间以后才停止相应动作,如图 6.21 所示。 6.3结构文本 结构文本是一种和 PASCAL 极其相似的编程语言。程序由一系列被分号隔开的陈述语句构成。这些语句使用预先定义的语句和子函数来改变变量,变量可以是已定义的值或内部存储值或输入/输出值。 赋值语句用于对欲改变的变量进行赋值。例如: Light:=SwitchA; 表示变量Light 的值将被改变,当开关 A 闭合或断开时,变量Light 的值也随之变化。赋值语句的一般格式如下:X:=Y ; 其中,X 是自变量,Y 是因变量。再看另一个例子: Light:SwitchA OR SwitchB; 表示灯的开关由开关 A 或B 控制。 表6.2 给出了一些结构文本中的操作符, 如上面语句中的OR。并且也列出了它们在 程序运行时的优先级。例如, InputA=6 InputB=4 InputC=2 OutputQ:=InputA/3+InputB/(3-InputC) 其中,(3-InputC)的值作为函数的除数,所以计算输出 Q 语句的第二步是4/(3-2)=4。除法比加法优先,所以第一步在计算加法之前计算 6/3。因此,输出OutputQ 的值是2+1=3。 结构文本对字符大小写不敏感,因此为了增强可读性可任意使用大小写字母。同样,也可使用空格键或空行来增强可读性。所有表示变量的等式都以字符%开始,在其后面是一个或两个字母码用以标识其存储单元和其相应数据类型,其中存储单元包括输入/输出存储器或内部存储器,数据类型包括位、字节、字。例如: %IX100(*Input memory bit 100*) %ID200(*Input memory word200*) %QX100(*Output memory bit 100*) 第一个字母 I 是输入存储单元,Q 是输出存储单元,M 是内部存储器。第二个字母X 表示位,8 表示字节I(8 位),W 表示字(16 位),D 表示双字(32 位),L表示长字(64 位)。 AT 用来确定变量的存储单元。因此有: Input AT %IX100; (*Input is located at input memory bit 100*) 英文原文6 IL, SFC and ST programming methods This chapter continues from the previous chapter and discusses the other IEC 1131-3 (International Electrotechnical Commission) programming languages, i.e. instruction lists (IL), sequential function charts (SFC), and structured text (ST). 6.1 Instruction lists A programming method, which can be considered to be the entering of a ladder program using text, is instruction lists (IL). Instruction list gives programs which consist of a series of instructions, each instruction being on a new line. An instruction consists of an operator followed by one of more operands, i.e. the subjects of the operator. In terms of ladder diagrams an operator may be regarded as a ladder element. Each instruction may either use or change the value stored in a memory register. For this, mnemonic codes are used, each code corresponding to an operator/ladder element. The codes used differ to some extent from manufacturer to manufacturer, though a standard IEC 1131-3 has been proposed and is being widely adopted. Table 6.1 shows some of the codes used by manufacturers, and the proposed standard, for instructions used in this chapter (see later chapters for codes for other functions). Table 6.1 Instruction code mnemonics Store result register An output into operand LD A (*Load A*) AND B (*AND B*) ST Q (* Store result in Q, i.e. output to Q*) In the first line of the program, LD is the operator, A the operand, and the words at the ends of program lines and in brackets and preceded and followed by * are comments added to explain what the operation is and are not part of the program operation instructions to the PLC. LD A is thus the instruction to load the A into the memory register. It can then later be called on for further operations. The next line of the program has the Boolean operation AND performed with A and B. The last line has the result stored in Q, i.e. outputted to Q. Labels can be used to identify various entry points to a program, useful as we will find later for jumps in programs, and these precede the instruction and are separated from it by a colon. Thus we might have: PUMP_OK: LD C (* Load C*) with there being the instruction earlier in the program to jump to PUMP_OK if a particular condition is realised. With the IEC 113-1 operators, an N after it is used to negate its value. For example, if we have: LD A (*Load A*) ANDN B (*AND NOT B*) Thus the ANDN operator inverts the value of ladder contacts and ANDs the result. 6.1.1 Ladder programs and instruction lists When looked at in terms of ladder diagrams, whenever a rung is started, it must use a start a rung code. This might be LD, or perhaps A or L, to indicate the rung is starting with open contacts, or LDI, or perhaps LDN or LD NOT or AN or LN, to indicate it is starting with closed contacts. All rungs must end with an output or store result code. This might be OUT or = or ST. The following shows how individual rungs on a ladder are entered using the Mitsubishi mnemonics for the AND gate, shown in Figure 6.1(a). The rung start with LD because it is starting with open contacts. Since the address of the input is X400, the instruction is LD X400. This is followed by another open contacts input and so the next program line involves the instruction AND with the address of the element, thus the instruction is AND X401. The rung terminates with an output and so the instruction OUT is used with the address of the output, i.e. OUT Y430. The single rung of a ladder would thus be entered as: LD X400 AND X401 OUT Y430 For the same rung with Siemens notation (Figure 6.1(b) we have: A I0.1 A I0.2 = Q2.0 Consider another example, an OR gate. Figure 6.2(a) shows the gate with Mitsubishi notation. The instructions for the rung start with an open contact is LD X400. The next item is the parallel OR set of contacts X401. Thus the next instruction is OR X401. The last step is the output, hence OUT Y430. The instruction list would thus be: LD X400 OR X401 OUT Y430 Figure 6.2(b) shows the Siemens version of the OR gate. The following is the Siemens instruction list: A I0.1 O I0.2 = Q2.0 Figure 6.3(a) shows the ladder system for a NOR gate in Mitsubishi notation. The rung starts with normally closed contacts and so the instruction is LDI. I when added to Mitsubishi instruction is used to indicate the inverse of the instruction. The next step is a series normally closed contact and so ANI, again the I being used to make an AND instruction the inverse. I is also the instruction for a NOT gate. The instructions for the NOR gate rung of the ladder would thus be entered as: LDI X400 ANI X401 OUT Y430 Figure 6.3(b) shows the NOR gate with Siemens notation. Note that N added to an instruction is used to make the inverse. The instruction list then becomes: LN I0.1 AN I0.2 = Q2.0 Consider the rung shown in Figure 6.4(a) in Mitsubishi notation, a NAND gate. It starts with the normally closed contacts X400 and so starts with the instruction LDI X400. The next instruction is for a parallel set of normally closed contacts, thus the instruction is ORI X401. The last step is the output, hence OUT Y430. The instruction list is thus: LDI X400 ORI X401 OUT Y430 Figure 6.4(b) shows the NAND gate in Siemens notation. The instruction list is then: AN I0.1 ON I0.2 = Q2.0 6.1.2 Branch codes The Exclusive OR (XOR) gate shown in Figure 6.5(a) in Mitsubishi notation has two parallel arms with an AND situation in each arm. In such a situation Mitsubishi uses an ORB instruction to indicate OR together parallel branches. The first instruction is for a normally open pair of contacts X400. The next instruction is for a series set of normally closed contacts X401, hence ANI X401. After reading the first two instructions, the third instruction starts a new line. It is recognised as a new line because it starts with LDI, all new lines starting with LD or LDI. But the first line has not been ended by an output. The PLC thus recognises that a parallel line is involved for the second line and reads together the listed elements until the ORB instruction is reached. The mnemonic ORB (OR branches/blocks together) indicates to the PLC that it should OR the results of the first and second instructions with that of the new branch with the third and fourth instructions. The list concludes with the output OUT Y430. The instruction list would thus be entered as: LD X400 ANI X401 LDI X400 待添加的隐藏文字内容3AND X401 ORB OUT Y430 Figure 6.5(b) shows the Siemens version of XOR gate. Brackets are used to indicate that certain instructions are to be carried out as a block. They are used in the same way as brackets in any mathematical equation. For example (2 + 3)/4 means that the 2 and 3 must be added before dividing by 4. Thus with the Siemens instruction list we have in step 0 the instruction A(. The brackets close in step 3. This means that the A in step 0 is applied only after the instructions in steps 1 and 2 have been applied. The IEC 1131-3 standard for such programming is to use brackets in the way used in the above Siemens example. Figure 6.6(a) shows a circuit, in Mitsubishi notation, which can be considered as two branched AND blocks. The instruction used here is ANB. The instruction list is thus: Figure 6.6(b) shows the same circuit in Siemens notation. Such a program is written as an instruction list using brackets. The A instruction in step 0 applies to the result of steps 1 and 2. The A instruction in step 4 applies to the result of steps 5 and 6. The program instruction list is thus: Figure 6.7(a) shows a ladder, in Mitsubishi notation, with two rungs. In writing the instruction list we just write the instructions for each line in turn. The instruction LD or LDI indicates to the PLC that a new rung is starting. The instruction list is thus: LD X400 OUT Y430 LDI X400 OUT Y431 The system is one where when X400 is not activated, there is an output from Y431 but not Y430. When X400 is activated, there is then an output from Y430 but not Y431. Figure 6.7(b) shows the same program in Siemens notation. The = instruction indicates the end of a line. The A or AN instruction does not necessarily indicate the beginning of a rung since the same instruction is used for AND and AND NOT. The instruction list is then: A I0.0 = Q2.0 AN I0.0 = Q2.1 6.1.4 Programming examples The following tasks are intended to illustrate the application of the programming techniques given in this section and are the examples for which ladder diagrams and function block diagrams were derived in Section 5.7. See that section for an explanation of the ladder diagrams; here we just show the instruction lists relating to the programs. A signal lamp is required to be switched on if a pump is running and the pressure is satisfactory, or if the lamp test switch is closed. Figure 6.8 Shows the ladder program and the related instruction list. For a valve which is to be operated to lift a load when a pump is running and either the lift switch is operated or a switch operated indicating that the load has not already been lifted and is at the bottom of its lift channel, Figure 6.9 shows the ladder program and the related instruction list. For a system where there has to be no output when any one of four sensors gives an output, otherwise there is to be an output, Figure 6.10 shows the ladder p