|
Description In STEP 7 (TIA Portal), you can use the conversion functions from the "Instructions" and "Advanced Instructions" palettes to convert the contents of the variables to selected data types for the S7-1200/1500. Fig. 01 gives you an overview of the most used conversions.

Fig. 01
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. Proceed as described in the table below to insert and parameterize this operation in your block editor.
| No. |
Procedure |
| 1 |
In the block editor, open the "Instructions" palette and open the "Converters" folder. Then use drag-and-drop to insert the "CONVERT" instruction into your network. |
| 2 |
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. |
| 3 |
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). |
| 4 |
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").
Note
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. |
| 5 |
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 UINT 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 UINT 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.
Note
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.

Fig. 02
|
Table 01
Rounding of REAL numbers
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 three advanced instructions from STEP 7 (TIA Portal) for converting the STRING data type into a numerical value and vice versa. The procedure for programming this is identical to that described in Table 01.
| Advanced Instructions |
Description |
| S_CONV |
A digit string (STRING) is converted into a number value or a number value is converted into a digit string (STRING).
- Convert the STRING data type to USINT, SINT, UINT, INT, UDINT, DINT, CHAR, LREAL and REAL.
- Convert the USINT, SINT, UINT, INT, UDINT, DINT, CHAR, LREAL and REAL data types to STRING.
- Copy a character string (STRING to STRING).
|
| STRG_VAL |
Convert a digit string into the relevant whole number or floating point display. |
| VAL_STRG |
Convert a whole number value with or without sign or a floating point value into the relevant digit string display. |
Table 02
Conversion into the TIME data format Using the advanced instruction "T_CONV" you convert a numerical value of the DINT 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 Instructions >Date and Time"" palette. Fig. 03 shows an sample conversion of INT and REAL number values into the TIME data format.

Fig. 03
Further Information
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.
Creation environment
The screens in this FAQ response were created with STEP 7 V11.0+SP2.
|