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

L1     Input       Ladder logic program  Output  L2
                                                                                      CPT ADD SUB MUL DIV MOD SQR
                                        FRD                                     Compare Compute/Math Move/LogicalFile/Misc.
                                      From BCD
                   1
                                   Source     I:012
                   2      I:012                      O:013
                   3                                                                          MOD
                                   Destination  B3:0
                  Thumbwheel                   60        LED                          Modulo
                     switch                             Display                       Source A         Thumb_Value
                                   MUL                                                                                              7
                   0  6   0        MULTIPLY             14 0                          Source B                              2
                                   Source A   B3:0
                                               60                                     Dest                  Actual_Value
                     Celsius                          Fahrenheit
                                   Source B     9                                                                                    1
                                   Destination  N7:0
                                              540                    Figure 11-15  ControlLogix Modulo (MOD) instruction.
                                   DIV
                                   DIVIDE                                              Thumb_Value = 7
                                   Source A  N7:0
                                              540                                      7
                                   Source B     5                                        =1
                                                                                       2
                                   Destination  N7:1
                                              108
                                                                     11.6  Other Word-Level Math
                                   ADD                               Instructions
                                   ADD
                                   Source A   N7:1
                                              108                    The program of Figure 11-16 is an example of the square
                                   Source B    32
                                                                     root (SQR) instruction. The operation of the logic rung
                                   Destination  B3:1                 can be summarized as follows:
                                              140
                                        TOD                            •  When input switch SW is closed the SQR instruc-
                                       TO BCD                             tion is executed.
                                   Source     B3:1                     •  The number whose square root we want to deter-
                                              140                         mine (144) is placed in the source.
                                   Destination  O:013                  •  The function calculates the square root and places it
                                                                          (12) in the destination.
               Figure 11-14  Program for converting Celsius temperature   •  If the value of the source is negative, the instruction
               to Fahrenheit.                                             will store the square root of the absolute (positive)
                                                                          value of the source at the destination.
                 •  The DIV instruction divides 5 into the 540 and
                    stores the answer (108) in address N7:1.            The program of Figure 11-17 is an example of the ne-
                 •  The ADD instruction adds 32 to the value of 108   gate (NEG) instruction. This math function changes the
                                                                     sign of the source value from positive to negative. The
                    and stores the sum (140) in address B3:1.        operation of the logic rung can be summarized as follows:
                 •  Finally the TOD instruction is used to convert BCD
                    values into integers. to interface with the LED display.  •  When input switch SW is closed the NEG instruc-
                 •  Thus 60°C is displayed as 140°F.                      tion is executed.
                  The Modulo (MOD) instruction, shown in Figure 11-15,       Input           Ladder logic program
               is part of the ControlLogix Compute/Math instruction set.   L1
               This instruction is used to calculate the remainder after the            SW    SQR
               value stored in Source A is divided by the value stored in        SW           SQUARE ROOT
               Source B. In this unconditional rung example:                                  Source A       N7:101
                                                                                                               144
                                                                                              Destination    N7:105
                          Source A                                                                              12
                          Source B   = Dest (remainder)
                                                                                                     (  144 = 12)
                         Thumb_Value   = Actual_Value
                              2                                      Figure 11-16  SLC 500 SQR (square root) instruction.



               242        Chapter 11  Math Instructions







          pet73842_ch11_234-251.indd   242                                                                              03/11/15   4:07 PM
   256   257   258   259   260   261   262   263   264   265   266