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- 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.
See the truth table below to figure out what we mean. (1 AND 1 = 1, 0 AND 0= 0)
A | B | Result |
0 | 0 | 0 |
1 | 0 | 0 |
0 | 1 | 0 |
1 | 1 | 1 |
- 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 OR B is true...)
A | B | Result |
0 | 0 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
1 | 1 | 1 |
- 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.
A | B | Result |
0 | 0 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
1 | 1 | 0 |
The ladder logic instructions are commonly called 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:
- 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.
- 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.
- 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.
AND symbol
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.
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.
AND symbol (dual instruction method)
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.
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.
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.
No comments:
Post a Comment