Académique Documents
Professionnel Documents
Culture Documents
Math Instructions
Chapter Objectives
1. Analyze and interpret math instructions as they apply to a PLC program 2. Create PLC programs involving math instructions 3. Apply combinations of PLC arithmetic functions to processes
Chapter Objectives
Most PLCs have arithmetic function capabilities. Basic PLC math instructions include add, subtract, multiply and divide to calculate the sum, difference, product, and quotient of the content of word registers. The PLC is capable of doing many arithmetic operations per scan period for fast updating of data. This chapter covers the basic mathematical instructions performed by PLCs and their applications.
I. Math Instructions
Math instructions, like data manipulation instructions, enable the programmable controller to take on more of the qualities of a conventional computer. The PLCs math functions capability allows it to perform arithmetic functions on values stored in memory words or registers. For example, assume you are using a counter to keep track of the number of parts manufactured, and you would like to display how many more parts must be produced in order to reach a certain quota. This display would require the data in the accumulated value of the counter to be subtracted from the quota required. Other applications include combining parts counted, subtracting detected defects, and calculating run rates. Depending on what type of processor is used, various math instructions can be programmed. The basic four mathematical functions performed by PLCs are: AdditionThe capability to add one piece of data to another. SubtractionThe capability to subtract one piece of data from another. MultiplicationThe capability to multiply one piece of data by another. DivisionThe capability to divide one piece of data by another.
I. Math Instructions
Math instructions use the contents of two words or registers and perform the desired function. The PLC instructions for data manipulation (data transfer and data compare) are used with the math symbols to perform math functions. Math instructions are all output instructions. Figure 11-1 shows the Compute/Math menu tab for the SLC 500 PLC and its associated RSLogix software. The commands can be summarized as follows: CPT (Compute)Evaluates an expression and stores the result in the destination. ADD (add)Adds source A to source B and stores the result in the destination. SUB (Subtract)Subtracts source B from source A and stores the result in the destination. MUL (Multiply)Multiplies source A by source B and stores the result in the destination.
I. Math Instructions
I. Math Instructions
DIV (Divide)Divides source A by source B and stores the result in the math register. SQR (Square Root)Calculates the square root of the source and places the integer result in the destination. NEG (Negate)Changes the sign of the source and places it in the destination. TOD (To BCD)Converts a 16-bit integer source value to BCD and stores it in the math register or the destination. FRD (From BCD)Converts a BCD value in the math register or the source to an integer and stores it in the destination. Figure 11-2 shows the CPT (compute)instruction used with SLC 500 controllers. When CPT instruction is executed, then copy, arithmetic, logical, or conversion operation residing in the expression field of this instruction is performed and the result is sent to the destination. The execution time of a CPT instruction is longer than that of a single arithmetic operation and uses more instruction words.
I. Math Instructions
V. Division Instruction
The divide (DIV)instruction divides the value in source A by the value in source B and stores the result in the destination and math register. Figure 11-11 shows an example of the DIV instruction. The operation of the logic rung can be summarized as follows: When input switch SW is closed the rung will be true. The data in source A(the accumulated value of counter C5:10) is then divided by the data in source B (the constant 2). The result is placed in the destination N7:3. If the remainder is 0.5 or greater, a roundup occurs in the integer destination. The value stored in the math register consists of the unrounded quotient (placed in the most significant word) and the remainder (placed in the least significant word). Some PLCs support the use of floating-decimal as well as integer (whole number) values. As an example, 10 divided by 3 may be expressed as 3.333333 (fl oating-decimal notation) or 3 with a remainder of 1.
V. Division Instruction
V. Division Instruction
The program of Figure 11-12 is an example of how the DIV instruction calculates the integer value that results from dividing source Aby source B.The operation of the program can be summarized as follows: When input switch SW is closed the DIV instruction is executed. The value stored in source A,address N7:0 (120), is then divided by the value stored in source B,address N7:1 (4). The answer, 30, is placed in the destination address N7:5. As a result, the equal instruction becomes true, turning output PL1 on.
V. Division Instruction
V. Division Instruction
The program of Figure 11-13 is an example of how the DIV function is used as part of a program to convert Celsius temperature to Fahrenheit. The operation of the program can be summarized as follows: The thumbwheel switch connected to the input module indicates Celsius temperature. The program is designed to convert the recorded Celsius temperature in the data table to Fahrenheit values for display. The following conversion formula forms the basis for the program: F=(9/5 C)+32 In this example, a current temperature reading of 60C is assumed. The MUL instruction multiplies the temperature (60C) by 9 and stores the product (540) in address N7:0. Next, the DIV instruction divides 5 into the 540 and stores the answer (108) in address N7:1. Finally, the ADD instruction adds 32 to the value of 108 and stores the sum (140) in address O:13. Thus 60C 5 140F.
V. Division Instruction
REVIEW QUESTIONS
1. Explain the function of math instructions as applied to the PLC. 2. Name the four basic math functions performed by PLCs. 3. What standard format is used for PLC math instructions? 4. Would math instructions be classified as input or output instructions? 5. With reference to the instruction of Figure 11-24 , what is the value of the number stored at source B if N7:3 contains a value of 60 and N7:20 contains a value of 80? 6. With reference to the instruction of Figure 11-25 , what is the value of the number stored at the destination if N7:3 contains a value of 500? 7. With reference to the instruction of Figure 11-26 , what is the value of the number stored at the destination if N7:3 contains a value of 40 and N7:4 contains a value of 3? 8. With reference to the instruction of Figure 11-27 , what is the value of the number stored at the destination if N7:3 contains a value of 15 and N7:4 contains a value of 4?
REVIEW QUESTIONS
REVIEW QUESTIONS
9. With reference to the instruction of Figure 11-28 , what is the value of the number stored at N7:20 if N7:3 contains a value of 2345? 10. With reference to the instruction of Figure 11-29 , what will be the value of each of the bits in word B3:3 when the rung goes true? 11. With reference to the instruction of Figure 11-30 , what is the value of the number stored at N7:101? 12. With reference to the instruction of Figure 11-31 , list the values that will be stored in file #N7:10 when the rung goes true.
REVIEW QUESTIONS
PROBLEMS
1. Answer each of the following with reference to the counter program shown in Figure 11-32 . a. Assume the accumulated count of counters C5:0 and C5:1 to be 148 and 36, respectively. State the value of the number stored in each of the following words at this point: (1) C5:0.ACC (2) C5:1.ACC (3) N7:1 (4) Source B of the GEQ instruction b. Will output PL1 be energized at this point? Why? c. Assume the accumulated count of counters C5:0 and C5:1 to be 250 and 175, respectively. State the value of the number stored in each of the following words at this point: (1) C5:0.ACC (2)C5:1.ACC (3)N7:1 (4)Source B of the GEQ instruction d. Will output PL1 be energized at this point? Why?
PROBLEMS
PROBLEMS
2. Answer each of the following with reference to the overfill alarm program shown in Figure 11-33 . a. Assume that the vessel is fi lling and has reached the 300-lb point. State the status of each of the logic rungs (true or false) at this point. b. Assume that the vessel is filling and has reached the 480-lb point. State the value of the number stored in each of the following words at this point: (1) I:012 (2) N7:1 c. Assume that the vessel is filled to a weight of 502 lb. State the status of each of the logic rungs (true or false) for this condition. d. Assume that the vessel is filled to a weight of 510 lb. State the value of the number stored in each of the following words for this condition: (1) I:012 (2) N7:1 e. With the vessel filled to a weight of 510 lb, state the status of each of the logic rungs (true or false).
PROBLEMS
PROBLEMS
3. Answer the following with reference to the temperature control program shown in Figure 11-34 . a. Assume that the set-point temperature is 600F. At what temperature will the electric heaters be turned on and off? b. Assume that the set-point temperature is 600F and the thermocouple input module indicates a temperature of 590F. What is the value of the number stored in each of the following words at this point? (1) I:012 (2) I:013 (3) N7:0 (4) N7:1 (5) N7:2 c. Assume that the set-point temperature is 600F and the thermocouple input module indicates a temperature of 608F. What is the status (energized or not energized) of each of the following outputs? (1) PL1 (2) PL2 (3) Heater
PROBLEMS
PROBLEMS
4. With reference to the Celsius to Fahrenheit conversion program shown in Figure 11-35 , state the value of the number stored in each of the following words for a thumbwheel setting of 035: a. I:012 b. N7:0 c. N7:1 d. O:013
PROBLEMS
PROBLEMS
5. Design a program that will add the values stored at N7:23 and N7:24 and store the result in N7:30 whenever input A is true, and then, when input B is true, will copy the data from N7:30 to N7:31. 6. Design a program that will take the accumulated value from TON timer T4:1 and display it on a 4-digit, BCD format set of LEDs. Use address O:023 for the LEDs. Include the provision to change the preset value of the timer from a set of 4-digit BCD thumbwheels when input A is true. Use address I:012 for the thumbwheels. 7. Design a program that will implement the following arithmetic operation: Use a MOV instruction and place the value 45 in N7:0 and 286 in N7:1. Add the values together and store the result in N7:2. Subtract the value in N7:2 from 785 and store the result in N7:3. Multiply the value in N7:3 by 25 and store the result in N7:4. Divide the value in N7:4 by 35 and store the result in F8:0.
PROBLEMS
8. a.There are three part conveyor lines (1-2-3) feeding a main conveyor. Each of the three conveyor lines has its own counter. Construct a PLC program to obtain the total count of parts on the main conveyor. b. Add a timer to the program that will update the total count every 30 s. 9. With reference to math instruction program shown in Figure 11-36 , when the input goes true, what value will be stored at each of the following? a. N7:3 b. N7:5 c. F8:1 10. With reference to the math instruction program shown in Figure 11-37 , when the input goes true, what value will be stored at each of the following? a. N7:3 b. N7:4 c. N7:5 d. N7:6
PROBLEMS
PROBLEMS
PROBLEMS
11. Two part conveyor lines, A and B, feed a main conveyor line M. A third conveyor line, R, removes rejected parts a short distance away from the main conveyor. Conveyors A, B, and R have parts counters connected to them. Construct a PLC program to obtain the total parts output of main conveyor M. 12. A main conveyor has two conveyors, A and B, feeding it. Feeder conveyor A puts six-packs of canned soda on the main conveyor. Feeder conveyor B puts eight-packs of canned soda on the main conveyor. Both feeder conveyors have counters that count the number of packsleaving them. Construct a PLC program to give a total can count on the main conveyor.