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)。

PLC基本知識 -- 5.3 布爾函數  (順便學英文)

  • 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都為真時,結果也為真。

PLC基本知識 -- 5.3 布爾函數  (順便學英文)

  • 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)在某些通信協議中通常用作錯誤檢查。

PLC基本知識 -- 5.3 布爾函數  (順便學英文)

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)將自動放入此目標內 存位置。


PLC基本知識 -- 5.3 布爾函數  (順便學英文)

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. / 梯形圖中的布爾函數指令如下所示:

PLC基本知識 -- 5.3 布爾函數  (順便學英文)

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指令。


PLC基本知識 -- 5.3 布爾函數  (順便學英文)

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: / 下面這個梯形圖,顯示了這種方式:

PLC基本知識 -- 5.3 布爾函數  (順便學英文)

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的詳細說明。想要在文檔中找到理論,您可能會遇到一些困難。細節不重要,而理論很重要。


分享到:


相關文章: