0% found this document useful (0 votes)
132 views16 pages

ch-11 - Math Functions

1) The document discusses math instructions in programmable logic controllers (PLCs) that allow arithmetic functions like addition, subtraction, multiplication, and division. 2) Basic PLC math instructions include add, subtract, multiply, and divide instructions that operate on values stored in memory registers. 3) Examples show how addition and other math instructions work, including adding the values from two counters and comparing the sum to a threshold.

Uploaded by

Swati Madhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views16 pages

ch-11 - Math Functions

1) The document discusses math instructions in programmable logic controllers (PLCs) that allow arithmetic functions like addition, subtraction, multiplication, and division. 2) Basic PLC math instructions include add, subtract, multiply, and divide instructions that operate on values stored in memory registers. 3) Examples show how addition and other math instructions work, including adding the values from two counters and comparing the sum to a threshold.

Uploaded by

Swati Madhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

11

Math Instructions

Image Used with Permission of Rockwell Automation, Inc.

Chapter Objectives
Most PLCs have arithmetic function capabilities. After completing this chapter, you will be able to:
Basic PLC math instructions include add, sub- 11.1 Analyze and interpret math instructions as they apply
tract, multiply and divide to calculate the sum, to a PLC program
difference, product, and quotient of the content 11.2 Create PLC programs involving math instructions
of word registers. The PLC is capable of doing 11.3 Apply combinations of PLC arithmetic functions to
many arithmetic operations per scan period for processes
fast updating of data. This chapter covers the
basic mathematical instructions performed by
PLCs and their applications.

226

pet10882_ch11_226-241.indd 226 7/27/10 4:09 PM


11.1 Math Instructions CPT
Compute
Math instructions, like data manipulation instructions,
enable the programmable controller to take on more of Destination
the qualities of a conventional computer. The PLC’s math
Expression
functions capability allows it to perform arithmetic func-
tions on values stored in memory words or registers. For
example, assume you are using a counter to keep track Figure 11-2 SLC 500 CPT (compute) instruction.
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 re- DIV (Divide)—Divides source A by source B and
quire the data in the accumulated value of the counter to stores the result in the math register.
be subtracted from the quota required. Other applications SQR (Square Root)—Calculates the square root
include combining parts counted, subtracting detected de- of the source and places the integer result in the
fects, and calculating run rates. destination.
Depending on what type of processor is used, various NEG (Negate)—Changes the sign of the source and
math instructions can be programmed. The basic four places it in the destination.
mathematical functions performed by PLCs are: TOD (To BCD)—Converts a 16-bit integer source
Addition—The capability to add one piece of data to value to BCD and stores it in the math register or the
another. destination.
Subtraction—The capability to subtract one piece of FRD (From BCD)—Converts a BCD value in the
data from another. math register or the source to an integer and stores it
in the destination.
Multiplication—The capability to multiply one piece
of data by another. Figure 11-2 shows the CPT (compute) instruction used
Division—The capability to divide one piece of data with SLC 500 controllers. When CPT instruction is ex-
by another. ecuted, then copy, arithmetic, logical, or conversion op-
eration residing in the expression field of this instruction
Math instructions use the contents of two words or is performed and the result is sent to the destination. The
registers and perform the desired function. The PLC in- execution time of a CPT instruction is longer than that of
structions for data manipulation (data transfer and data a single arithmetic operation and uses more instruction
compare) are used with the math symbols to perform words.
math functions. Math instructions are all output instruc-
tions. Figure 11-1 shows the Compute/Math menu tab for
the SLC 500 PLC and its associated RSLogix software. 11.2 Addition Instruction
The commands can be summarized as follows: Most math instructions take two input values, perform
CPT (Compute)—Evaluates an expression and stores the specified arithmetic function, and output the result
the result in the destination. to an assigned memory location. For example, the ADD
instruction performs the addition of two values stored in
ADD (add)—Adds source A to source B and stores
the referenced memory locations. How these values are
the result in the destination.
accessed depends on the controller. Figure 11-3 shows the
SUB (Subtract)—Subtracts source B from source A
and stores the result in the destination.
MUL (Multiply)—Multiplies source A by source B Input Ladder logic program
and stores the result in the destination. L1 SW
ADD
SW ADD
Source A N7:0
25
CPT ADD SUB MUL DIV SQR NEG TOD FRD Source B N7:1
50
Destination N7:2
Input/Output Compare Compute/Math Move/Logic
75

Figure 11-1 Compute/Math menu tab. Figure 11-3 SLC 500 ADD instruction.

Math Instructions Chapter 11 227

pet10882_ch11_226-241.indd 227 7/27/10 4:10 PM


ADD instruction used with the SLC 500 controllers. The come on when the sum of the counts from the two coun-
operation of the logic rung can be summarized as follows: ters is equal to or greater than 350. The operation of the
program can be summarized as follows:
• When input switch SW is closed the rung will be
true. • Source A of the ADD instruction is addressed to
• The value stored at the source A address, N7:0 (25), store the accumulated value of counter C5:0.
is added to the value stored at the source B address, • Source B of the ADD instruction is addressed to
N7:1 (50). store the accumulated value of counter C5:1.
• The answer (75) is stored at the destination address • The value at source A is added to the value at source
N7:2. B, and the result (answer) is stored at destination
• Source A and source B can be either values or address N7:1.
addresses that contain values, but A and B cannot • Source A of the GEQ (greater than or equal) instruc-
both be constants. tion is addressed to store the value of the destination
The program of Figure 11-4 illustrates how the ADD address N7:1.
instruction can be used to add the accumulated counts of • Source B of the GEQ instruction contains the con-
two up-counters. This application requires a pilot light to stant value of 350.

Inputs Ladder logic program Output


L1 L2
S1
CTU
COUNT-UP COUNTER CU
S1 PL1
Counter C5:0
DN
Preset 350
Accumulated 0 125
S2
CTU
COUNT-UP COUNTER CU
S2 Counter C5:1
DN
Preset 350
Accumulated 0 100

ADD
ADD
Source A C5:0.ACC
250
Reset Source B C5:1.ACC

Destination N7:1

PL1
GEQ
GREATER THAN OR EQUAL
Source A N7:1

Source B 350

Reset C5:0
RES

C5:1
RES

Figure 11-4 Counter program that uses the ADD instruction.

228 Chapter 11 Math Instructions

pet10882_ch11_226-241.indd 228 7/27/10 4:10 PM


Status Table
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
S2:0/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
S2:1/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
S2:2/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
S2:3/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
S2:4/ 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1
S2:5/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Address S2:0 Table: S2:Status

Figure 11-5 Processor status file S2.

• The GEQ instruction and PL1 output will be true Input Ladder logic program
whenever the accumulated values in the two counters L1 SW
SUB
are equal to or greater than the constant value 350. SUBTRACT
SW
• A reset button is provided to reset the accumulated Source A N7:10
count of both counters to zero. 520
Source B N7:05
When performing math functions, care must be taken 322
Destination N7:20
to ensure that values remain in the range that the data
198
table or file can store; otherwise, the overflow bit will be
set. The arithmetic status bits for the SLC 500 controller Figure 11-6 SLC 500 SUB (subtract) instruction.
are found in word 0, bits 0 to 3 of the processor status
file S2 (Figure 11-5). After an instruction is executed, the
arithmetic status bits in the status file are updated. The • The answer (198) is stored at the destination ad-
description of each bit can be summarized as follows: dress, N7:20.
• Source A and source B can be either values or ad-
Carry (C)—Address S2:0/0, is set to 1 when there is
dresses that contain values, but A and B cannot both
a carry in the ADD instruction or a borrow in the SUB
be constants.
instruction.
Overflow (O)—Address S2:0/1, is set to 1 when the The program of Figure 11-7 shows how the SUB func-
result is too large to fit in the destination register. tion can be used to indicate a vessel overfill condition.
Zero (Z)—Address S2:0/2, is set to 1 when the result This application requires an alarm to sound when a supply
of the subtract instruction is zero. system leaks 5 lb or more of raw material into the ves-
sel after a preset weight of 500 lb has been reached. The
Sign (S)—Address S2:0/3, is set to 1 when the result
operation of the program can be summarized as follows:
is a negative number.
• When the start button is pressed, the fill solenoid
(rung 1) and filling indicating light (rung 2) are turned
11.3 Subtraction Instruction on and raw material is allowed to flow into the vessel.
The SUB (subtract) instruction is an output instruction that • The vessel has its weight monitored continuously by
subtracts one value from another and stores the result in the PLC program (rung 3) as it fills.
the destination address. When rung conditions are true, the • When the weight reaches 500 lb, the fill solenoid is
subtract instruction subtracts source B from source A and de-energized and the flow is cut off.
stores the result in the destination. Figure 11-6 shows the
• At the same time, the filling pilot light indicator is
SUB instruction used with the SLC 500 controllers. The
turned off and the full pilot light indicator (rung 3)
operation of the logic rung can be summarized as follows:
is turned on.
• When input switch SW is closed the rung will be true. • Should the fill solenoid leak 5 lb or more of raw
• The value stored at the source B address, N7:05 material into the vessel, the alarm (rung 5) will en-
(322), is subtracted from the value stored at the ergize and stay energized until the overflow level is
source A address, N7:10 (520). reduced below the 5-lb overflow limit.

Math Instructions Chapter 11 229

pet10882_ch11_226-241.indd 229 7/27/10 4:10 PM


Inputs Ladder logic program Outputs
Fill
L1 Stop Start Full solenoid L2

1
Fill
Start Fill solenoid
solenoid
Start

Stop Fill
solenoid Full Filling
2

Stop
GEQ Full
3 GREATER THAN OR EQUAL Filling
Source A Ι:012

Source B 500
Ι:012 Full

Weight (All 16 bits)


transducer Full
SUB
4 SUBTRACT Alarm
Source A Ι:012

Source B 500

Destination N7:1

Alarm
GEQ
5 GREATER THAN OR EQUAL
Source A N7:1

Source B 5

Figure 11-7 Vessel overfill alarm program.

11.4 Multiplication Instruction • The data in source A (constant 20) will be multi-
plied by the data in source B (accumulated value of
The multiply (MUL) instruction is an output instruction counter C5:10).
that multiplies two values and stores the result in the des-
• The resultant answer is placed in the destination
tination address. Figure 11-8 shows the MUL instruction
N7:2.
used with the SLC 500 controllers. The operation of the
logic rung can be summarized as follows: • Similar to previous math instructions, source A and
B in multiplication instructions can be values (con-
• When input switch SW is closed the rung will be stants) or addresses that contain values, but A and B
true. cannot both be constants.
Input Ladder logic program The program of Figure  11-9 is an example of how
L1 SW MUL instruction calculates the product of two sources.
MUL
MULTIPLY
The operation of the program can be summarized as
SW
Source A 20 follows:
Source B C5:10.ACC • When input switch SW is closed the MUL instruc-
tion is executed.
Destination N7:2
• The value stored in source A, address N7:1 (123),
is then multiplied by the value stored in source B,
Figure 11-8 SLC 500 MUL (multiply) instruction. address N7:2(61).

230 Chapter 11 Math Instructions

pet10882_ch11_226-241.indd 230 7/27/10 4:10 PM


Input Ladder logic program Output
L1 L2
SW
SW MUL
MULTIPLY PL1
Source A N7:1
123
Source B N7:2
61
Destination N7:3
7503

PL1
EQU
EQUAL
Source A N7:3
7503
Source B 7503

Figure 11-9 MUL instruction used to calculate the product of two sources.

• The product (7503) is placed into destination word of the DIV instruction. The operation of the logic rung
N7:3. can be summarized as follows:
• As a result, the equal instruction becomes true, turn- • When input switch SW is closed the rung will be true.
ing output PL1 on.
• The data in source A (the accumulated value of
The program of Figure 11-10 is an example of how the counter C5:10) is then divided by the data in source B
MUL instruction is used as part of an oven temperature (the constant 2).
control program. The operation of the program can be • The result is placed in the destination N7:3.
summarized as follows: • If the remainder is 0.5 or greater, a roundup occurs
• The PLC calculates the upper and lower deadband, in the integer destination.
or off/on limits, about the set-point. • The value stored in the math register consists of the
• Upper and lower temperature limits are set automati- unrounded quotient (placed in the most significant
cally at 61 percent regardless of the set-point value. word) and the remainder (placed in the least signifi-
• Set-point temperature is adjusted by means of the cant word).
thumbwheel switch. • Some PLCs support the use of floating-decimal as
• The analog thermocouple interface module is used well as integer (whole number) values. As an exam-
to monitor the current temperature of the oven. ple, 10 divided by 3 may be expressed as 3.333333
(floating-decimal notation) or 3 with a remainder
• In this example, the set-point temperature is 400°F.
of 1.
• Therefore, the electric heaters will be turned on when
the temperature of the oven drops to less than 396°F The program of Figure 11-12 is an example of how the
and stay on until the temperature rises above 404°F. DIV instruction calculates the integer value that results
• If the set-point is changed to 100°F, the deadband from dividing source A by source B. The operation of the
remains at 61 percent, with the lower limit being program can be summarized as follows:
99°F and the upper limit being 101°F. • When input switch SW is closed the DIV instruc-
• The number stored in word N7:1 represents the tion is executed.
upper temperature limit, and the number stored in • The value stored in source A, address N7:0 (120),
word N7:2 represents the lower limit. is then divided by the value stored in source B,
address N7:1 (4).
11.5 Division Instruction • The answer, 30, is placed in the destination address
The divide (DIV) instruction divides the value in source A N7:5.
by the value in source B and stores the result in the desti- • As a result, the equal instruction becomes true, turn-
nation and math register. Figure 11-11 shows an example ing output PL1 on.

Math Instructions Chapter 11 231

pet10882_ch11_226-241.indd 231 7/27/10 4:10 PM


Inputs Ladder logic program Outputs
L1 L2
MUL
ON/OFF MULTIPLY Heater
Source A Ι:012
400
Source B 0.0100000
TWS Destination N7:0 PL1
1 4
2 Ι:012
ADD
3 ADD
Source A Ι:012
4 0 0 400
Source B N7:0
4
High limit Destination N7:1
404

SUB PL2
Ι:013 SUBTRACT
Source A Ι:012
400
Thermocouple Source B N7:0
input 4
Low limit Destination N7:2
396

PL1
LES
LESS THAN
Source A Ι:013
0
Source B N7:2
396

PL 2
GRT
GREATER THAN
Source A Ι:013
0
N7:1
Source B 404

ON/OFF PL1 PL2 Heater

Heater

Figure 11-10 The MUL instruction used as part of a temperature control program.

Input Ladder logic program The program of Figure  11-13 is an example of how
L1 SW the DIV function is used as part of a program to convert
DIV
DIVIDE
Celsius temperature to Fahrenheit. The operation of the
SW
Source A C5:10.ACC program can be summarized as follows:
Source B 2 • The thumbwheel switch connected to the input
module indicates Celsius temperature.
Destination N7:3
• The program is designed to convert the recorded
Celsius temperature in the data table to Fahrenheit
Figure 11-11 SLC 500 DIV (divide) instruction. values for display.

232 Chapter 11 Math Instructions

pet10882_ch11_226-241.indd 232 7/27/10 4:10 PM


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-12 DIV instruction used to calculate the value that results
from dividing source A by source B.

L1
Input Ladder logic program Output
L2
• Next, the DIV instruction divides 5 into the 540 and
stores the answer (108) in address N7:1.
MUL • Finally, the ADD instruction adds 32 to the value of
1 MULTIPLY
Source A Ι:012 108 and stores the sum (140) in address O:13.
2 Ι:012 60 O:013
Source B 9 • Thus 60°C 5 140°F.
3
Thumbwheel Destination N7:0 LED
switch
540
Display
11.6 Other Word-Level Math
DIV Instructions
0 6 0 DIVIDE 14 0
Source A N7:0 The program of Figure 11-14 is an example of the square
Celsius 540 Fahrenheit root (SQR) instruction. The operation of the logic rung
Source B 5
can be summarized as follows:
Destination N7:1
108 • When input switch SW is closed the SQR instruc-
ADD tion is executed.
ADD
Source A N7:1 • The number whose square root we want to deter-
108 mine (144) is placed in the source.
Source B 32
• The function calculates the square root and places it
Destination O:013
140 (12) in the destination.
• If the value of the source is negative, the instruction
Figure 11-13 Program for converting Celsius temperature will store the square root of the absolute (positive)
to Fahrenheit.
value of the source at the destination.

• The following conversion formula forms the basis Input Ladder logic program
for the program: L1 SW
SQR

(5 )
9 × C 1 32
F 5 __ SW SQUARE ROOT
Source A N7:101
144
• In this example, a current temperature reading of Destination N7:105
60°C is assumed. 12

• The MUL instruction multiplies the temperature (√144 = 12)


(60°C) by 9 and stores the product (540) in address
N7:0. Figure 11-14 SLC 500 SQR (square root) instruction.

Math Instructions Chapter 11 233

pet10882_ch11_226-241.indd 233 7/27/10 4:10 PM


Input Ladder logic program Input Ladder logic program
L1 SW L1 SW
NEG TOD
SW NEGATE SW TO BCD
Source A N7:52 Source N7:23
101 10
Destination N7:53 Destination O:20
–101 16

Figure 11-15 SLC 500 NEG (negate) instruction. Figure 11-17 SLC 500 TOD (convert to BCD) instruction.

The program of Figure  11-15 is an example of the Figure 11-17 is an example of the TOD instruction. The
negate (NEG) instruction. This math function changes operation of the logic rung can be summarized as follows:
the sign of the source value from positive to negative.
• When input switch SW is closed the TOD instruc-
The operation of the logic rung can be summarized as
tion is executed.
follows:
• The binary bit pattern at the source address N7:23 is
• When input switch SW is closed the NEG instruc- converted into a BCD bit pattern of the same deci-
tion is executed. mal value at the destination address O:20.
• The positive value 101 stored at the source address • The source displays the value 10, which is the
N7:52 is negated to 2101 and stored in destination correct decimal value; however, the destination
address N7:53. displays the value 16.
• Positive numbers will be stored in straight binary • The processor interprets all bit patterns as binary;
format, and negative numbers will be stored as 2’s therefore the value 16 is the binary interpretation of
complement. the BCD bit pattern.
The program of Figure 11-16 is an example of the clear • The bit pattern for 10 BCD is the same as the bit
(CLR) instruction. The operation of the logic rung can be pattern for 16 binary.
summarized as follows:
The convert from BCD (FRD) instruction is used to con-
• When input switch SW is closed the CLR instruc- vert binary-coded decimal (BCD) values to integer values.
tion is executed. This instruction could be used to convert data from a BCD
• Upon execution it sets all bits of a word to zero. external source, such as a BCD thumbwheel switch, to the
• In this example it changes the value of all bits stored binary format in which the processor operates. The program
in the destination address N7:22 to 0. of Figure 11-18 is an example of the FRD instruction. The
operation of the logic rung can be summarized as follows:
The convert to BCD (TOD) instruction is used to
convert 16-bit integers into binary-coded decimal • When input switch SW is closed the FDR instruc-
(BCD) values. This instruction could be used when tion is executed.
transferring data from the processor (which stores data • The BCD bit pattern stored at the source address
in binary format) to an external device, such as an LED I:30 is converted into a binary bit pattern of the same
display, that functions in BCD format. The program of decimal value at the destination address, N7:24.

Input Ladder logic program


Input Ladder logic program L1 SW
L1 FRD
SW
CLR SW FROM BCD
SW CLEAR Source I:30
Destination N7:22 16
0000000000000000 Destination N7:24
10

Figure 11-18 SLC 500 FRD (convert from BCD)


Figure 11-16 SLC 500 CLR (clear) instruction. instruction.

234 Chapter 11 Math Instructions

pet10882_ch11_226-241.indd 234 7/27/10 4:10 PM


Input Ladder logic program Input Ladder logic program
L1 SW L1 SW
SCL FAL
SW SCALE SW FILE ARITH/LOGICAL EN
Source N7:0 Control R6:1 DN
100 Length 4
Rate (/10000) 25000 Position 0 ER
Mode All
Offset 127 Destination #N7:100

Destination N7:1 Expression


377 #N7:25 + #N7:50

Figure 11-19 SLC 500 SCL (scale) instruction. #N7:25 #N7:50 #N7:100
N7:25 25 + N7:50 50 = N7:100 75
234 + 22 256
The scale data (SCL) instruction is used to allow very 1256 + 456 1712
large or very small numbers to be enlarged or reduced by N7:28 77 + N7:53 100 = N7:103 177
the rate value. When rung conditions are true, this instruc-
Figure 11-20 SLC 500 file add function of the FAL
tion multiplies the source by a specified rate. The rounded
instruction.
result is then added to an offset value and placed in the
destination. The program of Figure 11-19 is an example
of the SCL instruction. The operation of the logic rung
can be summarized as follows: data in file address N7:25 to the data stored in file
• When input switch SW is closed the SCL instruc- address N7:50 and store the result in file address
tion is executed. N7:100.
• The number 100 stored at the source address, N7:0, • The rate per scan is set at All, so the instruction
is multiplied by 25,000, divided by 10,000, and goes to completion in one scan.
added to 127. The program of Figure 11-21 is an example of the file
• The result, 377, is placed in the destination address, subtract function of the FAL instruction. The operation of
N7:1. the logic rung can be summarized as follows:
You can use SCL instruction to scale data from your • When input switch SW is closed the rung goes true
analog module and bring it into the limits prescribed by the and the processor subtracts a program constant
process variable or another analog module. For instance, (255) from each word of file address N10:0 and
you can use the SCL instruction to convert a 4–20 mA
input signal to a PID process variable, or to scale an ana-
log input to control an analog output.
Input Ladder logic program
L1
11.7 File Arithmetic Operations SW
FAL
SW FILE ARITH/LOGICAL EN
File arithmetic functions include file add, file subtract, Control R6:5 DN
file multiply, file divide, file square root, file convert from Length 4
BCD, and file convert to BCD. The file arithmetic and Position 0 ER
logic (FAL) instruction can combine an arithmetic opera- Mode 2
Destination #N7:255
tion with file transfer. The arithmetic operations that can
be implemented with the FAL are ADD, SUB, MULT, Expression
DIV, and SQR. #N10:0 – 255
The file add function of the FAL instruction can be
#N10:0 #N7:255
used to perform addition operations on multiple words.
The program of Figure 11-20 is an example of the file add N10:0 680 – 255 = N7:255 425
950 695
function of the FAL instruction. The operation of the logic 20 –235
rung can be summarized as follows: N10:3 100 = N7:258 –155

• When input switch SW is closed the rung goes true Figure 11-21 SLC 500 file subtract function of the FAL
and the expression tells the processor to add the instruction.

Math Instructions Chapter 11 235

pet10882_ch11_226-241.indd 235 7/27/10 4:10 PM


Input Ladder logic program Input Ladder logic program
L1 SW L1 SW
FAL FAL
SW FILE ARITH/LOGICAL EN SW FILE ARITH/LOGICAL EN
Control R6:8 DN Control R6:7 DN
Length 4 Length 4
Position 0 ER Position 1 ER
Mode All Mode Incremental
Destination #N7:500 Destination F8:200

Expression Expression
#N7:330 * N7:23 #F8:20 / #F8:100

#F8:20 #F8:100 F8:200


#N7:330 N7:23 #N7:500
F8:20 100 ÷ F8:100 1000 = F8:200 0.1
N7:330 20 * N7:23 100 = N7:500 2000
25 2
240 24000
1.33 1.5
–78 –7800
F8:23 586 F8:103 3
N7:333 321 = N7:503 32100
Figure 11-23 SLC 500 file divide function of the FAL
Figure 11-22 SLC 500 file multiply function of the FAL
instruction.
instruction.

stores the result at the destination file address, • The rate per scan is set at All, so the instruction
N7:255. goes to completion in one scan.
• The rate per scan is set at 2, so it will take 2 scans The program of Figure 11-23 is an example of the file
from the moment the instruction goes true to com- divide function of the FAL instruction. The operation of
plete its operation. the logic rung can be summarized as follows:
The program of Figure 11-22 is an example of the file • When input switch SW is closed the rung goes true
multiply function of the FAL instruction. The operation of and the data in file address F8:20 is divided by the
the logic rung can be summarized as follows: data in file address F8:100, with the result stored in
• When input switch SW is closed the rung goes true element address F8:200.
and the data in file address N7:330 is multiplied by • The mode is Incremental, so the instruction operates
the data in element address N7:23, with the result on one set of elements for each false-to-true transi-
stored at the destination file address N7:500. tion of the instruction.

236 Chapter 11 Math Instructions

pet10882_ch11_226-241.indd 236 7/27/10 4:10 PM


CHAPTER 11 REVIEW QUESTIONS

1. Explain the function of math instructions as applied destination if N7:3 contains a value of 15 and N7:4
to the PLC. contains a value of 4?
2. Name the four basic math functions performed by 9. With reference to the instruction of Figure 11-28,
PLCs. what is the value of the number stored at N7:20 if
3. What standard format is used for PLC math N7:3 contains a value of 2345?
instructions? 10. With reference to the instruction of Figure 11-29,
4. Would math instructions be classified as input or what will be the value of each of the bits in word
output instructions? B3:3 when the rung goes true?
5. With reference to the instruction of Figure 11-24, 11. With reference to the instruction of Figure 11-30,
what is the value of the number stored at source B what is the value of the number stored at N7:101?
if N7:3 contains a value of 60 and N7:20 contains a 12. With reference to the instruction of Figure 11-31,
value of 80? list the values that will be stored in file #N7:10
6. With reference to the instruction of Figure 11-25, when the rung goes true.
what is the value of the number stored at the desti-
nation if N7:3 contains a value of 500?
NEG
7. With reference to the instruction of Figure 11-26, NEGATE
what is the value of the number stored at the des- Source N7:3
tination if N7:3 contains a value of 40 and N7:4 Destination N7:20

contains a value of 3?
Figure 11-28 Instruction for Question 9.
8. With reference to the instruction of Figure 11-27,
what is the value of the number stored at the CLR
CLEAR
ADD Destination B3:3
ADD 0000111100001111
Source A N7:3
Source B N7:4
Destination N7:20 Figure 11-29 Instruction for Question 10.

Figure 11-24 Instruction for Question 5. SQR


SQUARE ROOT
SUB Source A N7:101
SUBTRACT Destination N7:105
Source A N7:3 4
Source B 338
Destination N7:20 Figure 11-30 Instruction for Question 11.

Figure 11-25 Instruction for Question 6. FAL


FILE ARITH/LOGICAL EN
DIV Control R6:0 DN
DIVIDE Length 5
Source A N7:3 Position 0 ER
Source B N7:4 Mode All
Destination N7:20 Destination #N7:10
Expression
#N11:0  10
Figure 11-26 Instruction for Question 7.
File #N11:0
MUL
MULTIPLY 328
Source A N7:3 150
Source B N7:4 10
Destination N7:20 32
0

Figure 11-27 Instruction for Question 8. Figure 11-31 Instruction for Question 12.

Math Instructions Chapter 11 237

pet10882_ch11_226-241.indd 237 7/27/10 4:10 PM


CHAPTER 11 PROBLEMS

1. Answer each of the following with reference to the (3) N7:1


counter program shown in Figure 11-32. (4) Source B of the GEQ instruction
a. Assume the accumulated count of counters C5:0 d. Will output PL1 be energized at this point?
and C5:1 to be 148 and 36, respectively. State Why?
the value of the number stored in each of the fol- 2. Answer each of the following with reference to the
lowing words at this point: overfill alarm program shown in Figure 11-33.
(1) C5:0.ACC a. Assume that the vessel is filling and has reached
(2) C5:1.ACC the 300-lb point. State the status of each of the
(3) N7:1 logic rungs (true or false) at this point.
(4) Source B of the GEQ instruction b. Assume that the vessel is filling and has reached
b. Will output PL1 be energized at this point? the 480-lb point. State the value of the number
Why? stored in each of the following words at this
c. Assume the accumulated count of counters C5:0 point:
and C5:1 to be 250 and 175, respectively. State (1) I:012
the value of the number stored in each of the fol- (2) N7:1
lowing words at this point: c. Assume that the vessel is filled to a weight of
(1) C5:0.ACC 502 lb. State the status of each of the logic rungs
(2) C5:1.ACC (true or false) for this condition.

Inputs Ladder logic program Output


L1 L2
S1
CTU
COUNT-UP COUNTER CU
S1 PL1
Counter C5:0
DN
Preset 350
Accumulated 0

S2 S2
CTU
COUNT-UP COUNTER CU
Counter C5:1
DN
Preset 350
Reset Accumulated 0

ADD
ADD
Source A C5:0.ACC

Source B C5:1.ACC

Destination N7:1
PL1
GEQ
GREATER THAN OR EQUAL
Source A N7:1

Source B 350

Reset C5:0
RES

C5:1
RES

Figure 11-32 Program for Problem 1.

238 Chapter 11 Math Instructions

pet10882_ch11_226-241.indd 238 7/27/10 4:10 PM


Inputs Ladder logic program Outputs
Fill
L1 Stop Start Full solenoid L2

1
Fill
Start Fill solenoid
solenoid

Fill Filling
Stop solenoid Full Filling
2

Full
GEQ Full
Ι:012
3 GREATER THAN OR EQUAL
Source A Ι:012
Weight (All 16 bits) Alarm
transducer Source B 500

Full
SUB
4 SUBTRACT
Source A Ι:012

Source B 500

Destination N7:1

Alarm
GEQ
5 GREATER THAN OR EQUAL
Source A N7:1

Source B 5

Figure 11-33 Program for Problem 2.

d. Assume that the vessel is filled to a weight of c. Assume that the set-point temperature is 600°F
510 lb. State the value of the number stored in and the thermocouple input module indicates a
each of the following words for this condition: temperature of 608°F. What is the status (energized
(1) I:012 or not energized) of each of the following outputs?
(2) N7:1 (1) PL1
e. With the vessel filled to a weight of 510 lb, state (2) PL2
the status of each of the logic rungs (true or (3) Heater
false). 4. With reference to the Celsius to Fahrenheit con-
3. Answer the following with reference to the tem- version program shown in Figure 11-35, state the
perature control program shown in Figure 11-34. value of the number stored in each of the following
a. Assume that the set-point temperature is 600°F. words for a thumbwheel setting of 035:
At what temperature will the electric heaters be a. I:012
turned on and off? b. N7:0
b. Assume that the set-point temperature is 600°F c. N7:1
and the thermocouple input module indicates a d. O:013
temperature of 590°F. What is the value of the
number stored in each of the following words at 5. Design a program that will add the values stored
this point? at N7:23 and N7:24 and store the result in N7:30
(1) I:012 whenever input A is true, and then, when input B is
(2) I:013 true, will copy the data from N7:30 to N7:31.
(3) N7:0 6. Design a program that will take the accumulated
(4) N7:1 value from TON timer T4:1 and display it on a
(5) N7:2 4-digit, BCD format set of LEDs. Use address

Math Instructions Chapter 11 239

pet10882_ch11_226-241.indd 239 7/27/10 4:10 PM


Inputs Ladder logic program Outputs
L1 L2
MUL
ON/OFF MULTIPLY Heater
Source A Ι:012
400
Source B 0.0100000
TWS
Destination N7:0
1
4
2 Ι:012 PL1
3 ADD
ADD
Source A Ι:012
400
Source B N7:0
Ι:013 4 PL2
Destination N7:1
404
Thermocouple
input
SUB
SUBTRACT
Source A Ι:012
400
Source B N7:0
4
Destination N7:2
396

PL1
LES
LESS THAN
Source A Ι:013
0
Source B N7:2
396

PL 2
GRT
GREATER THAN
Source A Ι:013
0
N7:1
Source B 404

ON/OFF PL1 PL2 Heater

Heater

Figure 11-34 Program for Problem 3.

O:023 for the LEDs. Include the provision to • Multiply the value in N7:3 by 25 and store the
change the preset value of the timer from a set of result in N7:4.
4-digit BCD thumbwheels when input A is true. • Divide the value in N7:4 by 35 and store the
Use address I:012 for the thumbwheels. result in F8:0.
7. Design a program that will implement the follow- 8. a. There are three part conveyor lines (1-2-3) feed-
ing arithmetic operation: ing a main conveyor. Each of the three conveyor
• Use a MOV instruction and place the value 45 in lines has its own counter. Construct a PLC pro-
N7:0 and 286 in N7:1. gram to obtain the total count of parts on the
• Add the values together and store the result in N7:2. main conveyor.
• Subtract the value in N7:2 from 785 and store the b. Add a timer to the program that will update the
result in N7:3. total count every 30 s.

240 Chapter 11 Math Instructions

pet10882_ch11_226-241.indd 240 7/27/10 4:10 PM


Input Ladder logic program Output 10. With reference to the math instruction program
L1 L2
Fahrenheit
shown in Figure 11-37, when the input goes
Celsius MUL true, what value will be stored at each of the
1 MULTIPLY
Source A Ι:012 following?
2 Ι:012 O:013
a. N7:3
Source B 9
3 b. N7:4
Thumbwheel Destination N7:0 LED c. N7:5
switch Display
DIV d. N7:6
DIVIDE
Source A N7:0 11. Two part conveyor lines, A and B, feed a main
conveyor line M. A third conveyor line, R,
Source B 5
removes rejected parts a short distance away from
Destination N7:1 the main conveyor. Conveyors A, B, and R have
ADD parts counters connected to them. Construct a PLC
ADD program to obtain the total parts output of main
Source A N7:1
conveyor M.
Source B 32
12. A main conveyor has two conveyors, A and B,
Destination O:013 feeding it. Feeder conveyor A puts six-packs of
canned soda on the main conveyor. Feeder con-
Figure 11-35 Program for Problem 4.
veyor B puts eight-packs of canned soda on the
main conveyor. Both feeder conveyors have coun-
9. With reference to math instruction program shown ters that count the number of packs leaving them.
in Figure 11-36, when the input goes true, what Construct a PLC program to give a total can count
value will be stored at each of the following? on the main conveyor.
a. N7:3
b. N7:5
c. F8:1
Input
SUB
Input SUBTRACT
Source A N7:1
ADD 80
Source B N7:2
ADD 20
Source A N7:1 Destination N7:3
208
Source B N7:2 MUL
114
Destination N7:3 MULTIPLY
Source A N7:3
MUL Source B 2

MULTIPLY Destination N7:4


Source A N7:3
ADD
Source B N7:4 ADD
4 Source A N7:4
Destination N7:5
Source B 24
DIV
Destination N7:5
DIVIDE
Source A N7:5 SQR
SQUARE ROOT
Source B 5.000000 Source N7:5

Destination F8:1 Destination N7:6

Figure 11-36 Program for Problem 9. Figure 11-37 Program for Problem 10.

Math Instructions Chapter 11 241

pet10882_ch11_226-241.indd 241 7/27/10 4:10 PM

You might also like