PLC基本知识 -- 51 运算指令 (顺便学英文)
Math Instructions / 运算指令
Let's now look at using some basic math functions on our data. Many times in our applications we must execute some type of mathematical formula on our data. It's a rare occurrence when our data is actually exactly what we needed.
现在让我们看看如何在数据上使用一些基本的数学函数。很多时候,在我们的应用程序中,我们必须对数据执行某种类型的数学公式;但当我们的数据确实是我们所需要的类型的时候,我们也不一定要用到运算指令。
As an example, let's say we are manufacturing widgets. We don't want to display the total number we've made today, but rather we want to display how many more we need to make today to meet our quota. Lets say our quota for today is 1000 pieces. We'll say X is our current production. Therefore, we can figure that 1000-X=widgets left to make. To implement this formula we obviously need some math capability.
举个例子,假设我们在生产小部件,我们不想显示我们今天完成的总数,但是我们想显示我们今天需要完成多少才能达到我们的配额。假设我们今天的配额是1000件,我们当前的产量是X,那么,我们可以计算出我们还需要完成多少才能达到我们的配额,即还需要完成的小部件数量是1000-X。显然,为了实现这个公式,我们需要一些数学运算能力。
In general, PLCs almost always include these math functions:
一般来说,PLC通常包括以下这些数学运算功能:
Addition - The capability to add one piece of data to another. It is commonly called ADD.加法 - 将一段数据与另一段数据相加的功能,它通常被称为ADD。Subtraction - The capability to subtract one piece of data from another. It is commonly called SUB.减法 - 从一个数据中减去另一个数据的能力,它通常被称为SUB。Multiplication - The capability to multiply one piece of data by another. It is commonly called MUL.乘法 - 将一段数据乘以另一段数据的能力,它通常被称为MUL。Division - The capability to divide one piece of data from another. It is commonly called DIV.除法 - 将一个数据与另一个数据进行相除的能力,它通常被称为DIV。As we saw with the MOV instruction there are generally two common methods used by the majority of plc makers. The first method includes a single instruction that asks us for a few key pieces of information. This method typically requires:
正如我们在MOV指令中讲到的,大多数PLC制造商通常使用两种常用的方法。第一个方法 包含一条指令,它要求我们提供一些关键信息。这种方法通常需要:
Source A - This is the address of the first piece of data we will use in our formula. In other words it's the location in memory of where the first "number" is that we use in the formula.源A - 这是我们将在我们的公式中使用的第一数据块的地址。换句话说,它是我们在公式中使用的第一个“数字”在内存中的位置。Source B - This is the address of the second piece of data we will use in our formula. In other words it's the location in memory of where the second "number" is that we use in the formula. -NOTE: typically we can only work with 2 pieces of data at a time. In other words we can't work directly with a formula like 1+2+3. We would have to break it up into pieces. Like 1+2=X then X+3= our result.源B - 这是我们将在公式中使用的第二数据块的地址。换句话说,它是我们在公式中使用的第二个“数字”在内存中的位置。注意:通常我们一次只能处理2个数据。换句话说,我们不能直接用1+2+3这样的公式,我们得把它拆成碎片,比如1+2=X,然后X+3=结果。Destination - This is the address where the result of our formula will be put. For example, if 1+2=3, (I hope it still does!), the 3 would automatically be put into this destination memory location.结果 - 这是我们的计算公式的结果将被存放的地址。例如,如果1+2=3,3将自动放入这个目标内存位置。ADD symbol / ADD指令符号
The instructions above typically have a symbol that looks like that shown above. Of course, the word ADD would be replaced by SUB, MUL, DIV, etc. In this symbol, The source A is DM100, the source B is DM101 and the destination is DM102. Therefore, the formula is simply whatever value is in DM100 + whatever value is in DM101. The result is automatically stored into DM102.
上面的指令通常有一个类似于上面所示的符号。当然,ADD这个指令会被替换为SUB、MUL、DIV等。在这个符号中,源A的地址是DM100,源B的地址是DM101,计算结果的地址是DM102。因此,公式就是DM100中的任何值+ DM101中的任何值,计算结果自动存储到DM102中。
Shown above is how to use math functions on a ladder diagram. Please note that once again we are using a one-shot instruction. As we've seen before, this is because if we didn't use it we would execute the formula on every scan. Odds are good that we'd only want to execute the function one time when input 0000 becomes true. If we had previously put the number 100 into DM100 and 200 into DM101, the number 300 would be stored in DM102.(i.e. 100+200=300, right??)
上图显示的是如何在梯形图上使用数学运算函数。请注意,我们再次使用上升沿指令DIFU。正如我们之前看到的,这是因为如果我们不使用它,程序每次扫描时都会执行一次这个公式。当输入0000为“真”(True)时,我们只希望执行一次这个运算函数,这种功能是很常用的。如果我们预先将数字100放入地址DM100,将数字200放入地址DM101,那么数字300将被存储在地址DM102中。(100+200=300,对吧?)
ADD symbol (dual method) / ADD指令符(用于双指令方式)
The dual instruction method would use a symbol similar to that shown above. In this method, we give this symbol only the Source B location. The Source A location is given by the LDA instruction. The Destination would be included in the STA instruction.
双指令方法将使用类似于上图所示的符号。在这个方法中,ADD指令只给出这个符号的源B地址DM101,源A的地置DM100由LDA指令给出,结果的地址DM102将包括在STA指令中。
Shown above is a ladder diagram showing what we mean.
上图是双指令方法的梯形图。
The results are the same as the single instruction method shown above.
其计算结果和上面所讲单指令的计算结果是一样的。
In the example above, data memory 102 (DM102) initially holds the constant (number) 0000. Each time the operator pushes button 0000 the difu instruction will turn on (become true) FOR ONE SCAN. When this happens we load the value(number) in DM100(100) and add it to the value(number) in DM101(200). The result, 300 in this example (100+200=300) is then stored in DM102(300).
在上面的示例中,数据内存102 (DM102)最初保存的常量(数字)是0。每次操作员按下0000按钮,DIFU指令就会打开(变为“真”)一个扫描周期,当发生这种情况时,我们加载DM100中的值(数字)100并将其与DM101中的值(数字)200相加。其结果,本例中的300(100+200=300)存储到DM102中去。
What would happen if we had a result that was greater than the value that could be stored in a memory location?
如果计算结果大于存储器可以存储的最大值,会发生什么情况呢?
Typically the memory locations are 16-bit locations. (more about number types in a later chapter) In plain words this means that if the number is greater than 65535 (2^16=65536) it is too big to fit. Then we get what's called an overflow. Typically the plc turns on an internal relay that tells us an overflow has happened. Depending on the plc, we would have different data in the destination location. (DM102 from example) Most PLCs put the remainder here.
通常,内存地址是16位的地址(关于数字类型的更多内容将在后面的章节中介绍)。简单地说,这意味着如果数字大于65535(2^16=65536),那么它就太大了,寄存器无法容纳。然后我们得到了所谓的溢出。通常,这时候PLC会打开内部继电器,告诉我们发生了溢出。根据PLC的不同,我们在目标地址(比如DM102)会有不同的数据,大多数PLC将其余数放在这里。
Some use 32-bit math which solves the problem. (except for really big numbers!) If we're doing division, for example, and we divide by zero (illegal) the overflow bit typically turns on as well. Suffice it to say, check the overflow bit in your ladder and if its true, plan appropriately.
一些使用32位的运算来解决这个问题(除非是非常大的数字!)。例如,如果我们在做除法,然后除以0(非法),溢出位通常也会打开。我只想说,检查一下你的梯形图上是否有溢出的部分,如果是的话,适当地规划一下,可以设计成报警输出。
Many PLCs also include other math capabilities. Some of these functions could include:
许多PLC还包括其他一些数学运算功能。其中一些功能可能包括:
Square roots / 平方根ScalingAbsolute value / 绝对值Sine / 正弦Cosine / 余弦Tangent / 正切Natural logarithm / 自然对数Base 10 logarithm / 以10为底的对数X^Y (X to the power of Y) / X的Y次方Arcsine (tan, cos) / 反正弦and more....check with the manufacturer to be sure. / 还有其他的请查询用户手册Some PLCs can use floating point math as well. Floating point math is simply using decimal points. In other words, we could say that 10 divided by 3 is 3.333333 (floating point). Or we could say that 10 divided by 3 is 3 with a remainder of 1(long division). Many micro/mini PLCs don't include floating point math. Most larger systems typically do.
一些PLC也可以使用浮点数。浮点数学就是简单地使用小数点,换句话说,我们可以说10除以3等于3.333333(浮点数)或者我们可以说10除以3等于3余数是1(长除法),许多迷你PLC不包括浮点运算,但大多数大型系统通常都会有浮点运算功能。
Understand the theory and we can always learn how our manufacturer of choice does it.
理解这个理论,我们就可以知道如何选择我们所需类型的PLC。
PLC基本知识 -- 22 PLC如何工作 (顺便学英文)
How PLC Works / PLC如何工作
A PLC works by continually scanning a program. We can think of this scan cycle as consisting of 3 important steps. There are typically more than 3 but we can focus on the important parts and not worry about the others. Typically the others are checking the system and updating the current internal counter and timer values.
PLC的工作原理是不断地扫描程序。我们可以认为这个扫描周期包括三个重要的步骤。当然细分的话不止3个步骤,但我们可以先专注于这3个重要的部分,其他的通常是检查系统和更新当前的内部计数器和计时器值等等。
Step 1 - CHECK INPUT STATUS - First the PLC takes a look at each input to determine if it is ON or OFF. In other words, is the sensor connected to the first input on? How about the second input? How about the third... It records this data into its memory to be used during the next step.
步骤1 - 检查输入状态 - 首先PLC查看每个输入点,以确定其是否打开或关闭。换句话说,就是传感器连接到第一个输入点了吗?第二个输入点呢?第三个呢?…… 它将这些数据记录到内存中,以便在下一步中使用。
Step 2 - EXECUTE PROGRAM - Next the PLC executes your program one instruction at a time. Maybe your program said that if the first input was ON then it should turn ON the first output. Since it already knows which inputs are ON/OFF from the previous step it will be able to decide whether the first output should be turned ON based on the state of the first input. It will store the execution results for use later during the next step.
步骤2 - 执行程序 – 接下来,PLC一条一条执行你的程序。也许你的程序是这么写的:如果第一个输入点是打开的,那么它应该打开第一个输出点。由于PLC已经在第一步时知道了哪些输入点是打开或者关闭的,所以它将能够根据第一个输入点的状态来决定是否应该打开第一个输出点。它将存储这个执行结果,以便在下一步中使用。
Step 3 - UPDATE OUTPUT STATUS - Finally the PLC updates the status of the outputs. It updates the outputs based on which inputs were ON during the first step and the results of executing your program during the second step. Based on the example in step 2 it would now turn ON the first output because the first input was ON and your program said to turn ON the first output when this condition is true.
步骤3 - 更新输出状态 - 最后PLC更新输出点状态。 它根据第一步中打开的输入点和第二步中执行程序的结果更新输出点状态。根据第2步中的示例,它现在将打开第一个输出点,因为第一个输入点是打开的,并且你的程序写的是当这个条件为真时,它将打开第一个输出点。
After the third step the PLC goes back to step one and repeats the steps continuously. One scan time is defined as the time it takes to execute the 3 steps listed above.
在第三步之后,PLC返回到第一步并不断重复这些步骤。一次扫描时间被定义为执行上面列出的三个步骤所花费的时间。
相关问答
台达里ATMR是AND和TMR具体是什么意思?
ATMR指令相当于AND+TMR指令之组合,其前一接点成立时,此指定定时器将开始计时,当计时值到达时(计时值>=设定值),其AND接点动作成立;当前面接点不成立时...
008703是哪个国家的区号?
是国际海事卫星号码。国际海事卫星组织(英语:Inmarsatplc)(LSE:ISAT)是英国的卫星通信公司,提供全球性的移动服务。以11个地球静止轨道通信卫星,通过便...是...
at070tn83能用plc驱动吗?
AT070TN83是一款7英寸TFT液晶屏,可以通过PLC驱动器进行控制。PLC驱动器是一种常见的控制器,可用于控制各种工业设备和机器。它可以通过编程来控制输入和输出信...
西门子plc的inwork与atwork区别?
西门子PLC的INWORK和ATWORK是两种不同的工作模式,它们之间的主要区别在于扫描方式和执行顺序。INWORK是西门子PLC的“立即工作”模式,也被称为“单周期扫描”...
plcine能组成什么单词?
可以组成单词pencil,意思是:n.铅笔。vt.用铅笔写(或画、作记号)。例句:1.Hepulledthestubofapencilfrombehindhisear.他从耳后...
施耐德modbus地址表换算方法?
1、将设备的16进制地址转换为10进制:0003H(16进制数,H没用,只是说明该数为16进制数)=0003。2、设备定义PLC----莫迪康---Mobus-rtu----串口。3、变量定义.....
BAT----要翻译的单词abbr.1.=B.A.T.IndustriesPLC(英国)世...
[回答]BAT----要翻译的单词abbr.{abreviation的缩写,表明这是缩写词.}KK:[]--kk指的是什么DJ:[]--dj又指的是什么n.[C]--这个〔c〕又代表什么意思?{counta....
pressthekeytostartthemovementatthesettingrevolution._作业帮
[回答]pressthekeytostartthemovementatthesettingrevolution.按此键以设定的转速启动按键以启动设置更新的运行。如果你想改变旋转值再按一...
英语翻译Thegasdetectionandalarmsystemshallbeactiveatallt...
[回答]气体探测及报警系统需要时刻被激活,包括模块里的电源断掉的时候.就地的气体报警站要和平台上的火灾、气体探测系统使用相同的电源或者提供能够维持...
at89s51单片机有多少组?
at89s51单片机有4组。AT89S51有PDIP、PLCC、TQFP三种封装方式,其中最常见的就是采用40Pin封装的双列直接PDIP封装。芯片共有40个引脚,引脚的排列顺序为从靠...