Try our online PLC Simulator- FREE. Click here now to try it. |
Learn quickly with our PLC Training DVD Series: on sale
Click here now for details! 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. In general, PLCs almost always include these math functions:
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:
ADD symbol 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. 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??) ADD symbol (dual 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. Shown above is a ladder diagram showing what we mean. The results are the same as the single instruction method shown above. Click here and view the animation to really learn! 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. 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. Many PLCs also include other math capabilities. Some of these functions could include:
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. Understand the theory and we can always learn how our manufacturer of choice does it. Learn quickly with our PLC Training DVD Series: on saleClick here now for details! |
||
copyright © 1996-2011 by Phil Melore.
All rights reserved. |