Page 72 - Programmable Logic Controllers, Fifth Edition
P. 72

Table 3-7 Gray Code and Binary
                               1                                           Equivalent
                               2
                               4
                               8                           Input
                               C                           module                   Gray Code             Binary
                                                                                       0000                                0000
                                                                                       0001                                0001
                                                                                       0011                                0010
                                1s Input = 0
                                2s Input = 0                                           0010                                0011
                                4s Input = 0                                           0110                                0100
                                8s Input = 1
                                                                                       0111                                0101
                                                                                       0101                                0110
                                                                                       0100                                0111
                                                                                       1100                                1000
                               +  –
                                                                                       1101                                1001

                   Figure 3-13  BCD thumbwheel switch interfaced to a PLC.             1111                                1010
                                                                                       1110                                1011
                                                                                       1010                                1100
                                                                                       1011                                1101
                   you to change the display format of data to binary, octal,
                   decimal, hexadecimal, or ASCII.                                     1001                                1110
                                                                                       1000                                1111
                   3.7  Gray Code

                   The Gray code is a special type of binary code that does
                   not use position weighting. In other words, each position   In binary, as many as four digits could change for a
                   does not have a definite weight. The Gray code is set up   single “count.” For example, the transition from binary
                   so that as we progress from one number to the next, only   0111 to 1000 (decimal 7 to 8) involves a change in all
                   one bit changes. This can be quite confusing for count-  four digits. This kind of change increases the possibil-
                   ing circuits, but it is ideal for encoder circuits. For ex-  ity for error in certain digital circuits. For this reason,
                   ample, absolute encoders are position transducers that use   the Gray code is considered to be an error-minimizing
                   the Gray code to determine angular position. The Gray   code.
                   code has the advantage that for each “count” (each transi-  Gray codes are used with position encoders for accu-
                   tion from one number to the next) only one digit changes.   rate control of the motion of robots, machine tools, and
                   Table 3-7 shows the Gray code and the binary equivalent   servomechanisms. Figure 3-15 shows an optical encoder
                   for comparison.                                       disk that  uses  a  4-bit  Gray  code  to  detect  changes  in




                                  Thumbwheel or                                                      Decimal
                                    other input                                                      readout
                                                                      PLC
                                    6  41 9                BCD       Processor   Binary             17 65
                                                          to binary              to BCD
                                             Input                                              Output
                                            module                                             module
                                                           Input A  TOD
                                                                    To BCD
                                                                    Source     N7:23
                                                                    Destination  O:20

                                                               Convert-to-BCD instruction
                                  Figure 3-14  PLC number conversion.



                                                                                 Number Systems and Codes  Chapter 3     53







          pet73842_ch03_046-060.indd   53                                                                               03/11/15   3:50 PM
   67   68   69   70   71   72   73   74   75   76   77