使用PLC的自动化制造系统——2.1.2 编程

来源:互联网 发布:全国电动汽车台数据 编辑:程序博客网 时间:2024/04/30 02:56

2.1.2 Programming
2.1.2编程

   

    The first PLCs were programmed with a technique that was based on relay logic wiring schematics. This eliminated the need to teach the electricians, technicians and engineers how to program a computer - but, this method has stuck and it is the most common technique for programming PLCs today. An example of ladder logic can be seen in Figure 2.5. To interpret this diagram imagine that the power is on the vertical line on the left hand side, we call this the hot rail. On the right hand side is the neutral rail. In the figure there are two rungs, and on each rung there are combinations of inputs (two vertical lines) and outputs (circles). If the inputs are opened or closed in the right combination the power can flow from the hot rail, through the inputs, to power the outputs, and finally to the neutral rail. An input can come from a sensor, switch, or any other type of sensor. An output will be some device outside the PLC that is switched on or off, such as lights or motors.In the top rung the contacts are normally open and normally closed. Which means if input A is on and input B is off, then power will flow through the output and activate it. Any other combination of input values will result in the output X being off.

      起初PLC的编程是在继电器逻辑布线示意图技术的基础上的。这减少了教电工,技术员和工程师如何在电脑上编程的需要,这种方法一直坚持至今,是最常见的PLC的编程技术。梯形逻辑的例子可以从图2.5看出。为了解释这个图,想像电源在左手边垂直线一方,我们称之为火线。在右边是中性线。在图中有两个梯级,和每个梯级有输入(两个垂直线)和输出(圆圈)的组合。如果输入以正确的组合打开或闭合,电流将从火线流经输入,驱动输出,并最终到达中性线。输入可以来自一个传感器,开关,或任何其他类型的传感器。输出可能是PLC以外的某些设备,可以开启或关闭,如灯光,或电动机。在最上边的梯级,触点是常开和常闭。这意味着如果输入A是ON并且输入B是OFF,那么电流将流经输出和激活它。任何其他输入值的组合将导致输出X被关闭。

 

    The second rung of Figure 2.5 is more complex, there are actually multiple combinations of inputs that will result in the output Y turning on. On the left most part of the rung, power could flow through the top if C is off and D is on. Power could also (and simultaneously) flow through the bottom if both E and F are true. This would get power half way across the rung, and then if G or H is true the power will be delivered to output Y. In later chapters we will examine how to interpret and construct these diagrams.

    There are other methods for programming PLCs. One of the earliest techniques involved mnemonic instructions.These instructions can be derived directly from the ladder logic diagrams and entered into the PLC through a simple programming terminal. An example of mnemonics is shown in Figure 2.6. In this example the instructions are read one line at a time from top to bottom. The first line 00000 has the instruction LDN (input load and not) for input A. This will examine the input to the PLC and if it is off it will remember a 1 (or true), if it is on it will remember a 0 (or false). The next line uses an LD (input load) statement to look at the input. If the input is off it remembers a 0, if the input is on it remembers a 1 (note: this is the reverse of the LD). The AND statement recalls the last two numbers remembered and if the are both true the result is a 1, otherwise the result
is a 0. This result now replaces the two numbers that were recalled, and there is only one number remembered. The process is repeated for lines 00003 and 00004, but when these are done there are now three numbers remembered. The oldest number is from the AND, the newer numbers are from the two LD instructions. The AND in line 00005 combines the results from the last LD instructions and now there are two numbers remembered.The OR instruction takes the two numbers now remaining and if either one is a 1 the result is a 1, otherwise the result is a 0. This result replaces the two numbers, and there is now a single number there. The last instruction is the ST (store output) that will look at the last value stored and if it is 1, the output will be turned on, if it is 0 the output will be turned off.

 

      图2.5的第二个梯级更复杂,其实有多种输入的组合导致输出Y运行。在梯级的最左边的部分,电流可能流过顶部,如果C是off并且D是ON。电力还可以(同时)流经底部,如果E和F都为真。这将使电流流过梯级的一半,然后如果G或H是真,电流将被传递到输出到Y。在后面的章节,我们会研究如何解释和建造这些图表。

      还有其他的PLC编程方法。其中最早的技术涉及助记符指令。这些指令可能直接源自梯形逻辑图,并通过一个简单的编程终端输入到PLC。助记符指令例子如图2.6所示。在这个例子中指令一次自上而下读取一行。第一行00000是输入A的指令LDN(input load and not),将检查到PLC中的输入,如果它是off,就记有1(或true),如果它是on,它会记为0(或false)。下一行使用一个LD (输入负载)语句检查输入。如果输入off,它记为0,如果输入为on,它还会记为1 (注:这是LD的取反)。AND声明取回记住的最后两个数字,如果二者都为真,结果是1,否则结果是0。这一结果现在取代了两个被召回数字,并只有一个数字在内存中。这一过程将重复进行00003行和00004行,但如果这些完成,现在有三个数字在内存中。最旧的数字是从AND指令获得,最新的数字是从两个LD指令获得。00005行的AND组合了从上两个LD指令,现在已经有两个数字在内存中。OR指令采用现在剩下的两个数字,如果一方是1的结果是1, 否则结果是0。这一结果可替代上两个数字,现在有一个数字。最后一个指令是ST(存储输出),将检视一下过去存储的值,如果是1,输出将被值ON,如果它是0,输出将被值OFF。

 

    The ladder logic program in Figure 2.6, is equivalent to the mnemonic program. Even if you have programmed a PLC with ladder logic, it will be converted to mnemonic form before being used by the PLC. In the past mnemonic programming was the most common, but now it is uncommon for users to even see mnemonic programs.

     

    图2.6的梯形逻辑程序相当于助记符程序。 即使你有梯形逻辑编程,PLC的,它将被PLC转换为助记符形式。在过去助记符程序是最普遍的,但现在对用户是不普遍的甚至很少看到助记符程序。

 

    Sequential Function Charts (SFCs) have been developed to accommodate the programming of more advanced systems. These are similar to flowcharts, but much more powerful. The example seen in Figure 2.7 is doing two different things. To read the chart, start at the top where is says start. Below this there is the double horizontal line that says follow both paths. As a result the PLC will start to follow the branch on the left and right hand sides separately and simultaneously. On the left there are two functions the first one is the power up function. This function will run until it decides it is done, and the power down function will come after. On the right hand side is the flash function, this will run until it is done. These functions look unexplained, but each function, such as power up
will be a small ladder logic program. This method is much different from flowcharts because it does not have to follow a single path through the flowchart.

     

      顺序功能图(SFCs)已经制定,以适应对更先进系统的编程。它们类似于流程图,但更强大的。在图2.7中看到的例子就是做两件不同的事情。阅读图表时, 从顶部写着“start”的地方开始。下面有双重水平线的是告诉你有着两个路径。因此,PLC分别并同时从左右两个分支开始。在左边有两个函数的第一个是power up函数。此函数将运行至其判决完成,接着power down函数接着而来。在右边是flash函数,它一直运行到它完成。这些函数看上去莫名其妙,但每个函数,例如power up可能是一个小的梯形逻辑程序。这种方法和流程图有很大不同,因为它不必通过单一路径遍历流程图。

 

 

    Structured Text programming has been developed as a more modern programming language. It is quite similar to languages such as BASIC. A simple example is shown in Figure 2.8. This example uses a PLC memory location i. This memory location is for an integer, as will be explained later in the book. The first line of the program sets the value
to 0. The next line begins a loop, and will be where the loop returns to. The next line recalls the value in location i, adds 1 to it and returns it to the same location. The next line checks to see if the loop should quit. If i is greater than or equal to 10, then the loop will quit, otherwise the computer will go back up to the REPEAT statement continue from
there. Each time the program goes through this loop i will increase by 1 until the value
reaches 10.

      结构化文本编程已发展为一个更现代的编程语言。它与如BASIC之类的语言很相似。一个简单的例子如图2.8所示。此示例使用一个PLC的内存占位符i。这个内存占位符是一个整数,这将在这本书的后面解释。程序的第一行设置i的值为0 。下一行开始一个循环,并将在循环返回。下一行返回i的值,并增加了1,并返回到相同的位置。下一行检查是否应该退出循环。如果i大于或等于10,那么循环将退出,否则计算机将返回到repeat声明并从那里继续。每次程序通过这个循环时,i的值将增加1直到该值达到10。

 

原创粉丝点击