Page 254 - Programmable Logic Controllers, Fifth Edition - Mobile version
P. 254

11.1  Math Instructions
                                                                           MUL (Multiply)—Multiplies source A by source B
                                                                           and stores the result in the destination.
                   Math instructions, like data manipulation instructions, en-
                   able the programmable controller to take on more of the   DIV (Divide)—Divides source A by source B and
                   qualities of a conventional computer. The PLC’s math func-  stores the result in the math register and destination.
                   tions capability allows it to perform arithmetic functions on   SQR (Square Root)—Calculates the square root of the
                   values stored in memory words or registers. For example,   source and places the integer result in the destination.
                   assume you are using a counter to keep track of the number   NEG (Negate)—Changes the sign of the source and
                   of parts manufactured, and you would like to display how   places it in the destination.
                   many more parts must be produced in order to reach a certain   TOD (To BCD)—Converts a 16-bit integer source
                   quota. This display would require the data in the accumu-  value to BCD and stores it in the math register or the
                   lated value of the counter to be subtracted from the quota re-  destination.
                   quired. Other applications include combining parts counted,   FRD (From BCD)—Converts a BCD value in the
                   subtracting detected defects, and calculating run rates.  math register or the source to an integer and stores it
                     Depending on what type of processor is used, various   in the destination.
                   math instructions can be programmed.  The basic four
                   mathematical functions performed by PLCs are:           The basic math instructions are ADD, SUB, MUL, and
                                                                         DIV. Each of these instructions has three parameter fields.
                     Addition—The capability to add one piece of data to   Namely, Source A, Source B and Destination fields.
                     another.
                     Subtraction—The capability to subtract one piece of   •  The Source A and Source B fields can be an input
                                                                             rack location, file address, instruction field, or a
                     data from another.                                      fixed value. For example:
                     Multiplication—The capability to multiply one piece        Input Location      I:1
                     of data by another.                                        File Address        N7:5
                     Division—The capability to divide one piece of data        Instruction Field   C5:2.ACC
                     by another.                                                Fixed Value         30
                     Math instructions use the contents of two words or regis-  •  The Destination fields can be an output location,
                   ters and perform the desired function. The PLC instructions   file address, or an instruction field. For example:
                   for data manipulation (data transfer and data compare) are   Output location     O:2
                   used with the math symbols to perform math functions.        File Address        N7:8
                   Math instructions are all output instructions. These instruc-  Instruction Field   T4:1.PRE
                   tions can be conditional or unconditional. With conditional   Figure 11-2 shows the CPT (compute) instruction used
                   arithmetic instructions the input logic determines when the   with SLC 500 controllers. When CPT instruction is executed,
                   instruction executes. Unconditional arithmetic instructions   then copy, arithmetic, logical, or conversion operation resid-
                   execute with each scan.                               ing in the expression field of this instruction is performed
                     Figure 11-1 shows the Compute/Math menu tab for the   and the result is sent to the destination. The execution time
                   SLC 500 PLC and its associated RSLogix software. The   of a CPT instruction is longer than that of a single arithmetic
                   commands can be summarized as follows:                operation and uses more instruction words.

                     CPT (Compute)—Evaluates an expression and stores      The main advantage of the compute instruction is that
                     the result in the destination.                      it allows you to enter quite complex expressions in one in-
                     ADD (Add)—Adds source A to source B and stores      struction. Figure 11-3 shows a ladder rung used to convert
                     the result in the destination.                      a Fahrenheit temperature to a Celsius temperature using
                                                                         a single RSLogix 5000 compute instruction.  The CPT
                     SUB (Subtract)—Subtracts source B from source A
                     and stores the result in the destination.
                                                                                         CPT
                                                                                         Compute

                        CPT  ADD  SUB MUL  DIV  SQR  NEG TOD  FRD                        Destination

                            Input/Output  Compare  Compute/Math  Move/Logic              Expression

                   Figure 11-1  Compute/Math menu tab.                   Figure 11-2  SLC 500 CPT (compute) instruction.



                                                                                        Math Instructions  Chapter 11   235







          pet73842_ch11_234-251.indd   235                                                                              03/11/15   4:07 PM
   249   250   251   252   253   254   255   256   257   258   259