© 1998 Motion Corporation |
One of the main issues for many users in terms of their rotary optical encoder needs is the available disk resolution or cycles/revolution that is required to satisfy their system motion control parameters. Generating special encoding and decoding schemes to meet these special motion control parameters may not always result in a cost effective system. However, the following paragraphs incorporate the data from a simple QBASIC program listed below, (an EXCEL spreadsheet can also be used) to generate "non-standard" code which can be cost effectively used in the new design of most rotary optical encoders.
Two output signal in quadrature are normally provided. These signals yield a resolution of 16384 counts per revolution. The angular resolution for this encoder 1.32 minutes. The problem with any incremental encoder is the loss of any pulse or interruption of the pulse train produces errors in any succeeding angular measurement. Absolute optical encoders however, output a code which defines in a unique manner the discrete angular position of the rotary shaft. A 12 bit absolute encoder (Figure 2) would also encode each 5.27 minutes of the 360° of the shaft rotation. Even if the encoder shaft stops rotating, the angular position information is still available to the motion control system.
Consider the problem as to which code should be used to define the angular position information for the absolute encoder. The most obvious selection is natural binary. Now we can process the encoder output data with minimal conversion, The difficulty using natural binary is the character of-the coded information that is extracted from a rotating optical disc (Figure 3 indicates a series of various disc sizes). Synchronization and data capture at the bit transition boundary is the real issue. Thus, from binary 7 (0111) to binary 8 (1000) there are 4 bit changes in the coding pattern. This transition pattern may result in errors or problems of ambiguity between successive numbers. Codes that satisfy the requirement that there is only a single bit change between successive numbers are called unit-distance codes, reflective codes, or cyclic codes. One of the most popular cyclic code is called the Gray code. This unit distance or cyclic code is related to natural binary representation of decimal information by the following logic equation.
The term GJ represents the jth bit of the Gray code and bj represents the jtb bit of the natural binary code. The Gray code is generated by the exclusive OR of adjacent binary bits. Solving the inverse of this logic equation we obtain the computation of binary information from a Gray code.
DECIMAL BINARY GRAY
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
TABLE 1
This table represents 4 bits
(24) of coded information. In order to perform a generalized Gray
code conversion the following program written for 13 bit conversion in QBASIC
enables the user to relate decimal, Gray, and Hexadecimal Gray from 0 to 8191.
REM CONVERSION OF DECIMAL TO GRAY CODE 13 BITS PRINT SPC(4); "DEC"; SPC(4); "BIN EQ GRAY"; SPC(7); "GRAY"; SPC(2); "HEX" DIM E(12) FOR bin=0 TO 8191 a=bin: b=INT(bin/2) gray=aXORb d=gray/2 h=INT(d) IF bin THEN PRINT SPC(5), bin; SPC(2); ELSE IF bin=10 AND bind THEN PRINT SPC(4); bin; SPC(2); IF bin=100 AND bin THEN PRINT SPC(3); bin; SPC(2); ELSE IF bin=1000 THEN PRINT SPC(2); bin; SPC(2); GOSUB CONVERT FOR k=0 TO 12 PRINT USING "#"; E(12-k); NEXT k IF, gray THEN PRINT SPC(7); gray; ELSE IF gray=10 AND grayd THEN PRINT SPC(6); gray; ELSE IF gray=100 AND gray THEN PRINT SPC(5); gray; ELSE IF gray=1000 THEN PRINT SPC(4); gray; IF gray THEN PRINT SPC(3); HEX$(gray) ELSE PRINT SPC(2); HEX$(gray) NEXT bin END CONVERT: FOR g=0 TO 12 c=d-h IF c=0 THEN E(g)=0 ELSE E(g)=1 IF d/2 THEN E(g)=0 d=h/2 h=INF(d) NEXT g RETURNThe programs outer loop presents the 8192 numbers which are to be converted by the Inner loops. In order to obtain the jth and j+1 position binary digit, the function INT(bin/2) is used. This allows shifting one bit to the left by dividing by 2 mid using only the integer part of the number. The Gray number results from the exclusive OR of the terms a and b. The subroutine CONVERT stores the Gray bits in a linear array 13 bits wide. The subroutine loop then converts the Gray decimal number to a 13 bit representation. 'resting is also performed in the subroutine to indicate whether the stored bits are either 0 or 1. The bits stored in the array are printed out in the correct order from MSB to LSB by the main program print loop. Many applications require an offset Gray encoding scheme for the optical encoder. That is, if the resolution per 360° is not equal to an integer multiple of a binary number (128, 256, etc), the encoding scheme must use an offset in order to eliminate any ambiguity while preserving the unit-distance code requirements. As the rotation passes through the 360° turn there must be only one bit change in the Gray code. Thus, if 400 counts per revolution is required, the offset is equal to 56(2N - counts/turn)/2. N is the integer defining the closest binary number to the specified count. Using the QBASIC program the offset can be incorporated in the main decimal loop. The loop will be based on (bin-56) rather then bin. When the input number is 0, the Gray code would be equivalent to its value at binary 56.