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