Page 255 - Programmable Logic Controllers, Fifth Edition - Mobile version
P. 255
L1 Input Temp_Convert Ladder logic program L1 Input SW Ladder logic program
CPT ADD
Compute
Temp_Convert SW ADD
Dest Result Source A N7:0
60 25
Source B N7:1
Expression (N7:5-32)*5/9 50
Destination N7:2
75
Figure 11-3 Compute instruction used to convert from
Fahrenheit to Celsius.
Figure 11-4 SLC 500 ADD instruction.
instruction for the SLC 500 and Logix 5000 processors • The value stored at the source A address, N7:0 (25),
operate in the same manner. This operation of the rung is added to the value stored at the source B address,
can be summarized as follows: N7:1 (50).
• The arithmetic operation [°C = (°F − 32) × (5/9)] • The answer (75) is stored at the destination address
is defined in the Expression. N7:2.
• The compute operation is performed whenever the • Source A and source B can be either values or
Temp_Convert input tag is true. addresses that contain values, but A and B cannot
• When the CPT instruction is executed the result of both be constants.
the equation is put into the DEST tag name Result. The program of Figure 11-5 illustrates how the ADD
• In this example a temperature of 140°F is pro- instruction can be used to add the accumulated counts of
grammed into N7:5 of the Expression and the com- two up-counters. This application requires a pilot light to
puted value of 60°C appears in the Result. come on when the sum of the counts from the two coun-
• The CPT has its own instruction set consisting of ters is equal to or greater than 350. The operation of the
commands, or operators, that can be embedded in program can be summarized as follows:
a mathematical expression. These commands range • Source A of the ADD instruction is addressed to the
from add and subtract to BCD conversion and abso- accumulated value of counter C5:0.
lute values. • Source B of the ADD instruction is addressed to the
• The operations you write into the expression are accumulated value of counter C5:1.
performed by the instruction in a prescribed order,
not necessarily the order you write them. The first • The value at source A is added to the value at source
order is parentheses so you can override the order of B, and the result (answer) is stored at destination
operation by grouping terms within parentheses. This address N7:1.
forces the instruction to perform an operation within • Source A of the GEQ (greater than or equal) instruc-
the parentheses ahead of other operations. In this case tion is addressed to the value of the destination ad-
parentheses were used to assure that the subtraction dress N7:1.
was done before the multiplication and division. • Source B of the GEQ instruction contains the con-
stant value of 350.
• The GEQ instruction and PL1 output will be true
11.2 Addition Instruction whenever the accumulated sum of the values in the
Most math instructions take two input values, perform two counters is equal to or greater than the constant
the specified arithmetic function, and output the result value 350.
to an assigned memory location. For example, the ADD • A reset button is provided to reset the accumulated
instruction performs the addition of two values stored in count of both counters to zero.
the referenced memory locations. How these values are When performing math functions, care must be taken
accessed depends on the controller. Figure 11-4 shows the to ensure that values remain in the range that the data
ADD instruction used with the SLC 500 controllers. The table or file can store; otherwise, the overflow bit will be
operation of the logic rung can be summarized as follows:
set. The arithmetic status bits for the SLC 500 controller
• When input switch SW is closed the rung will be are found in word 0, bits 0 to 3 of the processor status
true. file S2 (Figure 11-6). After an instruction is executed, the
236 Chapter 11 Math Instructions
pet73842_ch11_234-251.indd 236 03/11/15 4:07 PM