The text of a manual · part 10 of 18
Simatic S5 to RSLogix 5000 Application Conversion Guide: Chapter 3: Software Conversions Instructions, pages 71 to 79
Pages 71 to 79 of 140, from Simatic S5 to RSLogix 5000 Application Conversion Guide
The original document is the PDF (3.5 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 Siemens 6ES5-431-8MA11, Siemens 6ES5-451-8MA11 and Siemens 6ES5-452-8MR11
Page 71
Software Conversions Instructions
Chapter 3
Comparison - Greater Than or Equal To In the following comparison function the Operand 1 is compared to Operand 2 and if Operand 1 >= Operand 2 then the output is set to 1. The RSLogix 5000 equivalent bit/word for each bit/word used in the S5 in the following example is shown below: Function Operand1 Operand2 Output S5 Statement List L IB19 L IB20 >= F = Q3.0
S5 IB20 Q3.0
RSLogix 5000 IB19data_word1 data_word2 out_bit1 RSLogix 5000 Structured Text If data_word1 >= data_word2 THEN out_bit1 := 1; else out_bit1 := 0; END_IF; SIMATIC S5 - Ladder
RSLogix 5000 - Ladder
Publication LOGIX-AP010B-EN-P - May 2010
71
Page 72
Chapter 3
Software Conversions Instructions
Comparison - Less Than or Equal To In the following comparison function the Operand 1 is compared to Operand 2 and if Operand 1 <= Operand 2 then the output is set to 1. The RSLogix 5000 equivalent bit/word for each bit/word used in the S5 in the following example is shown below: Function Operand1 Operand2 Output S5 Statement List L IB19 L IB20 <= F = Q3.0
S5 IB19 IB20 Q3.0
RSLogix 5000 data_word1 data_word2 out_bit1 RSLogix 5000 Structured Text If data_word1 <= data_word2 THEN out_bit1 := 1; else out_bit1 := 0; END_IF; SIMATIC S5 - Ladder
RSLogix 5000 - Ladder
72
Publication LOGIX-AP010B-EN-P - May 2010
Page 73
Software Conversions Instructions
Jump Operations
Chapter 3
Jump operations programmable in S5 can easily be converted to RSLogix 5000 software. The function of these jump instructions is to select to include/exclude the execution of code sections based on the TRUE/FALSE result of other instructions (for example, COMPARE or AND). Besides these jump functions, RSLogix 5000 software also contains the following instructions that can be used in Structured Text to repeatedly execute a section of code before advancing to the next instruction. • • •
FOR…DO – executes a section of code a specified number of times. WHILE…DO – continually execute a portion of code as long as certain conditions are true. REPEAT…UNTIL - continually execute a portion of code until certain conditions are true.
Other similar functions that are available in RSLogix 5000 software are: • •
Publication LOGIX-AP010B-EN-P - May 2010
CASE OF – select what instruction to execute based on a numerical value. IF…THEN…ELSE – executes a section of code if conditions are true.
73
Page 74
Chapter 3
Software Conversions Instructions
Conditional Jump In the following example of the Conditional Jump function, the instruction that turns on the output if the input is on is executed only if the two data words are NOT equal. Function Operand 1 Operand 2 Input Output S5 Statement List L IB19 L IB20 >< F JC =DESA A I1.0 = Q4.0 DESA: NOP 0
S5 IB19 IB20 I1.0 Q4.0
RSLogix 5000 data_word1 data_word2 data_bit1 out_bit1 RSLogix 5000 Structured Text RSLogix 5000 Structured Text has instructions that allow the program to jump to other subroutines but does not permit the program to jump to another point in the same subroutine. The alternative structure is: If data_word1 <> data_word2 then ... (code that is after the NOP 0) else Out_bit1 := data_bit1; End_if; SIMATIC S5 - Ladder
S5 Ladder has instructions that allows the program to jump to other subroutines but does not permit the program to jump to another point in the same subroutine. RSLogix 5000 - Ladder
74
Publication LOGIX-AP010B-EN-P - May 2010
Page 75
Software Conversions Instructions
Chapter 3
Unconditional Jump In the following example of the Unconditional Jump function, the instruction that activates the output (if the input is on) is never executed regardless of whether the two data words are equal. Function Operand 1 Operand 2 Input Output
S5 IB19 IB20 I1.0 Q4.0
RSLogix 5000 data_word1 data_word2 data_bit1 out_bit1
S5 Statement List
RSLogix 5000 Structured Text RSLogix 5000 Structured Text has instructions that allow the program to jump to other subroutines but does not permit the program to jump to another point in the same subroutine.
L IB19 L IB20 >< F JU = DESA A I1.0 = Q4.0 DESA: NOP
SIMATIC S5 - Ladder S5 Ladder has instructions that allow the program to jump to other subroutines but does not permit the program to jump to another point in the same subroutine. RSLogix 5000 - Ladder
Miscellaneous Jump Execution of comparison operations in S5 sets condition codes CC0 & CC1. S5 Instruction
Description
RSLogix 5000 Implementation
JZ
ACCU 2 = ACCU 1
Equivalent to the equal to comparison instruction (EQ)
JN
ACCU 2 <> ACCU 1
Equivalent to the not equal to comparison instruction (NEQ).
JP
ACCU 2 > ACCU 1
Equivalent to the greater than comparison instruction (GT).
JM
ACCU 2 < ACCU 1
Equivalent to the less than comparison instruction (LT).
Publication LOGIX-AP010B-EN-P - May 2010
75
Page 76
Chapter 3
Software Conversions Instructions
Overflow Jump Function JO With S5 you can work with decimal number in the range -32768 to +32768. If the result of the arithmetic operation is outside this range then S5 sets the overflow bit, OV. The instructions JO can be used to program a jump if this bit is set. This is often used in programs to run error handling code when values exceed their expected range. With RSLogix 5000 software, the data type DINT can be used to store a 32-bit signed integer value between the range -2,147,483,648 to +2,147,483,647 therefore overflow of data is not usually an issue. However, if required, a combination of a greater than (GT) or less than (LT) comparison instruction and a jump (JMP) instruction can be used in RSLogix to exceed a jump if values exceed a specified range. RSLogix 5000 software also includes an arithmetic overflow status flag (S:V) that is set if a value cannot fit into the destination because the value is greater than the maximum value for the destination or less than the minimum value for the destination. This overflow bit can be used in conjunction with the JUMP (JMP) instruction to replicate the functionality of the S5 JO instruction.
76
Publication LOGIX-AP010B-EN-P - May 2010
Page 77
Software Conversions Instructions
Arithmetic Operations
Chapter 3
Arithmetic operations programmable in S5 can easily be converted to RSLogix 5000 software. The main difference between the two systems is that in S5 Statement List each operand is loaded into an accumulator before the operation is performed and then the result can be transferred to the required destination. The corresponding RSLogix 5000 Structured Text code is simpler as it executes the operation on the operands directly. In S5 all operands for a arithmetic operation must be of the same type (that is, 16 bit fixed point, 32 bit fixed point or 32 bit floating point) but in RSLogix 5000 operands of other types can be used in the same instruction. The following RSLogix 5000 arithmetic operations have no corresponding instruction in S5. • • •
MOD – Divides one operand by another and places the remainder in the specified destination. ABS – Takes the absolute value of the source and places it in the destination. CPT – Allows the programmer to define multiple arithmetic operations in one instruction
The following RSLogix 5000 advance arithmetic operations have no corresponding instruction in S5. • • •
LN – Computes the natural log of an operand and places it in the specified destination. LOG – Computes the base 10 log of an operand and places it in the specified destination. XPV – Computes the value of operand 1 (X) to the power of operand 2 (Y) and places the result in the specified destination.
S5 has increment (INC) and decrement (DEC) instructions that are used to increment and decrement the value in the accumulator. RSLogix 5000 software does not use the accumulator in the same way as S5 so this functionality can be achieved with the add or subtract instructions in the RSLogix 5000 software.
Examples The following examples illustrate how to convert the following arithmetic functions from S5 to RSLogix 5000. • • • •
Publication LOGIX-AP010B-EN-P - May 2010
Addition Subtraction Multiplication Division
77
Page 78
Chapter 3
Software Conversions Instructions
Addition S5 uses three addition instructions depending on whether the operands are 16 bit integers, 32 bit integers or floating point numbers. RSLogix 5000 software has one addition instruction that can be used regardless of the format of the operands. Note that you can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. You can check the S:V bit to see whether the rest was truncated. Function
S5
RSLogix 5000
Operand 1 (16 bit)
FW18 data_word1
Operand 1 (32 bit)
FD30
Operand 1 (floating point)
FD42
Operand 2 (16 bit)
FW20
Operand 2 (32 bit)
FD34
Operand 2 (floating point)
FD46
Output (16 bit)
FW22
Output (32 bit)
FD38
Operand (floating point)
FD50
S5 Statement List 16 bit fixed point numbers data_word2 data_word3
RSLogix 5000 Structured Text
L FW18 L FW20 +F T FW22 S5 Statement List 32 bit fixed point numbers L FD30 L FD34 +D T FD38 data_word3 := data_word1 + data_word2;
S5 Statement List 32 bit floating point numbers L FD42 L FD46 +G T FD50
78
Publication LOGIX-AP010B-EN-P - May 2010
Page 79
Software Conversions Instructions
Chapter 3
SIMATIC S5 - Ladder 16 bit fixed point numbers
RSLogix 5000 - Ladder
Publication LOGIX-AP010B-EN-P - May 2010
79