In STEP 7 (TIA Portal), how do you convert the data types for the S7-1200/S7-1500?
The table below (Fig. 1) gives you an overview of the most used conversions.
Conversion of data types INT, DINT, REAL and BCD numbers
STEP 7 (TIA Portal) provides the operation "CONV" (convert) to convert the data types INT, DINT, REAL and BCD numbers. Follow the instructions below to insert and parameterize this operation in your block editor.
- In the block editor you open the "Instructions" palette and then the folder "Simple Instructions > Converters". Use drag-and-drop to insert the "CONVERT" instruction in your network.
- After inserting the instruction box, the instruction data types are still not defined and under "CONV" you still see the wildcard characters "??? to ???". When you move the cursor over the left triangle of the first three question marks, an arrow key is displayed.
- Click the left arrow key and from the drop-down menu that opens you select the desired data type for the input parameter "IN" (INT, for example).
- Repeat the procedure for the output parameter "OUT" and from the drop-down menu on the right you select the data type to which you wish to convert the number value (REAL, for example). In this example you can convert a number value of the data type INT into the data type REAL ("Int to Real").
If you parameterize the input and output parameters directly with the variables, the instruction is defined automatically with the associated data types and Steps 2 to 4 above are not necessary.
- Parameterize the inputs and outputs of the converter with the variables of your choice. After parameterizing the inputs and outputs you can convert the number values below, for example.
- From Int to Int, DInt, Real, Bcd16, USint, UInt, UDint, SInt, LReal and Char
- From DInt to Int, DInt, Real, Bcd32, USint, UInt, UDint, SInt, LReal and Char
- From Real to Int, DInt, Real, USint, UInt, UDint, SInt and LReal
- From USint to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
- From UInt to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
- From UDint to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
- From SInt to Int, DInt, Real, USint, UInt, UDint, SInt, LReal and Char
- From LReal to Int, DInt, Real, USint, UInt, UDint, SInt and LReal
- From Char to Int, DInt, USint, UInt, UDint, SInt and Char
- From BCD16 (16-bit) to Int,
- From BCD32 (32-bit) to DInt.
Notes on the CONVERT instruction
Fig. 2 shows an example of data conversion from the BCD format to Real and from Byte to SInt.
- A number value in the BCD format must first be converted into the data type Int or DInt before you can convert it into the data type REAL, for example.
- If you perform a data type conversion from Byte to SInt or from Byte to USInt, with the CONVERT instruction you must manually set the data type SInt or USInt at the input and output.
Further information is available in the STEP 7 (TIA Portal) Online Help and under CONVERT: Convert value.
The instructions below are available for you to round a number value of the data type REAL to a whole number (INT or DINT). These instructions are in the "Converters" folder as described above.
- "CEIL": Rounding up to the next whole number.
- "FLOOR": Rounding down to the next whole number.
- "ROUND": Rounding to the next whole number.
- "TRUNC": No rounding.
Conversion of STRING data types
The table below contains instructions for converting the String data type. The procedure for programming this is identical to that described in the instructions.
|S_CONV||Convert character string|
|STRG_VAL||Convert character string to number value|
|VAL_STRG||Convert number value to character string|
|Strg_TO_Char||Convert character string to array of CHAR|
|Char_TO_Strg||Convert array of CHAR to character string|
|ATH||Convert ASCII character string to hexadecimal number|
|HTA||Convert hexadecimal number into ASCII character string|
Conversion to the TIME data format
Using the advanced instruction "T_CONV" you convert a numerical value of the INT data type into a time stamp (TIME) and vice versa. You must convert all other data types (INT, REAL, BCD, ...) into the DINT data type before you can convert them into the TIME data type. The "T_CONV" instruction is located in the block editor in the "Advanced" palette in the folder "Advanced Instructions > Date and Time".
Fig. 3 shows a conversion example of INT and REAL number values into the TIME data format.
The hardware data type HW_IO is for identifying a hardware module that STEP 7 (TIA Portal) uses to access the information of a module. This identification number is assigned automatically when creating the device configuration and is stored in the properties of the device in the HW Config. It is also available under the module name as system constant in the "PLC variables" list. In this way the module can be used directly through its name in the corresponding blocks.
More information on programming and parameterizing the instructions mentioned above is available in the STEP 7 (TIA Portal) Online Help. To obtain the Online Help you mark the instruction and press the "F1" key.
The screens in this FAQ response were created with STEP 7 (TIA Portal) V15.