Decoding gray code, Plc output, Models ddn & ddp – Electro Cam PS-4456 Absolute Gray Code Encoder User Manual
Page 3: Model ddh, O:2.0 ( ) 0

Use a limit test function to program a pulse in the PLC. The limit test uses a test reference (in this case the integer
register that the Gray Code is going into), and compares it to see if it is between a lower limit and an upper limit. If the
integer value is between the lower limit (ON setpoint), and the upper limit (OFF setpoint), the rung is true and an output
is turned on. If the integer value does not fall between the upper and lower limits, the rung is false, and nothing happens.
For every output pulse to occur, a different limit test must be programmed with the appropriate limits. Reminder: The
limit values are position values, not degrees.
Decoding Gray Code?
The Ladder Programming examples shown below apply
for all Gray Code Encoder models. The examples show
how to convert the 8 Bit Gray Code output signal (G0-G7)
of the encoder to a binary number (B0-B7) during each
scan of the PLC. The value of the Binary result will al-
ways be in the range of 0 - 255 because the 8 bit encoder
divides each revolution into 256 uniform increments. Lad-
der rungs which follow the conversion can compare the
rotary position value to known positions for control of
machine devices that must operate at specific positions
within the overall machine cycle. The rotary position of
the machine cycle can also be used to gate input sensors
and shift register functions.
Converting Gray Code to Binary involves a sequence of
"Exclusive OR" operations. It is simple to program this
same conversion logic in other programming languages
besides ladder logic. In addition to decoding the rotary
position of the encoder, controls with arithmetic capability
can be programmed to perform direction reversal, posi-
tion offset and re-zero functions, as well as convert the
position value to degrees for ease of monitoring and setup.
3
Limit Test
Low Lim
107
107 <
Test
N7:0
0 <
High Lim
128
128 <
PLC
Output
O:2.0
( )
0
LIM
Models DDN & DDP
G7
B7
B7
G6
B6
G6
B7
B6
G5
B5
G5
B6
B5
G4
B4
G4
B5
B4
G3
B3
G3
B4
B3
G2
B2
G2
B3
B2
G1
B1
G1
B2
B1
G0
B0
G0
B1
CLOCKWISE ROTATION
DRAWING L-1
G7
B7
B7
G6
B6
G6
B7
B6
G5
B5
G5
B6
B5
G4
B4
G4
B5
B4
G3
B3
G3
B4
B3
G2
B2
G2
B3
B2
G1
B1
G1
B2
B1
G0
B0
G0
B1
COUNTER-CLOCKWISE ROTATION
DRAWING L-2
G7
B7
B7
G6
B6
G6
B7
B6
G5
B5
G5
B6
B5
G4
B4
G4
B5
B4
G3
B3
G3
B4
B3
G2
B2
G2
B3
B2
G1
B1
G1
B2
B1
G0
B0
G0
B1
COUNTER-CLOCKWISE ROTATION
DRAWING L-3
CLOCKWISE ROTATION
DRAWING L-4
G7
B7
B7
G6
B6
G6
B7
B6
G5
B5
G5
B6
B5
G4
B4
G4
B5
B4
G3
B3
G3
B4
B3
G2
B2
G2
B3
B2
G1
B1
G1
B2
B1
G0
B0
G0
B1
Model DDH