The text of a manual · part 8 of 70
SLC 500 Instruction Set Reference Manual, pages 71 to 80
Pages 71 to 80 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 71
Math Instructions
4-9
Table 4.7 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if overflow is detected at destination; otherwise resets. On overflow, the minor error flag is also set. The value -32,768 or 32,767 is placed in the destination. Exception: If you are using an SLC 5/02 or higher processor and have S:2/14 (math overflow selection bit) set, then the unsigned, truncated least significant 16-bits of the result remains in the destination. For floating point destinations, the overflow result remains in the destination.
S:0/2
Zero (Z)
sets if result is zero; otherwise resets.
S:0/3
Sign (S)
sets if result is negative; otherwise resets.
Updates to the Math Register, S:13 and S:14 During integer operation, S:13 and S:14 contain the 32-bit signed result of the multiply instruction. This result is valid at overflow.
TIP
Divide (DIV) DIV Divide Source A Source B Dest
Use the DIV instruction to divide one value (source A) by another (source B). The rounded quotient is then placed in the destination. If the remainder is 0.5 or greater, round up occurs in the destination. The unrounded quotient is stored in the most significant word of the math register. The remainder is placed in the least significant word of the math register.
N7:23 0< N7:24 0< N7:25 0<
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
•
Output Instruction
For floating point operation, the math register does not change.
•
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.
Publication 1747-RM001G-EN-P - November 2008
Page 72
4-10
Math Instructions
Table 4.8 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if division by zero or overflow is detected; otherwise resets. On overflow, the minor error flag is also set. The value 32,767 is placed in the destination. Exception: If you are using an SLC1 5/02 or higher processor and have S:2/14 (math overflow selection bit) set, then the unsigned, truncated overflow remains in the destination. For floating point destinations, the overflow result remains in the destination.
S:0/2
Zero (Z)
sets if result is zero; otherwise resets; undefined if overflow is set.
S:0/3
Sign (S)
sets if result is negative; otherwise resets; undefined if overflow is set.
Updates to the Math Registers, S:13 and S:14 During integer operation, the unrounded quotient is placed in the most significant word (S:14), the remainder is placed in the least significant word (S:13).
TIP
For floating point operation, the math register does not change.
Example The remainder of 11/2 is 0.5, so the quotient is rounded up to 6 and is stored in the destination. The unrounded quotient, which is 5, is stored in S:14 and the remainder, which is 1, is stored at S:13.
DIV DIVIDE Source A Source B Dest
Publication 1747-RM001G-EN-P - November 2008
N7:0 11 N7:1 2 N7:2 6 where:
N7:0 = 11 N7:1 = 2 N7:2 = 6 result:
S:14 = 5 S:13 = 1
Page 73
Math Instructions
4-11
The 32-bit content of the math register is divided by the 16-bit source value and the rounded quotient is placed in the destination. If the remainder is 0.5 or greater, the destination is rounded up.
Double Divide (DDV)
DDV Double Divide Source N7:26 0< Dest N7:27 0<
This instruction typically follows a MUL instruction that creates a 32-bit result.
TIP
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.9 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if division by zero or if result is greater than 32,767 or less than -32,768; otherwise resets. On overflow, the minor error flag is also set. The value 32,767 is placed in the destination.
S:0/2
Zero (Z)
sets if result is zero; otherwise resets.
S:0/3
Sign (S)
sets if result is negative; otherwise resets; undefined if overflow is set.
Updates to the Math Registers, S:13 and S:14 Initially contains the dividend of the DDV operation. Upon instruction execution, the unrounded quotient is placed in the most significant word of the math register. The remainder is placed in the least significant word of the math register.
Publication 1747-RM001G-EN-P - November 2008
Page 74
4-12
Math Instructions
Use the CLR instruction to set the destination value of a word to zero.
Clear (CLR)
Updates to Arithmetic Status Bits CLR Clear Dest
N7:27 0<
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)
always resets.
S:0/2
Zero (Z)
always sets.
S:0/3
Sign (S)
always resets.
The instruction calculates the square root of a negative number without overflow or faults. In applications where the source value may be negative, use a comparison instruction to evaluate the source value to determine if the destination may be invalid.
SQR Square Root Source N7:28 0< Dest N7:29 0<
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
Table 4.10 Processor Function
When this instruction is evaluated as true, the square root of the absolute value of the source is calculated and the rounded result is placed in the destination.
Square Root (SQR)
•
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.
•
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.11 Processor Function
Publication 1747-RM001G-EN-P - November 2008
With this Bit
The Processor
S:0/0
Carry (C)
is reserved (integer). For floating point, it is always cleared.
S:0/1
Overflow (V)
always resets.
S:0/2
Zero (Z)
sets when destination value is zero.
S:0/3
Sign (S)
always resets.
Page 75
Math Instructions
4-13
Use the SCP instruction to produce a scaled output value that has a linear relationship between the input and scaled values. This instruction supports integer and floating point values. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Scale with Parameters (SCP)
Use the following formula to convert analog input data to engineering units. SCP Scale w/Parameters Input N7:30 100< Input Min. 0 0< Input Max. 32767 32767< Scaled Min. 0 0< Scaled Max. 10000 10000< Output N7:31 0< y = mx + b Where: y = scaled output m = slope = (scaled MAX. - scaled MIN.) / (input MAX. - input MIN.) x = input value b = offset (y intercept) = scaled MIN - (input MIN. x m)
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 • Output Instruction
•
•
TIP
The Input Minimum, Input Maximum, Scaled Minimum, and Scaled Maximum are used to determine the slope and offset values. The input value can go outside of the specified input limits and no ordering is required. For example, the scaled output value is not necessarily clamped between the scaled minimum and scaled maximum values.
Entering Parameters Enter the following parameters when programming this instruction. • Input value can be a word address or an address of floating point data elements. • Input Minimum and Input Maximum values determine the range of data that appears in the Input Value parameter. The value can be a word address, an integer constant, floating point data element, or a floating point constant. • Scaled Minimum and Scaled Maximum values determine the range of data that appears in the Scaled Output parameter. The value can be a word address, an integer constant, floating point data element, or a floating point constant. • Scaled Output value can be a word address or an address of floating point data elements.
Publication 1747-RM001G-EN-P - November 2008
Page 76
4-14
Math Instructions
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 4.12 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
always resets.
S:0/1
Overflow (V)
sets if overflow generated or an unsupported input is detected; otherwise resets.
S:0/2
Zero (Z)
sets when destination value is zero; otherwise resets.
S:0/3
Sign (S)
sets if the destination value is negative; otherwise resets.
Application Examples Example 1 In the first example, an analog I/O combination module (1746-NIO4I) is in slot 1 of the chassis. A pressure transducer is connected to input 0 and we want to read the value in engineering units. The pressure transducer measures pressures from 0 to 1000 psi and provides a 0 to 10V signal to the analog module. For a 0 to 10V signal, the analog module provides a range between 0 to 32,767. The following program rung places a number between 0 and 1000 into N7:20 based on the input signal coming from the pressure transducer into the analog module.
0000
SCP Scale w/Parameters Input Input Min. Input Max. Scaled Min. Scaled Max. Output
0001
Publication 1747-RM001G-EN-P - November 2008
I:1.0 0< 0 0< 32767 32767< 0 0< 1000 1000< N7:20 0<
END
Page 77
Math Instructions
4-15
Example 2 In the second example, an analog I/O combination module (1746-NIO4I) is in slot 1 of the chassis. We want to control the proportional valve connected to output 0. The valve takes a 4 to 20 mA signal to control how far it opens (0 to 100%). (Assume that additional logic is present in the program that calculates how far to open the valve in percent and places a number between 0 and 100 into N7:21.) The analog module provides a 4 to 20 mA output signal for a number between 6242 to 31,208. The following program rung directs an analog output to provide a 4 to 20 mA signal to the proportional valve (N7:21), based on a number between 0 and 100.
SCP Scale w/Parameters Input
0000
Input Min. Input Max. Scaled Min. Scaled Max. Output
N7:21 0< 0 0< 100 100< 6242 6242< 31208 31208< O:1.0 0<
END
0001
When this instruction is true, the value at the source address is multiplied by the rate value. The rounded result is added to the offset value and placed in the destination.
Scale Data (SCL)
Example SCL SCALE Source Rate [/10000] Offset
SCL
Dest
SCALE Source Rate
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
[/10000]
N7:0 100 25000
Offset
127
Dest
N7:1 377
The source 100 is multiplied by 25000 and divided by 10000 and added to 127. The result, 377, is placed in the destination.
•
Output Instruction
Publication 1747-RM001G-EN-P - November 2008
Page 78
4-16
Math Instructions
TIP
Anytime an underflow or overflow occurs in the destination file, minor error bit S:5/0 must be reset by the program. This must occur before the end of the current scan to prevent major error code 0020 from being declared. This instruction can overflow before the offset is added.
Note that the term rate is sometimes referred to as slope. The rate function is limited to the range -3.2768 to 3.2767. For example, -32768/10000 to +32767/10000.
Entering Parameters The value for the following parameters is between -32,768 to 32,767. • Source can be either a constant or a word address • Rate (or slope) is the positive or negative value you enter divided by 10,000. It can be either a constant or a word address • Offset can be either a constant or a word address
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 4.13 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
is reserved.
S:0/1
Overflow (V)
sets if an overflow is detected; otherwise resets. On overflow, minor error bit S:5/0 is also set and the value -32,768 or 32,767 is placed in the destination. The presence of an overflow is checked before and after the offset value is applied.(1)
S:0/2
Zero (Z)
sets when destination value is zero.
S:0/3
Sign (S)
sets if the destination value is negative; otherwise resets.
(1)
Publication 1747-RM001G-EN-P - November 2008
If the result of the Source times the Rate, divided by 10000, is greater than 32767, the SCL instruction overflows, causing error 0020 (Minor Error Bit), and places 32767 in the Destination. This occurs regardless of the current offset.
Page 79
Math Instructions
4-17
Application Example 1 - Converting 4 to 20 mA Analog Input Signal to PID Process Variable
16,383 (Scaled MAX.)
Scaled Value
0 (Scaled MIN.) 3,277 (Input MIN.)
Input Value
16,384 (Input MAX.)
Calculating the Linear Relationship Use the following equations to express the linear relationship between the input value and the resulting scaled value.
Scaled value = (Input Value X Rate) + Offset Rate = (Scaled MAX. - Scaled MIN.) / (Input MAX. - Input MIN.) (16,383 - 0)/(16,384 - 3277) = 1.249 (or 12,490/10000) Offset = Scaled MIN. - (Input MIN. X Rate) 0 - (3277 x 1.249) = -4093
Publication 1747-RM001G-EN-P - November 2008
Page 80
4-18
Math Instructions
Application Example 2 - Scaling an Analog Input to Control an Analog Output
32,764 10V (Scaled MAX.)
Scaled Value
0 0V (Scaled MIN.) 3,277 4 mA (Input MIN.)
16,384 20 mA (Input MAX.) Input Value
Calculating the Linear Relationship Use the following equations to calculate the scaled units.
Scaled value = (Input Value X Rate) + Offset Rate = (Scaled MAX. - Scaled MIN.) / (Input MAX. - Input MIN.) (32,764 - 0) / (16,384 - 3277) = 2.4997 (or 24,997/10000) Offset = Scaled MIN. - (Input MIN. x rate) 0 - (3277 x 2.4997) = - 8192
The above offset and rate values are correct for the SCL instruction. However, if the input exceeds 13,107, the instruction overflows and sets S:5/0 math overflow bit. For example:
17 mA = 13,926 x 2.2997 = 34,810 (actual overflow) 34,810 - 8192 = 26,618
To avoid an overflow, we recommend shifting the linear relationship along the input value axis and reduce the values.
Publication 1747-RM001G-EN-P - November 2008