The text of a manual · part 9 of 70
SLC 500 Instruction Set Reference Manual, pages 81 to 90
Pages 81 to 90 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 81
Math Instructions
4-19
Notice that an overflow occurred even though the final value was correct. This happens because the overflow condition occurred during the rate calculation. The following graph shows the shifted linear relationship. The input minimum value of 3,277 is subtracted from the input maximum value of 16,384, resulting in the value of 13,107.
32,764 10V (Scaled MAX.)
Scaled Value
0 0V (Scaled MIN.) 0 4 mA (Shifted Input MIN.)
13,107 20 mA (Shifted Input MAX.) Input Value
Calculating the Shifted Linear Relationship Use the following equations to calculate the scaled units.
Scaled value = (Input Value × Rate) + offset
Scaled MAX. – Scaled MIN. Rate = -----------------------------------------------------------------------Input MAX. – Input MIN.
32, 764 – 0 ---------------------------- = 2.4997 (or 24,997/10000 13, 107 – 0
Offset = Scaled MIN. – (Input MIN. × Rate)
0 – ( 0 × 2.4997 ) = 0
Publication 1747-RM001G-EN-P - November 2008
Page 82
4-20
Math Instructions
In this example, the SCL instruction is entered in the ladder logic program as follows.
Apply the Shift SUB SUBTRACT Source A Source B Dest
Analog Input I:1.0 3277 N7:0
Scale Shifted Analog Value SCL SCALE Source Rate [/10000] Offset Dest
N7:0 24997 0 O:2.0
Analog Output
The Ramp (RMP) instruction provides the ability to create linear, acceleration, deceleration, and “S” curve ramp output data wave forms. This instruction provides a means to ramp analog outputs when using them to control devices such as valves.
Ramp Instruction (RMP)
The instruction has the following parameters. RMP Ramp Control Dest
N7:0 N7:7
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
• Control - Control Block is an integer file address that is user selectable. It is a 7-element file, which consists of the following bits and registers: – Word 0 Bit 15 - Enable bit, follows rung state of ramp instruction. – Word 0 Bit 14 - Ramping bit, when set, RMP function is working. – Word 0 Bit 13 - Done bit, set once the RMP function completes (current time = desired time). – Word 0 Bit 12 - Error bit, set if invalid parameters are specified. – Word 0 Bits 0 to 7 - Ramp Algorithm Type. – Word 1 Desired Time - This word defines the time duration of the ramp, in timebase units (1 second or 10 milliseconds). (integer value, valid range = +1 to +32767) – Word 2 Current Time - This word is the current time position of ramp, in timebase units (1 second or 10 milliseconds). The instruction updates the current time when the rung state is true. (integer value, valid range = 0 to +32767) – Word 3 Beginning Output Value - Starting point of ramp (integer value, valid range = -32768 to +32767). – Word 4 Ending Output Value - Ending point of ramp (integer value, valid range = -32768 to +32767) – Words 5 and 6 - These words are for internal use only. • Destination - The Destination is any user defined integer word.
Page 83
Math Instructions
4-21
Table 4.14 Ramp Instruction Control Structure
Word 0
15
14
13
12
EN
RMP
DN
ER
11
10
9
8
7
Desired Time
Word 2
Current Time
Word 3
Beginning Output Value
Word 4
Ending Output Value
Words 5 and 6
Internal use only
(1)
TB = 0, Timebase = 0.01 seconds TB = 1, Timebase = 1.0 second
(2)
Waveform = 00 Linear Waveform = 01 Acceleration Waveform = 10 Deceleration Waveform = 11 “S” Curve
5
4
3
2
1
0
TB(1)
0
0
Waveform(2)
Ramp Algorithm Type 0
Word 1
6 0
0
The following illustrations show Linear Ramp, Acceleration, Deceleration and “S” Curve Ramp waveforms. Ending Ramp Output Value
Ending Ramp Output Value
Ramp Output Beginning Ramp Output Value
Beginning Ramp Output Value
Beginning Ramp Output Value Length of Ramp, in seconds
Length of Ramp, in seconds
“S” Curve Ramp Waveform
Ending Ramp Output Value
Ramp Output
Deceleration Waveform
Ramp Output Ending Ramp Output Value
Acceleration Waveform
Ramp Output
Linear Ramp Waveform
Beginning Ramp Output Value Length of Ramp, in seconds
Length of Ramp, in seconds
Publication 1747-RM001G-EN-P - November 2008
Page 84
4-22
Math Instructions
Instruction Operation When the rung state is true all parameters are validated to be in range. If the parameters are valid, the ramp function places the calculated output value in the destination register. The parameters are validated for every scan when the rung state is true. When the Ramp instruction is scanned and the rung state is true, the current time is updated, the destination value is calculated, and done condition is checked.
ATTENTION
ATTENTION
Changing words 1 through 4 during instruction execution causes loss of resolution of one unit of measurement (1 second or 0.01 seconds depending on ramp). If these values are modified during execution the destination value automatically recalculates for the new value on the next scan.
Modification of words 5 and 6 could result in unpredictable operation, possibly causing equipment damage and/or injury to personnel.
When the rung state is false, the current time is not updated and the destination value is not calculated. When the rung state sees another false to true change the current time is determined from the last updated position. An accuracy of +/- one unit (1 second or 0.01 seconds depending on ramp) or one scan, whichever is larger, can be expected for a false-to-true or true-to-false rung transition. The Ramp instruction is retentive. If a Ramp instruction is executing when a power cycle occurs, the instruction continues to operate starting with the last updated position. The accuracy is limited to one unit or one scan, whichever is larger. Ramp instructions can be cascaded.
Publication 1747-RM001G-EN-P - November 2008
Page 85
Math Instructions
4-23
RMP Equation The Ramp instruction is defined based on the following equations.
Linear: Output = ( E – S ) × P --- + S L
P P Acceleration: Output = ( E – S ) × --- × --- + S L L
–P L –P Deceleration: Output = ( E – S ) × ⎛ 1 – L -----------× ------------⎞⎠ + S ⎝ L L
While 0 ≤P ≤L ⁄ 2 “S” Curve:
While ( L ⁄ 2 ) < P < L L–P L–P P P Output = ( E – S ) × ⎛⎝ 1 – 2 × ------------ × ------------⎞⎠ + S Output = ( E – S ) × 2 × --- × --- + S L L L L
• S = the Beginning Output value • E = the Ending Output value • P = the Current Time • L = the Overall Time • Output = the RMP output value
Continuous Operation
RMP Ramp Control Dest
N7:0 13 N7:0
N7:0 N7:7
CLR Clear Dest
N7:2
12
Publication 1747-RM001G-EN-P - November 2008
Page 86
4-24
Math Instructions
Use the ABS instruction to calculate the absolute value of the Source and place the result in the Destination. 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.
Absolute (ABS)
Entering Parameters ABS Absolute Value Source N7:34 0< Dest N7:35 0<
Enter the following parameters when programming this instruction.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
• Source can be a word address, an integer constant, floating point data element, or a floating point constant • Destination can only be a word address or a floating point data element
•
Output Instruction
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.15 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)
always resets with a floating point value; sets if the input is -32,768 (integer value).
S:0/2
Zero (Z)
sets when destination value is zero; otherwise resets.
S:0/3
Sign (S)
always resets.
Page 87
Math Instructions
The CPT instruction performs copy, arithmetic, logical, and conversion operations. You define the operation in the Expression and the result is written in the Destination. The CPT uses functions to operate on one or more values in the Expression to perform operations such as:
Compute (CPT)
CPT Compute Dest Expression
4-25
N7:36 3< ( N7:13 AND N7:14 ) OR N7:15
• converting from one number format to another. • manipulating numbers. • performing trigonometric functions. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 • Output Instruction
•
•
Instructions that can be used in the Expression include: +, -, *, | (DIV), SQR, - (NEG), NOT, XOR, OR, AND, TOD, FRD, LN, TAN, ABS, DEG, RAD, SIN, COS, ATN, ASN, ACS, LOG, and ** (XPY).
TIP
The execution time of a CPT instruction is longer than a single arithmetic operation and uses more instruction words.
Entering Parameters Enter the following parameters when programming this instruction. • Destination can be a word address or the address of a floating-point data element • Expression is zero or more lines, with up to 28 characters per line, up to 255 characters
Publication 1747-RM001G-EN-P - November 2008
Page 88
4-26
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.16 Processor Function With this Bit
The Processor
S:0/0
Carry (C)
sets based on the result of the last instruction in the Expression.
S:0/1
Overflow (V) sets any time an overflow occurs during the evaluation of the Expression.
S:0/2
Zero (Z)
sets based on the result of the last instruction in the Expression.
S:0/3
Sign (S)
sets based on the result of the last instruction in the Expression.
The above bits are cleared at the start of the CPT instruction. Status file bit S:34/2 is for special handling of the math status bits when using floating point.
Application Example This application example uses Pythagorean’s theorem to find the length of the long leg of a triangle, knowing the two other leg lengths. Use the following equation.
c2 = a2 + b2
Publication 1747-RM001G-EN-P - November 2008 where c =
( a2 + b2 )
N10:0 =
( N7:1 ) 2 + ( N7:2 ) 2
Page 89
Math Instructions
4-27
Rung 2:0 uses standard math instructions to implement Pythagorean’s theorem. Rung 2:1 uses the CPT instruction to obtain the same calculation.
| Rung 2:0 +XPY–––––––––––––––+ | |–––––––––––––––––––––––––––––––––––––––––––––––––––––+–+X TO POWER OF Y +–+–| | | |Source A N7:1| | | | | | 3| | | | | |Source B 2| | | | | | | | | | | |Dest N7:3| | | | | | 0| | | | | +––––––––––––––––––+ | | | | +XPY–––––––––––––––+ | | | +–+X TO POWER OF Y +–+ | | | |Source A N7:2| | | | | | 4| | | | | |Source B 2| | | | | | | | | | | |Dest N7:4| | | | | | 0| | | | | +––––––––––––––––––+ | | | | +ADD–––––––––––––––+ | | | +–+ADD +–+ | | | |Source A N7:3| | | | | | 0| | | | | |Source B N7:4| | | | | | 0| | | | | |Dest N7:5| | | | | | 0| | | | | +––––––––––––––––––+ | | | | +SQR–––––––––––––––+ | | | +–+SQUARE ROOT +–+ | | |Source N7:5| | | | 0| | | |Dest N7:0| | | | 0| | | +––––––––––––––––––+ | | Rung 2:1 +CPT––––––––––––––––––––––––+ | |––––––––––––––––––––––––––––––––––––––––––––––––+COMPUTE +–| | |Dest N10:0| | | | 0| | | |Expression | | | |SQR ((N7:1 ** 2) + (N7:2 **| | | |2)) | | | +–––––––––––––––––––––––––––+ | | Rung 2:2 | |–––––––––––––––––––––––––––––––––––––+END+––––––––––––––––––––––––––––––––––––| | |
Publication 1747-RM001G-EN-P - November 2008
Page 90
4-28
Math Instructions
Use this instruction to swap the low and high bytes of a specified number of words in a bit, integer, ASCII, or string file. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors.
Swap (SWP)
Entering Parameters SWP Swap Source #ST10:1.DATA[0] Length 5
Enter the following parameters when programming this instruction.
Fixed SLC SLC SLC SLC SLC 5/01 5/02 5/03 5/04 5/05 •
•
•
Output Instruction
• Source can only be an indexed word address • Length refers to the number of words to be swapped, regardless of the file type. The address is limited to integer constants. For bit, integer, and ASCII file types, the length range is 1 to 128. For the string file type, the length range is 1 to 41. Note that this instruction is restricted to a single string element and cannot cross a string element boundary. The following example shows how the SWP instruction works.
SWP SWAP Source Length
#ST10:1.1 13
Before: ST10:1 = abcdefghijklmnopqrstuvwxyz After ST10:1 = badcfehgjilknmporqtsvuxwzy
Publication 1747-RM001G-EN-P - November 2008