The text of a manual · part 10 of 70
SLC 500 Instruction Set Reference Manual, pages 91 to 100
Pages 91 to 100 of 694
The original document is the PDF (7.2 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 1747-L514
Page 91
Math Instructions
4-29
Use the ASN instruction to take the arc sine of a number and store the result (in radians) in the destination. The source must be greater than or equal to -1 and less than or equal to 1. The resulting value in the destination is always greater than or equal to -Pi/2 and less than or equal to Pi/2, where Pi = 3.141592. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Arc Sine (ASN)
Updates to Arithmetic Status Bits ASN Arc Sine Source Dest
N7:37 0< N7:38 0<
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Output Instruction
Table 4.17 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S)
sets if the result is negative; otherwise resets.
Use the ACS instruction to take the arc cosine of a number (source in radians) and store the result (in radians) in the destination. The source must be greater than or equal to -1 and less than or equal to 1. The resulting value in the destination is always greater than or equal to 0 and less than or equal to Pi, where Pi = 3.141592. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Arc Cosine (ACS)
Updates to Arithmetic Status Bits ACS Arc Cosine Source N7:39 0< Dest N7:40 0<
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 • Output Instruction
•
•
Table 4.18 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V) sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S)
always resets.
Publication 1747-RM001G-EN-P - November 2008
Page 92
4-30
Math Instructions
Use the ATN instruction to take the arc tangent of a number (source) and store the result (in radians) in the destination. The resulting value in the destination is always greater than or equal to -Pi/2 and less than or equal to Pi/2, where Pi = 3.141592. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Arc Tangent (ATN)
Updates to Arithmetic Status Bits ATN Arc Tangent Source N7:41 0< Dest N7:42 0<
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Output Instruction
Table 4.19 Processor Function With this Bit The Processor S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S)
sets if the result is negative; otherwise resets.
Use the COS instruction to take the cosine of a number (source in radians) and store the result in the destination. The source must be greater than or equal to -205887.4 and less than or equal to 205887.4. The greatest accuracy is achieved when the source is greater than -2 Pi and less than 2 Pi, where Pi = 3.141592. The resulting value in the destination is always greater than or equal to -1 and less than or equal to 1. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Cosine (COS)
Updates to Arithmetic Status Bits COS Cosine Source Dest
N7:43 0< N7:44 0<
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Output Instruction
Publication 1747-RM001G-EN-P - November 2008
Table 4.20 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S sets if the result is negative; otherwise resets.
Page 93
Math Instructions
4-31
Use the LN instruction to take the natural log of the value in the source and store the result in the destination. The source must be greater than zero. The resulting value in the destination is always greater than or equal to -87.33654 and less than or equal to 88.72284. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Natural Log (LN)
Updates to Arithmetic Status Bits LN Natural Log Source N7:45 0< Dest N7:46 0<
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Output Instruction
Table 4.21 Processor Function With this Bit
The Processor
S:0/0 Carry (C)
always resets.
S:0/1 Overflow (V) sets if an overflow is generated or an unsupported input is detected; otherwise resets.
Log to the Base 10 (LOG)
S:0/2 Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3 Sign (S)
sets if the result is negative; otherwise resets.
Use the LOG instruction to take the log base 10 of the value in the source and store the result in the destination. The source must be greater than zero. The resulting value in the destination is always greater than or equal to -37.92978 and less than or equal to 38.53184. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Updates to Arithmetic Status Bits LOG Log Base 10 Source N7:47 0< Dest N7:48 0<
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 • Output Instruction
•
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated. Table 4.22 Processor Function
• With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V) sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S)
sets if the result is negative; otherwise resets.
Publication 1747-RM001G-EN-P - November 2008
Page 94
4-32
Math Instructions
Use the SIN instruction to take the sine of a number (source in radians) and store the result in the destination. The source must be greater than or equal to -205887.4 and less than or equal to 205887.4. The greatest accuracy is achieved when the source is greater than -2 Pi and less than 2 Pi, where Pi = 3.141592. The resulting value in the destination is always greater than or equal to -1 and less than or equal to 1. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Sine (SIN)
Updates to Arithmetic Status Bits SIN Sine Source Dest
N7:49 0< N7:50 0<
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated. Table 4.23 Processor Function
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Output Instruction
With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S)
sets if the result is negative; otherwise resets.
Use the TAN instruction to take the tangent of a number (source in radians) and store the result in the destination. The value in the source must be greater than or equal to -102943.7 and less than or equal to 102943.7. The greatest accuracy is achieved when the source is greater than -2 Pi and less than 2 Pi, where Pi = 3.141592. The resulting value in the destination is either a real number or infinity. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Tangent (TAN)
Updates to Arithmetic Status Bits TAN Tangent Source Dest
N7:51 0< N7:52 0<
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Output Instruction
Publication 1747-RM001G-EN-P - November 2008
Table 4.24 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S)
sets if the result is negative; otherwise resets.
Page 95
Math Instructions
X to the Power of Y (XPY)
4-33
Use the XPY instruction to raise a value (source A) to a power (source B) and store the result in the destination. If the value in source A is negative, the exponent (source B) should be a whole number. If it is not a whole number, the overflow bit is set and the absolute value of the base is used in the calculation. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors. The XPY instruction uses the following algorithm.
XPY X To Power of Y Source A N7:53 2< Source B N7:54 3< Dest N7:55 0<
XPY = 2 ** (Y * log2 (X)) If any of the intermediate operations in this algorithm produce an overflow, the Arithmetic Overflow Status bit (S:0/1) is set.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Updates to Arithmetic Status Bits
Output Instruction
The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated. Table 4.25 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if an overflow is generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets if the result is zero; otherwise resets.
S:0/3
Sign (S)
sets if the result is negative; otherwise resets.
Publication 1747-RM001G-EN-P - November 2008
Page 96
4-34
Math Instructions
Notes:
Publication 1747-RM001G-EN-P - November 2008
Page 97
Chapter
5
Data Handling Instructions
This chapter contains general information about the data handling instructions and explains how they function in your application program. Each of the instructions includes information on: • what the instruction symbol looks like. • how to use the instruction. Table 5.1 Data Handling Instructions Instruction Mnemonic TOD
Name Convert to BCD
FRD
Convert from BCD
DEG
DCD
Convert from Radians to Degrees Convert from Degrees to Radians Decode 4 to 1 of 16
ENC
Encode 1 of 16 to 4
COP and FLL
Copy File and
RAD
Purpose
Fill File MOV MVM
Move Masked Move
AND OR XOR NOT NEG FFL and FFU
And Or Exclusive Or Not Negate FIFO Load and
FIFO Unload
LFL and LFU
LIFO Load and
LIFO Unload
1
Page
Converts the integer source value to BCD format and stores it in the 5-2 destination. Converts the BCD source value to an integer and stores it in the 5-5 destination. Converts radians (source) to degrees and stores the result in the 5-8 destination. Converts degrees (source) to radians and stores the result in the 5-9 destination. Decodes a 4-bit value (0 to 15), turning on the corresponding bit in the 5-10 16-bit destination. Encodes a 16-bit source to a 4-bit value. Searches the source from the 5-11 lowest to the highest bit, and looks for the first set bit. The corresponding bit position is written to the destination as an integer. The COP instruction copies data from the source file to the destination file 5-13 The FLL instruction loads a source value into each position in the destination file. Moves the source value to the destination. 5-17 Moves data from a source location to a selected portion of the 5-18 destination. Performs a bitwise AND operation. 5-20 Performs a bitwise inclusive OR operation. 5-21 Performs a bitwise exclusive OR operation. 5-22 Performs a NOT operation. 5-23 Changes the sign of the source and stores it in the destination. 5-24 5-26 The FFL instruction loads a word into a FIFO stack on successive false-to-true transitions. The FFU unloads a word from the stack on successive false- to-true transitions. The first word loaded is the first to be unloaded. 5-28 The LFL instruction loads a word into a LIFO stack on successive false-to-true transitions. The LFU unloads a word from the stack on successive false-to-true transitions. The last word loaded is the first to be unloaded.
Publication 1747-RM001G-EN-P - November 2008
Page 98
5-2
Data Handling Instructions
Use this instruction to convert 16-bit integers into BCD values.
Convert to BCD (TOD) TOD To BCD Source Dest
With Fixed and SLC 5/01 processors, the destination can only be the math register. With SLC 5/02 and higher processors, the destination parameter can be a word address in any data file, or it can be the math register, S:13 and S:14.
N7:56 824< N7:57 0000h<
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
•
•
•
Output Instruction
If the integer value you enter is negative, the absolute value of the number is used for conversion.
Updates to Arithmetic Status Bits The arithmetic status bits are found in Word 0, bits 0 to 3 in the status file. After an instruction is executed, the arithmetic status bits in the status file are updated. Table 5.2 Processor Function
Publication 1747-RM001G-EN-P - November 2008
With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if the BCD result is larger than 9999. Overflow results in a minor error.
S:0/2
Zero (Z)
sets if destination value is zero.
S:0/3
Sign (S)
sets if the source word is negative; otherwise resets.
Page 99
Data Handling Instructions
5-3
Updates to the Math Register, S:13 and S:14 Contains the 5-digit BCD result of the conversion. This result is valid at overflow.
Example 1 The integer value 9760 stored at N7:3 is converted to BCD and the BCD equivalent is stored in N10:0. The maximum BCD value possible is 9999.
TOD TO BCD Source Dest
The destination value is displayed in BCD format.
N7:3 9760 N10:0 9760
9
7
6
0
N7:3
Decimal
0010
0110
0010
0000
9
7
6
0
N10:0
4-digit BCD
1001
0111
0110
0000
Example 2 The integer value 32760 stored at N7:3 is converted to BCD. The 5-digit BCD value is stored in the math register. The lower 4 digits of the BCD value is moved to output word O:2 and the remaining digit is moved through a mask to output word O:3. When using the math register as the destination parameter in the TOD instruction, the maximum BCD value possible is 32767.
TIP
However, for BCD values above 9999, the overflow bit is set, resulting in minor error bit S:5/0 also being set. Your ladder program can unlatch S:5/0 before the end of the scan to avoid major error 0020, as done in this example.
Publication 1747-RM001G-EN-P - November 2008
Page 100
5-4
Data Handling Instructions
0
0
15 S:14
0
3
2
7
6
0
N7:3 Decimal
3
2
7
6
0
S:13 & S:14 5-digit BCD
0
15
0
S:13
This example will output the absolute value (0 to 32767) contained in N7:3 as 5 BCD digits in output slots 2 and 3.
TOD ] [
TO BCD Source Dest
N7:3 32760 S:13 00032760
S:13 and S:14 are displayed in BCD format.
S:5 (U) 0
S:0 ] [ 1
Minor Error Bit
MOV MOVE Source Dest
S:13 10080 O:2.0 10080
0010 0111 0110 0000
MVM MASKED MOVE Source
S:14
Mask
000F
Dest
O:3.0
3
3
Publication 1747-RM001G-EN-P - November 2008
0000 0000 0000 0011