Su Chen Jonathon Lin

Programmable Logic Controllers


Скачать книгу

hexadecimal equivalent of 101100111010102 becomes 2CEA16.

       3.6.10Converting Hexadecimal to Binary

      Converting a hexadecimal number to its binary equivalent is the reverse of converting binary to hexadecimal. It involves the following two steps:

      •Convert each hexadecimal digit to its 4-digit equivalent.

      •Assemble the binary equivalent values in the proper sequence.

       Example 3.11: Converting A3C16 to its binary equivalent

      The converting process is as follows:

image

      The binary equivalent of A3C16 becomes 1010001111002.

      The operation of PLCs involves manipulation, transmission, and storage of data in various forms. PLCs are digital devices that can readily handle binary data. However, binary data in series of ones and zeros are intuitively difficult for humans to understand and interpret. The binary data must be converted to interpretable formats of numerals, letters, and symbols. The techniques to assign binary patterns to numerals, letters, and symbols are referred to as binary encoding. Several binary coding standards have been established. Some commonly used binary coding standards are ASCII, BCD, and Gray codes. They are introduced in the following three sections.

      ASCII code, pronounced as-kee, stands for American Standard Code for Information Interchange. This coding standard provides a set of alphanumeric characters to be used for information interchange in communication systems, computing systems, and peripheral equipment manufactured by different vendors.

      ASCII code can be 6, 7, or 8 bits. A 6-bit code can represent a total of 64 (or 26) possible characters; 7-bit code for 128 (or 27) characters; and 8-bit code for 256 (or 28) characters. Standard ASCII uses a 7-bit code with 128 possible characters to represent upper and lower case alphabets, 0 through 9 numerals, punctuation marks, standard symbols, and other special symbols. The 8-bit ASCII character set is referred to as extended ASCII. The 8-bit ASCII set allows the parity check function to be added to a standard 7-bit code (Table 3.9). In communication, parity checking refers to the use of parity bits to check that data has been transmitted accurately. The parity bit is added to every data unit (typically 7 or 8 bits) that is transmitted.

      The development of binary coded decimal (BCD) arose from the need for allowing data to be input to, and output from, digital devices such as computers and PLCs, in the form of decimal numbers. The purpose of BCD code is to facilitate the communication between the operator and digital devices; that is, to allow humans to use decimal numbers and digital devices to process binary numbers. BCD represents each of ten decimal numbers (0 – 9) as a 4-bit binary number. Table 3.10 summarizes the binary and BCD equivalents of ten decimals (0 – 9).

      The BCD representation of a decimal number can be readily obtained by replacing each decimal digit by its BCD equivalent, which can be found from Table 3.10.

      Table 3.9: Partial listing of 8-bit ASCII code

image

      Table 3.10: Binary and BCD equivalents of ten decimals (0 – 9)

DecimalBinaryBCD
000000
1010001
2100010
3110011
41000100
51010101
61100110
71110111
810001000
910011001

       Example 3.12: Deriving the BCD equivalent for a decimal number 5763

      The four digits in the decimal number 5763 are replaced by four 4-digit groups of equivalents. It has a total of 16 binary bits to represent this 4-digit decimal number. The BCD equivalent of this number is as follows:

image

      The Gray code is a set of modified binary code that is designed to suit in such applications for which only one bit changes as the counting number increases. This means that the sequential numbers must not have more than one bit changes as the count increments by one. This code is especially useful in working with transducers for linear and angular position sensing. Table 3.11 summarizes the Gray code with binary and decimal equivalents.

       3.10.1Basic Data Structure

      The data in PLCs is stored in binary word format. A word normally consists of two bytes, each having eight bits. A byte of 8 bits can express a maximum value of 255 decimals (Figure 3.6). The right-most bit in a one-byte word is called the least significant bit and left-most bit, the most significant bit. A two-byte word is used to express numbers larger than 255. It can hold up to 65535 decimals (Figure 3.7). With the signed decimal format, a two-byte word can store up to +32767 decimal numbers and up to –32767 decimal numbers (Figure 3.8).

      PLCs use two words of 16 bits to store decimal numbers larger than +32,767. Two words of 16 bits form a 32-bit decimal format (Figure 3.9). This 32-bit decimal format is referred to as double precision. With the signed numbers, a double precision word can have the maximum decimal value of +2,147,483,647 and the smallest value of –2,147,483,647.

      Table 3.11: Gray code with binary and decimal equivalents.

Gray CodeBinaryDecimal
000000
000111
0011102
0010113
01101004
01111015
01011106
01001117
110010008
110110019
1111101010
1110101111
1010110012
1011110113
1001111014
1000111115
image

      Figure 3.6: One-byte word

image

      Figure 3.7: Two-byte word

image

      Figure 3.8: Signed decimal numbers

image

      Figure 3.9: Double precision

       3.10.2The One’s Complement Method

      Two methods are used to represent negative numbers in PLCs: one’s complement and two’s complement. With the one’s complement method, a negative number is obtained by inverting or complementing each bit of the positive binary number. Inverting a bit means to change 1 to 0 and 0 to 1. The procedure of one’s complement is as follows (using 16-bit word format):

      •Express the decimal number in the binary form with a positive sign.

      •Complement each bit.

       Example 3.13: Use the one’s complement method to express