PISO-Encoder600(U)/PISO-Encoder300(U) User’s Manual
PISO-Encoder600(U)/PISO-Encoder300(U) User’s Manual (Rev. 2.0, March/2011 PPH-018-10 ) ----- -11-
2.3.1 Initializing the control register
The first procedure is to initialize the encoder card by the control register. In the
following demo program, the first step is to set the encoder mode by 0x3C | x1_mode,
i.e., the quadrant mode is set. And then the bit 2 of control register is set to 0 to enable
the software reset mode. Finally, according to the address of
PCIBase+WR1(card[cardNo].ctrl1.base+WR1), the initial setting parameters are sent to
the control register of PISO-Encoder600(U) to confirm with the above setting. In , the
bit 2 of control register is set to 1 to disable the software reset of counter value. Similarly,
the bit 3 of control register should be set to 1 for forthcoming data latch. Therefore, the
X1-axis encoder is ready to work.
x1_mode = ENC_QUADRANT; // ENC_QUADRANT is a pre-defined constant
0x00
card[cardNo].ctrl1 = 0x3C | x1_mode; //xx11 11xx, set the counting mode
//enable software encoder reset mode,
card[cardNo].ctrl1 &= 0xFB; //1111 1011, set bit2=0 to reset the encoder counter.
outportb(card[cardNo].base + WR1, card[cardNo].ctrl1);
card[cardNo].ctrl1 |= 0x04; //0000 0100, set bit2=1 to complete the reset.
outportb(card[cardNo].base + WR1, card[cardNo].ctrl1);
2.3.2 Reading the X1-axis 32-bits encoder counter value
After initializing the encoder card, the program stated below is designated to acquire
32-bit encoder counter value, which is described in section 2.2.2.
(3a) Set the /INT=0 to inhibit counter latch. And Set B1,B0 as 00 to import byte 0
data of 32-bit counter value. Finally call inportb() function to get data and store
in unsigned long variable value;
(3b) Set B1,B0 as 01 to import byte 1 data from 32-bit counter value. The data
needs to be shifted left by 8 bits(256L) and is added to the result of counter
value in (3a);
(3c) Set B1,B0 as 10 to import byte 2 data from 32-bit counter value. Then, the data
is shifted left by 16 bits(256L*256L) and is added to the counter value in (3b);
(3d) Set B1,B0 as 11 to import byte 3 data from 32-bit counter value. Then, the data
is shifted left by 24 bits(256L*256L*256L) and is added to the counter value in
(3c);
(4) When all four bytes of the 32-bit counter value have been read, the /INT bit of
control register has to be set as 1 to enable the function of counter latch that
completes one full cycle of the reading operation for counter value.
Based on the above procedures, user can repeat (3a)~(4) to achieve continuous