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

is then divided by the value stored in source B,
                      L1   Input     SW    Ladder logic program            •  The value stored in source A, address N7:0 (120),
                                            DIV                              address N7:1 (4).
                               SW           DIVIDE
                                            Source A    C5:10.ACC          •  The answer, 30, is placed in the destination address
                                                                             N7:5.
                                            Source B          2
                                                                           •  As a result, the equal instruction becomes true, turn-
                                            Destination     N7:3             ing output PL1 on.
                                                                           The program of Figure 11-14 is an example of how
                   Figure 11-12  SLC 500 DIV (divide) instruction.       the DIV function is used as part of a program to convert
                                                                         Celsius temperature to Fahrenheit. The operation of the
                     •  The result is placed in the destination N7:3.    program can be summarized as follows:
                     •  If the remainder is 0.5 or greater, a roundup occurs   •  The thumbwheel switch connected to the input
                       in the integer destination.                           module indicates Celsius temperature.
                     •  The value stored in the math register consists of the   •  The program is designed to convert the recorded
                       unrounded quotient (placed in the most significant    Celsius temperature in the data table to Fahrenheit
                       word) and the remainder (placed in the least signifi-  values for display.
                       cant word).                                         •  The following conversion formula forms the basis
                     •  Some PLCs support the use of floating point num-     for the program:
                       bers as well as integer (whole number) values. As
                                                                                                     )
                                                                                              (
                       an example, 10 divided by 3 may be expressed as                    F =            × C   + 32
                                                                                               9 __
                       3.333333 (floating-point notation) or 3 with a re-                      5
                       mainder of 1.
                     •  A minor fault bit is set upon detection of a division   •  In this example, a current temperature reading of
                                                                             60°C is assumed.
                       by zero.
                                                                           •  The PLC processor carries out its internal opera-
                     The program of Figure 11-13 is an example of how the    tions using binary numbers and the FRD instruction
                   DIV instruction calculates the integer value that results   is used to convert the 16-bit integer values from the
                   from dividing source A by source B. The operation of the   thumbwheel switch into BCD values.
                   program can be summarized as follows:                   •  The MUL instruction multiplies the temperature

                     •  When input switch SW is closed the DIV instruc-      (60°C) by 9 and stores the product (540) in address
                       tion is executed.                                     N7:0.




                                           Input             Ladder logic program         Output
                                      L1                                                           L2
                                               SW
                                                     SW                                PL1
                                                                   DIV
                                                                   DIVIDE
                                                                   Source A   N7:0
                                                                               120
                                                                   Source B    N7:1
                                                                                 4
                                                                   Destination  N7:5
                                                                                30
                                                                              PL1
                                                       EQU
                                                       EQUAL
                                                       Source A   N7:5
                                                                    30
                                                       Source B     30
                                      Figure 11-13   DIV instruction used to calculate the value that results
                                      from dividing source A by source B.



                                                                                        Math Instructions  Chapter 11   241







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