Post on 27-Jun-2015
description
transcript
1Northampton Community College
Arithmetic Instructions
Chapter 06 and supplemental material
2Northampton Community College
Arithmetic Instructions
Mnemonic Name Mnemonic NameADD Addition SWP Swap
SUB Subtraction ASN Arc Sine
MUL Multiply ACS Arc Cosine
DIV Divide ATN Arc Tangent
DDV Double Divide (SLC500) COS Cosine
CLR Clear LN Natural Log
SQRSquare Root(SQRT, Siemens)
LOG Log to the Base 10
SCP Scale with Parameters SIN Sine
SCL Scale TAN Tangent
ABS Absolute Value XPYX to the Power of Y(EXPT, Siemens)
CPT Compute NEG Negate
We will only be learning about the instruction shown in red
3Northampton Community College
Allen Bradley Arithmetic Instructions Math instructions are output instructions, therefore they are
placed against the right power rail.
The ControlLogix processor allows math instructions to be placed in series on the right side of the rung. (Not in this course)
The ADD, SUB, MUL and DIV instructions have three parameters: Source A Source B Destination
RSLogix 500 and LogixPro ControlLogix
4Northampton Community College
Basic Arithmetic Instructions The ADD, SUB, MUL and DIV instructions have three parameters:
Source A Source B Destination
These parameters have the following rules.1. Source A and Source B
In the SLC500 can be any valid word level address of type INT or FLOAT. In LogixPro can be any valid word level address of type INT. In ControlLogix a tag of type SINT, INT, DINT or REAL.
2. Source A can be a program constant and Source B In the SLC500 can be any valid word level address of type INT or FLOAT. In LogixPro can be any valid word level address of type INT. In ControlLogix a tag of type SINT, INT, DINT or REAL
3. Source B can be a program constant and Source A In the SLC500 can be any valid word level address of type INT or FLOAT. In LogixPro can be any valid word level address of type INT. In ControlLogix a tag of type SINT, INT, DINT or REAL.
4. Source A and Source B cannot both be program constants.5. The Destination is always
In the SLC500 a valid word level address of type INT or FLOAT . In LogixPro a valid word level address of type INT. In ControlLogix a tag of type SINT, INT, DINT or REAL.
5Northampton Community College
Siemens Arithmetic Instructions The Siemens processor allows math instructions to be
placed in series on the rung.
The ADD, SUB, MUL and DIV instructions have at least six parameters: Instruction Data Type Enable (EN) Enable Out (ENO) OUT IN1, IN2, (INn when the yellow star is present)
6Northampton Community College
Arithmetic Instructions
Arithmetic instructions can be conditional or unconditional: Conditional – Input logic determines when the instruction executes. Unconditional – Instruction executes every scan.
Conditional
0 AddSource A Vessel_A_Level 0Source B Vessel_B_Level 0Dest Total_of_Batch 0
ADD
Unconditional
7Northampton Community College
Allen Bradley Addition (ADD) Instruction The ADD instructions adds the value in Source A to the value in Source B
and stores the sum in the Destination.
0 AddSource A Vessel_A_Level 367Source B Vessel_B_Level 780Dest Total_of_Batch 1147
ADD
sumsignedbit
BatchofTotalLevelBVesselLevelAVessel
nDestinatioSourceBSourceA
321147780367
______
signedbitisroLogixP
sumsignedbit
NNN
nDestinatioBSourceASource
32
16850650200
1:72:70:7
8Northampton Community College
SLC500 Arithmetic Status Bits There are four arithmetic status bits. All of the arithmetic instructions share the
same four status bits. These bits will contain the status of the last math instruction that is executed. These bits are located in the Status File (S2) and are described as follows (Not
available in the LogixPro Simulator):
Status Bit Name Description
S:0/0 Carry (C)Bit is set to a (1) if a carry is generated; otherwise it is cleared (0). (It is for you to determine how this bit works)
S:0/1 Overflow (V)
Bit is set to a (1) if the result or value of the math instruction does not fit into the designated destination. Value is smaller than -32,768 or larger than 32,767; otherwise it is cleared (0).
S:0/2 Zero (Z)Bit is set to a (1) if the result or value after a math, move or logic instruction is zero; otherwise it is cleared (0).
S:0/3 Sign (S)
Bit is set to a (1) if the result or value after a math, move or logic instruction is a negative (less than zero) value; otherwise it is cleared (0). This bit is not to be confused with the sign bit (15) of a 16-bit word.
9Northampton Community College
ControlLogix Arithmetic Status Bits There are four arithmetic status bits. All of the arithmetic instructions share the
same four status bits. These bits will contain the status of the last math instruction that is executed.
Status Bit Name Description
S:C Carry (C)Bit is set to a (1) if a carry is generated; otherwise it is cleared (0). (It is for you to determine how this bit works)
S:V Overflow (V)
Bit is set to a (1) if the result or value of the math instruction does not fit into the designated destination. Min. and max. values are determined by the data type of the tag; otherwise it is cleared (0).
S:Z Zero (Z)Bit is set to a (1) if the result or value after a math, move or logic instruction is zero; otherwise it is cleared (0).
S:N Sign (S)
Bit is set to a (1) if the result or value after a math, move or logic instruction is a negative (less than zero) value; otherwise it is cleared (0). This bit is not to be confused with the sign bit (31) of a 32-bit word.
10Northampton Community College
Arithmetic Status Bit Example of Operation
The status bits will contain the status of the last math instruction that is executed. Therefore, in the example to the right, that status bits will contain the status of the Square Root SQR instruction.
11Northampton Community College
Siemens Addition (ADD) Instruction The ADD instructions adds the value in IN1 to the value in INB to the
value in INn and stores the sum in the OUT tag.
al
numnum
sumnumnum
OUTINnININ
Re850650200
65002,20001
0201
21
The Enable Out (ENO)
will set to a logic 1 when the instruction is true and has not generated and math errors.
12Northampton Community College
Allen Bradley Subtract (SUB) Instruction The SUB instructions subtracts the value in Source A from the
value in Source B and stores the difference in the Destination.
0
End of batches sensor
1 = End of BatchesEnd_of_Batches<Local:3:I.Data.2>
SubtractSource A Num_of_Batches.ACC 50Source B Bad_Batches.ACC 2Dest Total_of_Batch 48
SUB
differencebit
BatchofTotalACCBatchesBadACCBatchesofNum
DestSourceBSourceA
3248250
__._.__
)difference signedbit-32 (LogixPro
)difference signedbit-(16 20- 85 - 65
5:N7 2.ACC:C5 - 1.ACC:C5
nDestinatio B Source- A Source
13Northampton Community College
Siemens Subtract (SUB) Instruction The SUB instructions subtracts the value in IN1 from the value in
IN2 and stores the difference in the OUT.
48250
22,501
21
ININ
estotalBatchbadBatchesesnumOfBatch
OUTININ The Enable Out (ENO) will set to a logic 1 when the instruction is true and has not generated and math errors.
14Northampton Community College
SLC 500 Multiply (MUL) Instruction
The MUL instruction multiplies the value in Source A by the value in Source B and stores the 16-bit product in the Destination.
If the values being multiplied will result in a product outside the range -32,768 to 32,767, use Floating Point addresses.
nDestinatio in storedbit-(16 10,000 20* 500
4.PRE:T4 20* 3.PRE:T4
onDesitinati B * Source A Source
15Northampton Community College
When performing integer division, the DIV instruction performs long division. Therefore:
The instruction divides the value in Source A by the value in Source B and stores the results as follows: The rounded 16-bit quotient is stored in the Destination. When dividing 5 / 2, the destination will most likely a value of 3.
SLC 500 Divide (DIV) Instruction
122/5 ofremainderawith
16Northampton Community College
SLC500 Divide (DIV) Instruction
nDestinatioinstoredquotientroundedbit
NNN
nDestinatioBSourceASource
1632/5
23:79:7/7:7
/
17Northampton Community College
ControlLogix Multiply (MUL) Instruction
The MUL instruction multiplies the value in Source A by the value in Source B and stores product in the Destination.
0
Execute the MUL instruction
1 = ExecuteMultiply
<Local:3:I.Data.12>MultiplySource A 2 Source B Thumb_Value 6000Dest Actual_Value 12000
MUL
12000 6000* 2
ueActual_Val eThumb_Valu* 2
nDestinatio B * Source A Source
18Northampton Community College
ControlLogix Divide (DIV) Instruction
The ControlLogix DIV instruction divides the value of Source A by the value of Source B and stores the quotient in the Dest. See the next slide for rounding and truncating of the Dest.
0
Execute the MUL instruction
1 = ExecuteMultiply
<Local:3:I.Data.12>DivideSource A Raw_Thumb_Value 10Source B Thumb_Value 6Dest Actual_Value 1
DIV
1 6 / 10
ueActual_Val eThumb_Valu / ValueRaw_Thumb_
nDestinatio B Source/ A Source
21Northampton Community College
Siemens Multiply (MUL) Instruction
The Siemens MUL instruction multiplies the value of IN1 by the value of IN2 by the value of INn and stores the product in the OUT.
126*2
6humbValuet
eactualValu thumbValue* 2
OUT IN2* IN1 The Enable Out (ENO) will set to a logic 1 when the instruction is true and has not generated and math errors.
22Northampton Community College
Siemens Divide (DIV) Instruction
The Siemens DIV instruction divides the value of IN1 by the value of IN2 and stores the quotient in the OUT.
1 6 / 10
6thumbValue10,luerawThumbVa
eactualValu thumbValue / luerawThumbVa
OUT IN2 / IN1
The Enable Out (ENO)
will set to a logic 1 when the instruction is true and has not generated and math errors.
23Northampton Community College
ControlLogix Modulo (MOD) Instruction
The MOD instruction divides the value stored in Source A by the value in Source B and places the remainder in the Dest.
The Source A, Source B and the Dest follow the same rules as the ADD, SUB, MUL and DIV instructions.
0 ModuloSource A Thumb_Value 7Source B 2 Dest Actual_Value 1
MOD
25Northampton Community College
Siemens Modulo (MOD) Instruction
The MOD instruction divides the value stored in IN1 by the value in IN2 and places the remainder in the OUT.
26Northampton Community College
Allen Bradley Square Root (SQR) Instruction The SQR instruction has two parameter; Source and Destination. Both parameters must be word level addresses. In the SLC500 the value can
be of type INT or FLOAT and in the ControlLogix the value can be a tag of type SINT, INT, DINT or REAL.
The SQR instruction takes the square root of the value stored in the Source and stores the result in the Destination.
bit)-(16 4 3:N7
16 3:N7
4:N10 3:N7
bit)-(32 4 eHypostenus
16 Hypotenuse
esSumOfSquar Hypotenuse
27Northampton Community College
Siemens Square Root (SQR) Instruction The SQR instruction has two parameter; IN and OUT. Both parameters must be word level addresses. The SQR instruction takes the square root of the value stored in the IN
and stores the result in the OUT.
4 lvesselLeve
16 lvesselLeve
evelcylVesselL lvesselLeve
28Northampton Community College
ControlLogix Clear (CLR) Instruction
The CLR instruction has one parameter; Destination. In the SLC500, the Destination can be any valid word level
address and in the ControlLogix it can be a tag of type SINT, INT, DINT or REAL.
When the rung containing the CLR instruction is true, the value stored in the word level address referenced in the Destination is cleared; set to zero (0).
1
Execute the MUL instruction
1 = ExecuteMultiply
<Local:3:I.Data.12>ClearDest Actual_Value 0
CLR
ControlLogix Example
29Northampton Community College
Absolute Value (ABS) Instruction(Not available in LogixPro)
The ABS instruction has two parameters; Source and Destination. In the SLC500 the Source and Destination can be any valid word level address.
In the ControlLogix they can be a tag of type SINT, INT, DINT or REAL. When the rung containing the ABS instruction is true, the instruction takes the
absolute value of the value stored in the Source word and places the resultant value in the Destination word.
50 50-
5.PRE:T21 68:N10
nDestinatio Source
50 50-
ABS_Dest ABS_Source
nDestinatio Source
30Northampton Community College
Siemens CLR and ABS
Siemens does not have a Clear (CLR) instruction. The Siemens Absolute value instruction is not available in
ladder logic. It is only available in structured text.
31Northampton Community College
ControlLogix X To Power of Y (XPY) Instruction(Not available in LogixPro)
The XPY instruction has three parameters; Source A, Source B and Destination.
The rules for the parameters are the same as for the ADD, SUB, MUL and DIV instructions.
The instruction raises the value stored in Source A to the power of the value stored in Source B and stores the result in the Destination.
1 X To Power Of YSource X Vessel_B_Level 2Source Y Thumb_Value 6Dest Actual_Value 64
XPY
642
___6
_
ValueActualLevelBVessel ValueThumb
ControlLogix Example Shown
32Northampton Community College
Siemens X To Power of Y (EXPT) Instruction
The XPY instruction has three parameters; IN1, IN2 and OUT. The instruction raises the value stored in IN1 to the power of the value
stored in IN2 and stores the result in OUT.
642
6,26
thumbValueevelcylVesselL
lvesselLeveevelcylVesselL thumbValue
33Northampton Community College
Compute (CPT) Instruction, Allen Bradley(Not available in LogixPro Supplement to Textbook)
The Compute (CPT) instruction is an output instruction. It has two parameters: Destination Expression
In the SLC500 the Destination can be any valid word level address. In the ControlLogix it can be a tag of type SINT, INT, DINT or REAL.
The Expression can contain any valid expression (equation) to be solved.
In the SLC500 series the CPT instruction is only available on: SLC 5/03 OS302 or higher SLC 5/04 OS401 or higher SLC 5/05 all operating systems
34Northampton Community College
Compute (CPT), CALCULATE InstructionSupplement to Textbook
The Allen Bradley Compute (CPT) and the Siemens CALCULATE instruction can perform any or all of the following operations: Copy Arithmetic Logical Conversion
The operation is defined in the Expression and the result of the Expression is stored in the address referenced in the Destination.
35Northampton Community College
Compute (CPT) InstructionSupplement to Textbook
Instruction Explanation Instruction Explanation
+ Addition AND Bit-by-bit AND of two values
- Subtraction TOD Convert 16-bit Integers to BCD
* Multiplication FRD Convert BCD to 16-bit Integers
|Division in the SLC500 (This is the pipe character. It is a vertical line).
LN Calculates Natural Log
/ Division in the ControlLogix ABS Takes the absolute value
SQR Square Root (SQRT, Siemens) DEG Convert radians to degrees
-Negate. (Same as using the NEG instruction)
RAD Convert degrees to radians
NOTBit-by-bit inversion of a binary value
Trig Functions
SIN, COS, ATN, ACS, ASN, TAN
XORBit-by-bit eXclusive OR of two values
LOG Calculates log base 10
OR Bit-by-bit OR of two values **Raise a number to a power(SQR, Siemens)
Instructions that can be used in the Expression
36Northampton Community College
Compute (CPT) Instruction, ControlLogixSupplement to Textbook
The CPT instruction can be conditional or unconditional.
The Expression is an equation of zero or more lines, with up to 28 characters per line and up to 255 characters.
525
169
43
43
22
22
hypotenuse
hypotenuse
ThensideBandsideAIf
hypotenusesideBsideA
ControlLogix Example Shown
37Northampton Community College
Compute (CPT) InstructionSupplement to Textbook
The arithmetic status bits update as shown in the table:
With this bit: The Processor:
S:0/0 or S:C Carry (C)Sets based on the results of the last instruction executed in the expression.
S:0/1 or S:V Overflow (V)Sets anytime an overflow occurs during the evaluation of the expression.
S:0/2 or S:Z Zero (Z)Sets based on the results of the last instruction executed in the expression.
S:0/3 or S:N Sigh (S)Sets based on the results of the last instruction executed in the expression.
38Northampton Community College
CALCULATE Instruction, SiemensSupplement to Textbook
The CALCULATE instruction can be conditional or unconditional.
525
169
43
43
21
22
22
hypotenuse
hypotenuse
ThensideBandsideAIf
hypotenuseININ
39Northampton Community College
Order of Precedence When parentheses are not used to control the order in which elements
of a mathematical equation should be executed, there is an order of precedence to the math operators. This order and the direction they are evaluated are listed below.
Operator Symbol Direction Evaluated
Parentheses ( ) In order from inner pairs to outer pairs
FunctionsABS, ACS, ASN, ATN, COS,
DEG, FRD, LN, LOG, RAD, SIN, SQR, TAN, TOD, TRN
In the order as per instruction
Exponentiation ** Left to Right
Negation - Left to Right
Math *, |, /, MOD Left to Right
Math +, - Left to Right
Comparison LES, GRT, LEQ, GEQ, EQU, NEQ, LIM Left to Right
Logical AND, OR, NOT, XOR Right to Left
40Northampton Community College
Order of Precedence
Examples of Order of Precedence:
Equation to Evaluate
15 + 60 / 3 – 4 * 5 + 7
Evaluate from left to right
Division and multiplication have higher precedence than addition and subtraction
60 / 3 = 20
4 * 5 = 20
15 + 20 – 20 + 7
15 + 7 = 22
15 + 60 / 3 – 4 * 5 + 7 = 22
41Northampton Community College
Order of Precedence
Examples of Order of Precedence:
Equation to Evaluate25 * 2 + 4 / 2 * 6 – 45 + 16 / 8
Evaluate from left to rightDivision and multiplication have higher precedence than
addition and subtraction25 * 2 = 50
4 / 2 * 6 = 2 * 6 = 1216 / 8 = 2
50 + 12 – 45 + 262 – 45 + 217 + 2 = 19
25 * 2 + 4 / 2 * 6 – 45 + 16 / 8 = 19