Topic: DMD0024

GRAY - Gray Code to Integer


The Gray Code to Integer instruction (GRAY) converts a 16 bit Gray code value to an integer value. This instruction is designed for use with devices that use the gray code numbering scheme.

 

Gray codes are often used in linear encoders and rotary encoders in preference to straightforward binary encoding. This avoids the possibility that, when several bits change in the binary representation of an angle, a misread could result from some of the bits changing before others. Rotary encoders especially benefit from the cyclic nature of Gray codes, because the first and last values of the sequence differ by only one bit.

 

The Gray Code to Integer instruction will directly convert a gray code number to an integer for devices having a resolution of 512 or 1024 counts per revolution.

 

For a device having a resolution of 360 counts per revolution you must subtract 76 from the converted value to obtain the correct result (360-Excess-76 Gray Code).

 

For a device having a resolution of 720 counts per revolution you must subtract 152 from the converted value to obtain the correct result (720-Excess-152 Gray Code).

 

Gray Code

Binary

Decimal

0000

0000

0

0001

0001

1

0011

0010

2

0010

0011

3

0110

0100

4

0111

0101

5

0101

0110

6

0100

0111

7

1100

1000

8

1101

1001

9

1111

1010

10

1110

1011

11

1010

1100

12

1011

1101

13

1001

1110

14

1000

1111

15

.

...

...

1 0000 0001

1 1111 1110

510

1 0000 0000

1 1111 1111

511

.

...

...

10 0000 0001

11 1111 1110

1022

10 0000 0000

11 1111 1111

1023

 

Parameters:

Note: Use the F9 key (Element Browser) or Down-Arrow key (Auto-Complete) at any time to see a complete list of the memory locations that are valid in the current field of the instruction.

 

Input Value - designates the memory location that contains the Gray code value. This can be any constant value or any readable numeric location.

 

Output Value - designates a memory location to store the converted value. This can be any writable numeric location.

 


See Also:

 


Rung Example: