PLC基本知识 -- 5.3 布尔函数 (顺便学英文)

Boolean Math / 布尔函数

Let's now take a look at some simple "boolean math". Boolean math lets us do some vary basic functions with the bits in our registers. These basic functions typically include AND, OR and XOR functions. Each is described below.

现在让我们来看看一些简单的“布尔函数”。布尔函数能让我们用寄存器中的位来完成一些基本的函数功能,这些基本函数通常包括AND、OR和XOR函数。下面是详细描述。

AND - This function enables us to use the truth table below. Here, we can see that the AND function is very much related to multiplication. We see this because the only time the Result is true (i.e. 1) is when both operators A AND B are true (i.e. 1). The AND instruction is useful when your plc doesn't have a masking function. Oh yeah, a masking function enables a bit in a register to be "left alone" when working on a bit level. This is simply because any bit that is ANDed with itself will remain the value it currently is. For example, if you wanted to clear ( make them 0) only 12 bits in a 16 bit register you might AND the register with 0's everywhere except in the 4 bits you wanted to maintain the status of.

AND - 这个函数我们可以参考下面的真值表,表里我们可以看到AND函数与乘法的相关度较高,我 们之所以看到这一点,是因为只有当操作符A和B都为真(即1)时,结果才为真(即1)。

当你所使用的PLC没有屏蔽功能时AND指令是很有用的,哦,对,屏蔽功能使一个寄存器中的位工 作在一个位级别上的时候能够“独处”而不受干扰,这只是因为任何与自身AND的位都将保持其当前 的值,例如,如果您只想要清除(使它们为0)一个16位寄存器中的12位,那么您可以用0与除您 想要保持状态的4位之外的所有的位进行AND运算。

See the truth table below to figure out what we mean. (1 AND 1 = 1, 0 AND 0= 0)

参见下面的真值表,了解我所讲的意思( 1 AND 1 = 1, 0 AND 0 = 0)。

OR - This functions based upon the truth table below. Here, we can see that the OR function is very much related to addition. We see this because the only time the Result is true (i.e. 1) is when operator A or B is true (i.e. 1). Obviously, when they are both true the result is true. (If A and B is true...)

OR - 这个函数我们可以参考下面的真值表,在表里我们可以看到OR函数与加法非常相似。我们之 所以看到这一点,是因为只有当操作数A或者B为真(即1)时,结果才为真(即1)。显然,当它们A和 B都为真时,结果也为真。

EXOR - This function enables us to use the truth table below. Here, we can see that the EXOR (XOR) function is not related to anything I can think of ! An easy way to remember the results of this function is to think that A and B must be one or the other case, exclusively. Huh?
In other words, they must be opposites of each other. When they are both the same (i.e. A=B) the result is false (i.e. 0). This is sometimes useful when you want to compare bits in 2 registers and highlight which bits are different. It's also needed when we calculate some checksums. A checksum is commonly used as error checking in some communications protocols.

EXOR - 这个函数我们可以参考下面的真值表,在表里我们可以看到EXOR(XOR)函数与我能想 到的任何其他函数都没有相似性!要记住这个函数的结果,一个简单的方法是认为A和B是唯一 的。嗯?

换句话说,它们必须是彼此的对立面,其结果才会为真;当它们都是相同的(即A=B)时,结果为 假(即0)。

当您想要比较两个寄存器中的位并突出显示不同的位时,就可以用到这个函数,当我们计算校验和 (CheckSum)时也需要用到它,校验和(CheckSum)在某些通信协议中通常用作错误检查。

The ladder logic instructions are commonly called AND, ANDA, ANDW, OR, ORA, ORW, XOR, EORA XORW.

梯形图中与这些功能相关的逻辑指令通常被称为AND、ANDA、ANDW、OR、ORA、ORW、XOR、EORA、XORW。

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 other words its the location in memory of where the A is.

源A - 这是我们要使用的第一个数据的地址,换句话说,它是A在内存中的位置。

Source B - This is the address of the second piece of data we will use. In other words its the location in memory of where the B is.

源B - 这是我们要使用的第二个数据的地址,换句话说,它是B在内存中的位置。

Destination - This is the address where the result will be put. For example, if A AND B = 0 the result (0) would automatically be put into this destination memory location.

目标 - 这是要存放运算结果的地址。例如,如果A AND B = 0,则结果(0)将自动放入此目标内 存位置。


AND symbol / AND指令符号

The instructions above typically have a symbol that looks like that shown here. Of course, the word AND would be replaced by OR or XOR. In this symbol, The source A is DM100, the source B is DM101 and the destination is DM102. Therefore, we have simply created the equation DM100 AND DM101 = DM102. The result is automatically stored into DM102.

上面的指令通常有一个类似于上面所示的符号。当然,指令AND也可以被OR或XOR替换。在这个符号中,源A是DM100,源B是DM101,目标是DM102。因此,我们简单地创建了等式DM100 AND DM101 = DM102,其结果自动存储到DM102中。

The boolean functions on a ladder diagram are shown below. / 梯形图中的布尔函数指令如下所示:

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 instruction on every scan. Odds are good that we'd only want to execute the function one time when input 0000 becomes true.

请注意,我们再次使用了One-Shot(DIFU)指令。正如我们之前看到的,这是因为如果我们不使用它,在每次扫描时都会执行AND指令,但在这里当输入0000为真时,我们只希望执行一次AND指令,所以要用到One-Shot指令。


AND symbol (dual instruction method) / AND指令符号(双指令方式)

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.

双指令方式将使用类似于上面所示的符号。在这个方法中,我们只给出这个符号的源B的位置,源A的位置由LDA指令给出,目标地址将包括在STA指令中。

Below is a ladder diagram showing what is meant: / 下面这个梯形图,显示了这种方式:

The results are the same as the single instruction method shown above. It should be noted that although the symbol and ladder diagram above show the AND instruction, OR or EXOR can be used as well. Simply substitute the word "AND" within the instruction to be either "OR" or "EXOR". The results will be the same as shown in their respective truth tables.

其结果与上面所示的单一指令方法相同。需要注意的是,虽然上面的梯形图中使用的是AND指令,但也可以依据实际需求使用OR或EXOR指令进行替换。简单地替换指令中的指令符“AND”成为 “OR” 或 “EXOR” 即可,其结果将与各自对应的真值表中显示的结果相同。

We should always remember that the theory is most important. If we can understand the theory of why things happen as they do, we can use anybody's plc. If we refer to the manufacturers documentation we can find out the details for the particular plc we are using. Try to find the theory in that documentation and you might come up short. The details are insignificant while the theory is very significant.

我们应该永远记住理论是最重要的。如果我们能够理解事物为什么会这样发生的理论,我们就可以使用任何品牌的PLC。如果我们参考制造商的文件,我们可以找到我们正在使用的特定PLC的详细说明。想要在文档中找到理论,您可能会遇到一些困难。细节不重要,而理论很重要。