Converting S5 to IEC 61131-3

If you select an IEC language as your target language for a STEP5 import, you must be aware that portions of your project cannot be converted into IEC 61131-3. If part of a S5 POU contains code that cannot be converted into IEC 61131-3, an error message will be generated and the critical portion of the original STEP5 IL code will be inserted as a comment in the IEC POU. You must then replace or rewrite this code. System commands that only function in a specific S5 CPU cannot be converted into IEC. The “STEP5 Core Command List” can be converted into IEC code with a click of a button despite the fact that STEP5 is enormously different in the way it is conceived.

The core command list that can be converted to IEC 61131-3 contains all commands that can be converted to LD or FBD in a STEP5 programming system and also all commands that are allowed in a STEP5-PB (Program Block). In addition, of the STEP5 commands allowed only in IL or in FB’s (function blocks), the commands that can be converted to IEC are primarily those that are available in every S5 CPU (e.g., absolute and conditional jumps, shift commands, etc.)

The only exception or limitation for conversion is related to resetting timers which can be done in STEP5 but not normally in IEC 61131-3.

The individual convertible commands:

U, UN, O, ON, S, R, =  with the following     bit operands: I (inputs), O (outputs), M (memory locations), S (S memory     locations), D (Data in data blocks)

U, UN, O, ON with the following operands:     T (Timer), C (Counter)

S, R with the following operands: C

SU, RU, P, PN with the following operands:     E, A, M, D

O, O(, U(, )

L, T with the following operand ranges: E,     A, M, D, T, C, P (Periphery) and operand sizes: B (byte), W (word), D     (double word), L (left byte), R (right byte)

L with the following constant formats: DH,     KB, KF, KH, KM, KT, KZ, KY, KG, KC

SI, SE, SA with the following operands: T

ZV, ZR with the following operands: C

+, -, X, : with the following operands: F     (fixed point number), G (floating point number)

+, - with the following operands: D (32 bit     fixed point number)

!=, ><, >, <, >=, <= with     the following operands: F, D, G

ADD with the following operands: BF, KF, DH

SPA, SPB with the following operands: PB,     FB (with most parameter types), SB

A, AX with the following operands: DB, DX

BE, BEA, BEB

BLD, NOP, \*\*\*

UW, OW, XOW

KEW, KZW, KZD

SLW, SRW, SLD, RRD, RLD

SPA=, SPB=

SPZ=, SPN=, SPP=, SPM=

TAK

D, I

Most of the formal operand commands

Unconvertible Commands

U, UN, O, ON, S, R, =  with the following     bit operands: Timer and counter bits (T0.0, C0.0)

L, T with the following operand ranges: Q     (expanded periphery)

LC with the following operands: T, C

SV, SS, R, FR with the following operands:     T

FR with the following operands: C

Formal operand commands for starting, resetting     and releasing timers

All commands with operands from the ranges     BA, BB, BS, BT (operating system data).

SPA, SPB with the following operands: OB (works     only with certain S5's and certain OBs )

BA, BAB with the following operands: FX

E, EX with the following operands: DB, DX

STP, STS, STW

DEF, DED, DUF, DUD

SVW, SVD

SPO=, SPS=, SPR

AS, AF, AFS, AFF, BAS, BAF

ENT

SES, SEF

B with the following operands: DW, MW, BS

LIR, TIR, LDI, TDI, TNW, TXB, TXW

MAS, MAB, MSA, MSB, MBA, MBS

MBR, ABR

LRW, LRD, TRW, TRD

TSG

LB, TB, LW, TW with the following operands:     GB, GW, GD, CB, CW, CD

ACR, TSC

BI

SIM, LIM

If you examine the commands that cannot be converted you will see that they are generally special commands that are only available on certain CPUs. The standard commands that cannot be converted to IEC are: loading BCD coded timer or counter values (LC T, LC C), timer types SV and SS, and resetting timers.

Data Blocks

STEP5 data blocks are converted into POUs (Program Organization Units) that have a header but no code. This is convenient if the data blocks are used as normal variable ranges but inconvenient if attempts have been made to manually implement concepts like instance data blocks in the STEP5 program.

Other Problems when Importing from STEP5

The STEP5 import can be improved manually in the following ways.

1. Time values in word variables

In STEP5 a time value is allowed in every word address be it in the memory location area or in a data block. This is not allowed in IEC 61131-3, TIME variables or constants are not compatible with WORD addresses. This can result in the creation of erroneous command sequences when importing from STEP5. This will not happen if you open a data block and select the time format (KT) for the address in question. In other words, this error only occurs when the STEP5 program is worth the effort of improving it. When it does occur, you will see the message “Incompatible Types: Cannot convert WORD to TIME.” or “Incompatible Types: Cannot convert TIME to WORD.” You must then modify the declaration for the WORD variable (if available) and turn it into a TIME variable.

2. Failure to Access Data Blocks

There are no data blocks in IEC 61131-3 and it is impossible completely to recreate them in IEC. In STEP5 they are used as normal variable ranges (almost like a memory location ranges), and also in the form of arrays (B DW), pointers (B MW100 A DB 0) or unions (byte, word or double word access in DBs ). STEP5 conversion can only convert DB access if it is somewhat structured. When attempting to access DBsyou must know which DB is open (A DB). You must be aware of this when the A DB operation is closer to the beginning in the same POU or when the DB number is included with the POU as a formal parameter. If A DB is not found in front of the first DB access, the POU cannot be converted. The warning “No open data block (insert an A DB)” notifies you that this is the case. In the converted POU, you will see access to an undefined variable named “ErrorDW0” (for example) that will cause an error message to be generated when the newly converted POU is compiled. You can then replace the variables with access to the correct DB (e.g., replace “ErrorDW0” with “DB10.DW0”). The other option is to discard the converted POU and insert an A DB at the beginning of the POU in STEP5.

A STEP5 POU that accesses data words (data bytes, etc.) should always open the data block first. If necessary, the POU should be improved before being imported by inserting the appropriate A DB command preferably at the beginning of the POU. Otherwise the converted POU will have to be edited after the fact.

If there is more than one A BD operation that must be partially skipped, the conversion may have a errors, i.e., code may be generated that accesses the wrong DB.

3. Higher Concepts Related to Data Block Access

In STEP5 you have the option of creating something similar to instances by having the Code block open an indexed version of a data block. This could be done with the following sample code sequence:

L KF +5

T MW 44

B MW 44

A DB 0

The DB5 is opened at the end of this sequence (in general, the DB whose number is found in the memory location word %MW44 will be opened). This type of access is not recognized in the conversion which means that the following changes have to be made after the conversion:

First, all DBsmust be imported that act as instance DBs , e.g., DB5 and DB6. They will be imported as normal IL, LD or FBD POUs whichever you prefer. The POUs do not have a code, but rather a header with definitions of local variables. Type instances can now be created from these POUs. Create a user-defined type (e.g., named DBType) and insert the local variables and converted DBsas components. Then create global instances of this type by writing to a global variable list:

VAR_GLOBAL

DB5, DB6 : DBType;

END_VAR

You can now delete the converted DBsfrom your project.

Then you have to create a copy of the indexed version of the DBsby giving the corresponding POU another VAR_INPUT parameter of the type DBType. Data access within the POU must now be redirected to this instance. You must then include one of the instance DBsas an actual parameter when you open it.

4. The so-called integrated S5 function blocks that have a STEP5 access interface have a special function but their implementation is either not written in STEP5 (or MC5) or is protected by a special mechanism. POUs of this kind are generally firmware and can only be “imported as an interface”. The implementation portion of this type of POU is empty. These POUs must generally be reprogrammed after being converted.

5. There are also firmware OBsthat have no interface but whose code is in 805xx Assembler (as an example) and not in STEP5. This mainly affects the PID regulator listed as OB251 which obtains its parameters and local variables through a separate (data) block that you can select. Neither the PID regulator, the corresponding data block or other POUs that use regulators to access the data block can be converted to IEC. The IEC code that is created for data blocks and other POUs during the conversion is meaningless without the PID regulator. The meaning of the individual program parts can be found in the programming handbook for the CPU.

6. Configuration data blocks (like DB1 [S5-95U], DX0, and DX2) are sometimes used to configure S5 CPUsand other assemblies that were converted into useless IEC POUs. The meaning of much of this type of data can be found in the programming handbook for the CPU. For the rest you must use a S5 programming system that can evaluate the configuration DBs . The configuration affects settings for communication, analog value processing, multiprocessing, etc. Therefore, it is useless to even think about working with these POUs on a non-Siemens SPS.

Once the import is complete, you have to find the errors that are shown and then fix, add to and rewrite the affected spots. These spots are marked with comments like:

(*Warning! Unconvertible STEP5/7 code shown as comment:*)

This is followed by the unconvertible code which is also shown as a comment.

Finally, you must check the addresses. Original Siemens addresses are created during the import. These addresses have the following format:

Bits: Byte-Offset.Bit-Nummer

Non-Bits:Byte-Offset

Also word addresses that follow each other in sequence will overlap (simply due to the fact that the numbers in the addresses are byte offsets). This means that %MW32 and %MW33 have an overlapping byte which is %MB33 (only on a Siemens SPS). On your SPS, %MW32 and %MW33 would not normally have anything to do with each other.

Your PLC may have more hierarchies. For example, non-bits have several interlocking levels (“%MW10.0.0” as WORD). You can either make changes to the addresses to make them compatible with your PLC or you can try to leave them out entirely. Proceed very cautiously! In the original Siemens program, it is quite common that word access and bit or byte access is made in the same memory location. When imported into CoDeSys, accesses of this type will only be correctly compiled for data blocks. In this case, CoDeSys creates WORD variables for the words in the DBs . Then when WORD accesses word x in DB y there are no problems. Attempts to access the left or right byte in word x, a double word or a bit will then be compiled into more complex expressions. This cannot be done with memory locations, inputs or outputs since this can’t be done with a standard access method (e.g., word access). If you are working with %MX33.3 and with %MB33 or %MW32 or %MD30 you must go to the effort of converting them manually. The IEC program generated by the CoDeSys import will definitely not work correctly.

Open a cross reference list containing all inputs, outputs and memory locations to find out which accesses are important. Remove the mixed accesses manually.