Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 22 of 39

Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual: Chapter 11 - Conversion Functions

Pages 177 to 188 of 337, from Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual

The original document is the PDF (4.4 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 GE Fanuc IC692CPU211D / IC692MDR541C, Fanuc IC692CPU211D / IC692MDR541C, GE IC692CPU211D / IC692MDR541C and GE Fanuc IC693CPU311X

Page 177

Chapter

Conversion Functions

11 Use the conversion functions to convert a data item from one number type to another. Many programming instructions, such as math functions, must be used with data of one type. This section describes the following conversion functions:

GFK-0467M

Abbreviation

Function

BCD-4

Convert to BCD-4

Description Convert a signed integer to 4-digit BCD format.

Page 11-2

INT

Convert to Signed Integer

Convert BCD-4 or REAL to signed integer.

11-3

DINT

Convert to Double Precision Convert REAL to double precision signed Signed Integer integer format.

11-5

REAL

Convert to REAL

Convert INT, DINT, BCD-4, or WORD to REAL.

11-7

WORD

Convert to WORD

Convert REAL to WORD format.

11-9

TRUN

Truncate

Round the real number toward zero.

11-11

11-1

Page 178

11, >BCD-4 (INT) The Convert to BCD-4 function is used to output the 4-digit BCD equivalent of signed integer data. The original data is not changed by this function. Data can be converted to BCD format to drive BCD-encoded LED displays or presets to external devices such as high-speed counters. When the function receives power flow, it performs the conversion, making the result available via output Q. The function passes power flow when power is received, unless the specified conversion would result in a value that is outside the range 0 to 9999.

Enable

Value to be converted

INT_ TO_ BCD4

OK

IN

Converted value

Q

Parameters Parameter

Description enable IN ok

When the function is enabled, the conversion is performed. IN contains a reference for the integer value to be converted to BCD-4. The ok output is energized when the function is performed without error.

Q

Output Q contains the BCD-4 form of the original value in IN.

Valid Memory Types Parameter flow enable

•

IN ok Q •

%I

%Q

%M

%T

•

•

•

•

%S

%G

%R

%AI

%AQ const

•

•

•

•

•

• none

• •

•

•

•

•

•

•

•

Valid reference or place where power may flow through the function.

Example In the following example, when input %I0002 is set and no errors exist, the integer at input location %M0017 through %M0032 is converted to four BCD digits, and the result is stored in memory locations %Q0033 through %Q0048. Coil %M0032 turns on to verify successful conversion. | _____ |%I0002 | | %M0032 | - - | | - - - | INT_| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( ) - | | TO_ | | | | | | BCD4| | %M0017 - |IN Q| - %Q0033 | |_____| |

11-2

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 179

11, >INT

(BCD-4, REAL) The Convert to Signed Integer function is used to output the integer equivalent of BCD-4 or REAL data. The original data is not changed by this function.

Note The REAL data type is only available on 35x and 36x series CPUs, Release 9 or later, and on all releases of CPU352 and CPU37x. When the function receives power flow, it performs the conversion, making the result available via output Q. The function always passes power flow when power is received, unless the data is out of range. Enable

Value to be converted

BCD4_ TO_ INT

OK

IN

Converted value

Q

Parameters Parameter

Description enable

When the enable input is on, the conversion is performed.

IN

IN contains a reference for the BCD-4, REAL, or Constant value to be converted to integer.

ok

The ok output is energized whenever enable is energized, unless the data is out of range or NaN (Not a Number).

Q

Output Q contains the integer form of the original value in IN.

Valid Memory Types Parameter flow enable

•

IN ok Q

%I

%Q

%M

%T

•

•

•

•

%S

%G

%R

%AI

%AQ const

•

•

•

•

•

• none

• •

•

•

•

•

•

•

•

Note: For REAL data, the only valid types are %R, %AI, and %AQ. •

GFK-0467M

Valid reference or place where power may flow through the function.

Chapter 11 Conversion Functions

11-3

Page 180

11

Example 1 – BCD4 to Integer In the following example, whenever input %I0002 is set, the BCD-4 value in PARTS is converted to a signed integer and placed in %R0001. In the following ADD function, %R0001 is added to the signed integer value represented by the reference RUNNING. The sum is output by the ADD function to the reference TOTAL. | _____ _____ |%I0002 | | | | | - - | | - - - |BCD4_| - - - - - - - - - - - - - - - - | ADD_| - | | | | | | | TO_ | | INT | | | | | | | | INT | | | | PARTS -|IN Q|- %R0001 %R0001 |I1 Q|- TOTAL | |_____| | | | RUNNING-|I2 | | | |, - - - - Example 2 – Real to Integer This example shows conversion of a real number at %R0101 to an integer number at %R0200. When the enable input contact %M0100 is on, the conversion takes place. Note that during the conversion, the real number is rounded to the nearest integer. If the decimal portion of the real number is 0.5 or greater, the resulting integer is rounded up by a value of 1. If the decimal portion of the real number is less than 0.5, this decimal portion is discarded and the integer number is not rounded up. In the example below, real value 378.9462 is rounded up to integer value 379. If rounding is not wanted, use the REAL_TRUN_INT function, which truncates the decimal portion of the real number, regardless of its value, during the conversion.

%M0101

%M0100

REAL_ TO_ INT %R0101 +378.9462

11-4

IN

Q

%R0200 +00379

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 181

11, >DINT (REAL) The Convert to Double Precision Signed Integer function is used to output the double precision signed integer equivalent of real data. The original data is not changed by this function.

Note The REAL data type is only available on 35x and 36x series CPUs, Release 9 or later, and on all releases of CPU352 and CPU37x. When the function receives power flow, it performs the conversion, making the result available via output Q. The function always passes power flow when power is received, unless the real value is out of range. _____ | | (enable), | REAL| - (ok) | | | TO_ | | | | DINT| (value to be converted), |IN Q| - (output parameter Q) |_____|

Parameters Parameter enable

Description When the function is enabled, the conversion is performed.

IN

IN contains a reference for the value to be converted to double precision integer.

ok

The ok output is energized whenever enable is energized, unless the real value is out of range.

Q

Q contains the double precision signed integer form of the original value in IN.

Note It is possible for a loss of precision to occur when converting from REAL to DINT since the REAL has 24 significant bits.

Valid Memory Types Parameter flow enable

•

IN ok

•

%I

%Q

%M

%T o o o o

%S

%G

%R %AI %AQ const o

Q •

GFK-0467M

•

•

•

•

•

• none

• •

Valid reference or place where power may flow through the function.

Chapter 11 Conversion Functions

11-5

Page 182

11 Example In the following example, whenever enable input %M0100 is on, the real value at input location %R0101 is converted to a double precision signed integer, and the result is placed in location %R0200. Note that during the conversion, the real number is rounded to the nearest integer. If the decimal portion of the real number is 0.5 or greater, the resulting integer is rounded up by a value of 1. If the decimal portion of the real number is less than 0.5, this decimal portion is discarded and the integer number is not rounded up. In the example below, real value 7890.542 is rounded up to double integer value 7891. If rounding is not wanted, use the REAL_TRUN_DINT function, which truncates the decimal portion of the real number, regardless of its value, during the conversion.

%M0101

%M0100

REAL_ TO_ DINT %R0101 +7890.542

11-6

IN

Q

%R0200 +0000007891

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 183

11, >REAL (INT, DINT, BCD-4, WORD) The Convert to Real function is used to output the real value of the input data. The original data is not changed by this function. When the function receives power flow, it performs the conversion, making the result available via output Q. The function passes power flow when power is received, unless the specified conversion would result in a value that is out of range. It is possible for a loss of precision to occur when converting from DINT to REAL since the number of significant bits is reduced to 24.

Note This function is only available on 35x and 36x series CPUs, Release 9 or later, and on all releases of CPU352 and CPU37x. _____ | | (enable), | INT_| - (ok) | | | TO_ | | | | REAL| (value to be converted), |IN Q| - (output parameter Q) |_____|

Parameters Parameter enable

Description When the function is enabled, the conversion is performed.

IN

IN contains a reference for the integer value to be converted to REAL.

ok

The ok output is energized when the function is performed without error.

Q

Q contains the REAL form of the original value in IN.

Valid Memory Types Parameter flow enable

•

IN ok

%I

%Q

%M

%T o o o o

%S

%G

%R

%AI

%AQ const o

•

•

•

•

•

•

•

•

Q • o

GFK-0467M none

•

Valid reference or place where power may flow through the function. Not valid for DINT_TO_REAL.

Chapter 11 Conversion Functions

11-7

Page 184

11 Example 1 - Integer to Real Conversion In the following example, the integer value of input IN is +07891. The resulting value placed in %R0200 after the conversion to real format is +7891.000. %M0101

%M0100

INT_ TO_ REAL %R0101 +07891

IN

Q

%R0200 +7891.000

Example 2 – Double Integer to Real Conversion In the following example, the double integer value of input IN is +1234567891. The resulting value placed in %R0200 after the conversion to real format is +1234568000. Note that a double integer number has 10 significant places, but a real number has only 7 significant places; therefore, an integer number is rounded to 7 significant places during the conversion to a real number. In the example shown, the four least significant digits, 7891, of the double integer number are rounded to 8000 in the four least significant digits of the real number. %M0101

%M0100

DINT_ TO_ REAL %R0101 +1234567891

11-8

IN

Q

%R0200 +1234568000.

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 185

11, >WORD (REAL) The Convert to WORD function is used to output the WORD equivalent of real data. The original data is not changed by this function.

Note This function is only available on the 35x, 36x, and 37x series CPUs. When the function receives power flow, it performs the conversion, making the result available via output Q. The function passes power flow when power is received, unless the specified conversion would result in a value that is outside the range 0 to FFFFh. _____ | | (enable), | REAL| - (ok) | | | TO_ | | | | WORD| (value to be converted), |IN Q| - (output parameter Q) |_____|

Parameters Parameter enable

Description When the function is enabled, the conversion is performed.

IN

IN contains a reference for the value to be converted to WORD.

ok

The ok output is energized when the function is performed without error.

Q

Q contains the unsigned integer form of the original value in IN.

Valid Memory Types

•

GFK-0467M

Parameter flow enable IN

• ok Q

•

%I

%Q

%M

%T

%S

%G

%R

%AI

%AQ const

•

•

•

•

•

•

• none

• •

•

•

•

•

Valid reference or place where power may flow through the function.

Chapter 11 Conversion Functions

11-9

Page 186

11

Example – Real to Word Conversion In this example, since the RANGE function is not available as a REAL type, the real value in %R0001 is first converted to a word value (at %R0003), which is then used as the input to the following RANGE WORD function. The table below shows the values at the various inputs and outputs for the following figure.

Item

Value or State

%R0001

15767.83

%R0003

3A89h (15,768 decimal)

HI LIM

4E20h (20,000 decimal)

LOW LIM

2710h (10,000 decimal)

Q1

ON

| _____ _____ |%I0002 | | | | | - - | | - - - |REAL_| - - - - - - - - - - - - - - - - |RANGE| - | | | | | | | TO_ | | WORD| | | | | | | | WORD| | | %Q0001 | %R0001 - |IN Q|-%R0003 HI_LIM-|L1 Q| - - - ( ) - - - - | |_____| | | | | | | LOW_LIM-|L2 | | | | | | | | %R0003-|IN | |, - - - - 11-10

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 187

11

TRUN (INT, DINT) The Truncate function is used to round a real number toward zero. During the conversion, all numbers to the right of the decimal place are discarded in the output number. The original number is not changed by this function.

Note The 35x and 36x series CPUs (Release 9.00 or later and all releases of CPU352), and 37x are the only Series 90-30 CPUs with floating point capability; therefore, the TRUN function has no applicability for other 90-30 CPUs. When the function receives power flow, it performs the conversion, making the result available via output Q. For CPU 352, the function passes power flow when power is received, unless the specified conversion would result in a value that is out of range or unless IN is NaN (Not a Number). For all other 35x and 36x/37x series CPUs, the function does not pass power. _____ | | (enable), |REAL_| - (ok) | | |TRUN_| | | | INT | (value to be converted), |IN Q| - (output parameter Q) |_____|

Parameters Parameter

Description

Enable

When the function is enabled, the conversion is performed.

IN

IN contains a reference for the real value to be truncated.

Ok

The ok output is energized when the function is performed without error, unless the value is out of range or IN is NaN.

Q

Q contains the truncated INT or DINT value of the original value in IN.

Note It is possible for a loss of precision to occur when converting from REAL to DINT since the REAL has 24 significant bits.

Valid Memory Types Parameter flow enable

•

IN ok

•

Q • o

GFK-0467M

%I

%Q

%M

%T

%S

%G

%R

%AI

%AQ const

•

•

•

•

•

•

• none

• o o o o o

Valid reference or place where power may flow through the function. Valid for REAL_TRUN_INT only.

Chapter 11 Conversion Functions

11-11

Page 188

11 Example 1 – Truncate Real to Integer with Output Coil for CPU352 In the following example, the value at %R0101 is truncated (the decimal portion is discarded) and the resulting integer value of +05432 is placed into %R0200. . If a CPU352 were used, %M0101 would turn on, indicating a successful conversion. If any other 35x, 36x, or 37x CPU is used, no power flow is produced at the OK output, so no output coil would be programmed.

%M0101

%M0100

REAL_ TRUN_ INT %R0101 +5432.765

IN

Q

%R0200 +05432

Example 2 – Truncate Real to Double Integer with Output Coil for CPU352 In the following example, the value at %R0101 is truncated (the decimal portion is discarded) and the resulting double integer value of +0000005432 is placed into %R0200. If a CPU352 were used, %M0101 would turn on, indicating a successful conversion. If any other 35x, 36x, or 37x CPU is used, no power flow is produced at the OK output, so no output coil would be programmed.

%M0101

%M0100

REAL_ TRUN_ DINT %R0101 +5432.765

11-12

IN

Q

%R0200 +0000005432

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M