User's Manual
PMAC2 User Manual
88 Using the Position Compare Feature on PMAC2
Principle of Operation
When the encoder counter value matches the value in either Channel n’s Compare A Register or Compare
B Register, the compare output n is toggled from the existing state; either from 0 to 1, or from 1 to 0. The
toggling occurs on the transition from not-equal to equal in either direction.
In addition, when the counter becomes equal with one of the compare registers, the other register is
immediately incremented by the amount in the Auto-Increment register. If the encoder becomes equal by
moving in the positive direction, the value in the Auto-Increment register is added to the other compare
register. If the encoder becomes equal by moving in the negative direction, the value in the Auto-
Increment register is subtracted from the other compare register.
The user can determine the On/Off polarity of the signal by directly writing an output value to the initial
state register at any time. It is the user’s responsibility to determine whether he is in his desired On
region or the Off region when he uses the direct-write feature.
Scaling and Offset of Position Compare Registers
The position compare registers are scaled in encoder counts. A count is defined by the channel Encoder
Decode I-variable I9n0, typically with four counts per cycle or line. The compare registers are always
referenced to the position at the most recent power-up or reset, called Encoder Zero. This reference does
not change with motor homing, which changes Motor Zero, or axis offsets, which change Axis Zero. See
the Converting from Motor and Axis Coordinates section for more details.
Initial Setup
Use variable I9n1 to select whether the Channel n compare circuit will use Encoder n (I9n1=0) or the first
encoder on the ASIC, ENC1 or ENC5 (I9n1=1). Note that for Channels 1 and 5, there is no need to make
a choice; I911 and I951 always report as 1. The power-up/reset default for the other channels is I9n1=0.
Setting Up for a Single Pulse Output
If just a single compare pulse is desired (no using the auto-increment feature), the following steps should
be taken:
• Write the encoder value at the front edge into the Compare A register.
• Write the encoder value at the back edge into the Compare B register.
• Set the Auto-Increment register to zero.
• Set the initial state with the direct-write feature.
• Write a value to the initial state bit.
• Write a 1 to the direct-write enable bit (this is self-clearing to 0).
• Start the move that will cause the compare function.
DIRECTION OF MOTION
START POSITION
EQUn
COMPARE A
VALUE
COMPARE B
VALUE
Figure 16 Compare Function
For example, with the axis sitting still at about encoder position 100, and a 1 value of position compare
desired between encoder positions 1000 and 1010, the following code could be used: