Let G[n:0] be the input array of bits in Gray code
Let B[n:0] be the output array of bits in the usual binary representation
B[n] = G[n]
for i = n-1 downto 0
B[i] = B[i+1] XOR G[i]
GRAY CODE CONVERSION (GRY(474)) for Easy Conversion of Parallel Inputs from Absolute Encoders
to Binary, BCD, or Angle Data
This instruction converts Gray binary codes to binary, BCD, or angle data.
This enables easily handling position or angle data input as parallel signals
(2n) from an Absolute Encoder with a Gray code output using a DC Input Unit.
L #IN0 // IW encoder
T #encod_gray_dec // LW0
SET
R L 0.7
R L 0.6
R L 0.5
R L 0.4
R L 0.3
R L 0.2
AN L 0.1
JC M003
AN L 0.0
= L 0.0
M003: AN L 0.0
JC M004
AN L 1.7
= L 1.7
M004: AN L 1.7
JC M005
AN L 1.6
= L 1.6
M005: AN L 1.6
JC M006
AN L 1.5
= L 1.5
M006: AN L 1.5
JC M007
AN L 1.4
= L 1.4
M007: AN L 1.4
JC M008
AN L 1.3
= L 1.3
M008: AN L 1.3
JC M009
AN L 1.2
= L 1.2
M009: AN L 1.2
JC M010
AN L 1.1
= L 1.1
M010: AN L 1.1
JC M011
AN L 1.0
= L 1.0
M011: NOP 0
L #encod_gray_dec
T #OUT1 //decimaly out encoder