Programmable Logic Controllers. Su Chen Jonathon Lin

Чтение книги онлайн.

Читать онлайн книгу Programmable Logic Controllers - Su Chen Jonathon Lin страница 18

Автор:
Жанр:
Серия:
Издательство:
Programmable Logic Controllers - Su Chen Jonathon Lin

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

       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 the negative number of 150

      The binary number of 150 expressed in 16-bit word is:

      00000000100101102

      Convert each bit of this binary number as below.

image

      The binary number for –15010 in one’s complement becomes

      –15010 = 11111111011010012

      The one’s complement of a negative number expressed in binary becomes a positive number with the same quantity. The one’s complement of a negative number is obtained in the same fashion.

       Example 3.14: Find the one’s complement of binary 11010101111110012 (-1075810)

      The procedure is listed below.

image

      The binary number for the one’s complement of –1075810 becomes

      +1075810 = 00101010000001102

       3.10.3The Two’s Complement Method

      The two’s complement method is similar to the one’s complement except that only those bits after the first 1 is detected are inverted. The first 1 is examined from right to left.

       Example 3.15: Find the two’s complement of +5010

      The binary number for 5010 is 1100102

      Fill in this binary number to a 16-bit word and convert the digits as follows:

image

      The binary number for the two’s complement of +5010 becomes

      –5010 = 11111111110011102

      If a negative number is given in two’s complement, its complement becomes a positive number. Its complement is derived in the same way.

       Example 3.16: Find the two’s complement of a negative number –2110

      The binary number of –2110 given in two’s complement is

      1111111111101011

      Convert the binary number as follows:

image

      The two’s complement of –2110 becomes:

      +2110 = 00000000000101012

      A

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