Topic: DMD0024

Help File Version: 2.9.4.37

GRAY - Gray Code to Integer


The Gray Code to Integer (GRAY) instruction 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 absolute encoders, 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.

 

 

720 PPR, 360 PPR and 180 PPR encoders are designed to return a value referenced to degrees. These encoders don't naturally start counting at zero, so a MATH instruction is needed to remove the offset. The Gray Code to Integer instruction does not need to remove an offset for 512 PPR and for 1024 PPR encoders.

 

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

 

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 to open the Default Element Selection Tool (the Element Picker or the Element Browser) or use the Down-Arrow key (Auto-Complete) on any parameter field to see a complete list of the memory locations that are valid for that parameter of the instruction.

 

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

 

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

 


See Also:

FREQCNT - Frequency Counter

 

FREQTMR - Frequency Timer

 

GRAY - Gray Code to Integer

 

SCALE - Scale Value

 

SEG - Hex / BCD to 7 Segment Display

 

STR2INT - Convert String to Integer

 

STR2REAL - Convert String to Real

 

SWAPB - Swap Bytes

 


Rung Example: