D AT A C ONVERSIONS

D AT A C ONVERSIONS

Data conversion instructions change the contents of a given register from one format to another. Typical data conversion instructions include BCD-to- binary, binary-to-BCD, absolute, complement, and inversion.

A BCD-to-binary (BCD-BIN) data conversion instruction (see Figure 9-85) converts BCD input data from field devices, such as thumbwheel switches, into binary format. This conversion allows the input data to be used in math operations. Conversely, a binary-to-BCD (BIN-BCD) instruction converts data from the PLC into BCD format, so that field devices that operate in BCD (e.g., seven-segment LED indicators) can use it (see Figure 9-86).

The operation of a data conversion block is basically the same regardless of whether it is performing a BCD-BIN or a BIN-BCD conversion. When the control input is enabled, the block converts the contents of the first register (either BCD or BIN) into binary or BCD, depending on the conversion

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

instruction. It then places the result of the conversion in the second register and energizes the block output when the instruction is finished. Some PLCs allow multiple registers to be converted at the same time by specifying a length in the instruction (see Figure 9-87).

BCD number

is input into

Reg 1000

Holds BCD value

Reg 1200

Holds binary value after conversion

Reg 1200 0001011011110100 (5876 binary)

Figure 9-85. BCD-to-binary data conversion.

Reg 1000 Holds binary value Reg 1200 Holds BCD value after conversion

Reg 1200 (5876 0101100001110110

BCD)

BCD number is transferred to seven-segment LEDs via block transfer or other instruction

Figure 9-86. Binary-to-BCD data conversion.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

8 registers are converted after execution Figure 9-87. Multiple-register binary-to-BCD conversion.

Absolute, complement, and invert operations usually occur within a single register. In other words, the operation stores the result in the register location that the operand occupied. Figure 9-88 shows a typical absolute/comple- ment/invert block, which operates as follows:

• An absolute (ABS) functional block computes the absolute value (always positive) of the operand register’s contents. Thus, if register 1000 contains the value –5876, the result of the block instruction will

be +5876. This value will be stored in register 1000.

A complement (COMPL) functional block changes the sign of the operand register’s contents. For example, if register 1000 contains the value +5876, the result of the complement instruction will be –5876. Similarly, if register 1000 held the value –7654, the result of the complement would be +7654.

Absolute

ABS

• Makes number positive

COMPL

• Before execution Reg 1000 = –5,876

INV

• After execution

• Changes sign of value stored in register • Before execution Reg 1000 = +5,876 or

Reg 1000 = –7,654

• After execution

Reg 1000 = –5,876 or Reg 1000 = +7,654

Inversion

• Inverts every bit in a register • Before execution Reg 1000 = 0000 1111 0000 1111 • After execution

Reg 1000 = 1111 0000 1111 0000 Figure 9-88. Absolute/complement/invert functional block.

Industrial Text & Video Company 1-800-752-8398

www.industrialtext.com

S ECTION PLC Programming C HAPTER 3 Programming

Languages 9

• An invert (INV) functional block inverts all of the bits in the operand register. If the binary number in register 1000 is 0000 1111 0000 1111, the number will be 1111 0000 1111 0000 after the instruction, and the block output will be ON when the instruction is finished.