The conversion function CONV converts the data types of fixed-point numbers. Fig.
13.11 shows the general representation of the conversion function in the various programming languages. CONV is represented as an EN/ENO box in the case of LAD and FBD, as operations in the case of STL which convert the value in accumulator 1, and in the case of SCL there are functions with the notation Source data type_TO_Destination data type.
The conversion options additionally offered by SCL are described in Chapter 10.5.5
“Conversion functions” on page 413.
Setting of status bits and of the ENO output
If an error occurs when converting a fixed-point number to a BCD number, the sta- tus bits OV Exception Bit Overflow and OS Exception Bit Overflow Stored are set to “1”, the ENO output is set to “0”, and with SCL the ENO tag is set to FALSE.
Table 13.8 Implicit data type conversion to
from BOOL BYTE WORD DWORD INT DINT REAL TIME S5TIME DT TOD DATE CHAR STRING
BOOL XS XS XS
BYTE X X O
WORD X O
DWORD O
INT XS XS
DINT XS O OS
REAL
TIME O O
S5TIME O
DT TOD DATE
CHAR O OS OS XS
Implicit data type conversion is possible: X Independent of attribute IEC check O With deactivated attribute IEC check
XS Additionally with SCL and independent of attribute IEC check OS Additionally with SCL and deactivated attribute IEC check
Master control relay (MCR) dependency
The (actual) conversion function which changes the content of accumulator 1 is independent of the MCR function. Saving of the result of a conversion with an EN/ENO box (LAD, FBD) or with a transfer statement (STL) only takes place with the MCR functionality switched off. Zero is saved if the MCR function is switched on.
Conversion of INT to DINT
The function interprets the input value as a number with data type INT and trans- fers it to the right word of the output value. The signal state of bit 15 (the sign) of the input is transferred to bits 16 to 31 of the left word of the output value.
The conversion of INT to DINT does not report any errors.
Conversion of INT to BCD
The function interprets the input value as a number with data type INT and converts it into a BCD-coded number with 3 decades. The 3 right-justified decades represent the absolute value of the decimal number. The sign is present in bits 12 to 15. If all Fig. 13.11 Function and representation of the conversion function CONV
CONV CONV
DT1 to DT2
EN EN
OUT
OUT ENO
ENO Conversion of fixed-point numbers (CONV) LAD
STL
SCL
FBD
IN IN
Declaration Name
EN ENO IN OUT
- - INPUT OUTPUT
BOOL BOOL Data type 1 Data type 2
Enabling input Enabling output Input tag Output tag Description Data type
DT1 to DT2
Function: CONV
DT1 DT2
DT1 DT2 AWL operation SCL statement
//Example of a conversion from DINT to REAL
#var_real := DINT_TO_REAL (#var_dint);
L #var_dint //Example of a conversion from DINT to REAL DTR
T #var_real OUT := CONV(IN)
bits are set to signal state “0”, the sign is positive; all bits set to signal state “1”
means a negative sign.
If the INT number is too large for conversion into a BCD number (> 999), a conver- sion does not take place and the function sets the status bits OV and OS to “1”. The binary result and the ENO output are then set to signal state “0” in the case of LAD and FBD and the ENO tag and the ENO output to FALSE in the case of SCL.
Conversion of DINT to BCD
The function interprets the input value as a number with data type DINT and con- verts it into a BCD-coded number with 7 decades as the output value. The 7 right-jus- tified decades represent the absolute value of the decimal number. The sign is pres- ent in bits 28 to 31. If all bits are set to signal state “0”, the sign is positive; all bits set to signal state “1” means a negative sign.
If the DINT number is too large for conversion into a BCD number (> 9 999 999), a conversion does not take place and the function sets the status bits OV and OS to
“1”. The binary result and the ENO output are then set to signal state “0” in the case of LAD and FBD and the ENO tag and the ENO output to FALSE in the case of SCL.
Conversion of DINT to REAL
The function interprets the input value as a number in DINT format and converts it into a number in floating-point format REAL.
Since a number in DINT format has a greater accuracy than a number in REAL for- mat, rounding off may take place during conversion. It is rounded to the next inte- ger (corresponding to the ROUND function).
The function does not report any errors.
Conversion of BCD to INT
The function interprets the input value as a BCD-coded number with 3 decades and converts it into an INT number. The 3 right-justified decades represent the absolute value of the decimal number. The sign is present in bits 12 to 15. Signal state “0” of these bits means “positive”, signal state “1” means “negative”. Only the signal state of bit 15 is considered during conversion.
If a pseudo tetrad (numerical value 10 to 15 or A to F in hexadecimal representa- tion) is present in the BCD-coded number, the CPU signals a programming error and calls the organization block OB 121 Programming error. If this is not present, the CPU switches to the stop status.
The function does not set any status bits.
Conversion of BCD to DINT
The function interprets the input value as a BCD-coded number with 7 decades and converts it into an DINT number. The 7 right-justified decades represent the abso- lute value of the decimal number. The sign is present in bits 28 to 31. Signal state
“0” of these bits means “positive”, signal state “1” means “negative”. Only the signal state of bit 31 is considered during conversion.
If a pseudo tetrad (numerical value 10 to 15 or A to F in hexadecimal representa- tion) is present in the BCD-coded number, the CPU signals a programming error and calls the organization block OB 121 Programming error. If this is not present, the CPU switches to the stop status.
The function does not set any status bits.