Custom discs

Absolute Discs with Non-Power-of-Two Resolution: Cyclic Gray Codes for 360 and 1000 Positions

Absolute Discs with Non-Power-of-Two Resolution: Cyclic Gray Codes for 360 and 1000 Positions

For 360 or 1000 absolute positions with only one bit changing between last and first code, take the symmetric middle section of the reflected Gray code and remove (2ⁿ − M)/2 codes at each end. This article derives the symmetry, truncation and decoding formulas, explains why an odd number of positions is impossible, and gives track count, element width, decoding table and layout checks for 360 and 1000 positions.

Indexing tables, valve actuators and instruments with decimal displays often need 360 (1° per position) or 1000 absolute positions per revolution. The number of Gray code bits gives 2ⁿ codes per revolution, and neither 360 nor 1000 is a power of 2. The most direct approach is to take the first 360 codes of a 9-bit Gray code, but the first code G(0) = 000000000 and the last code G(359) = 111010100 differ in 5 bits; if the bits flip in a slightly different order when passing the seam, an intermediate code far from the true position can be read. This article gives a construction in which first and last code also differ in only one bit, the decoding formula, and the points to watch in the layout.

512 codes of the 9-bit reflected Gray code; 76 removed at each end, indices 76…435 kept; when the disc passes the 359 → 0 seam only the MSB b8 changes; red marks the bit changing at each step.
Figure 1 – 512 codes of the 9-bit reflected Gray code; 76 removed at each end, indices 76…435 kept; when the disc passes the 359 → 0 seam only the MSB b8 changes; red marks the bit changing at each step.

Symmetry of the reflected Gray code

The n-bit reflected Gray code is G(i) = i XOR (i » 1), i = 0…2ⁿ − 1. Replace i by its mirror i′ = 2ⁿ − 1 − i, i.e. the bitwise complement of the n bits of i:

i′ = i XOR (2ⁿ − 1), i′ » 1 = (i » 1) XOR (2^(n−1) − 1)

XORing the two expressions gives

G(2ⁿ − 1 − i) = G(i) XOR 2^(n−1)

That is, two codes symmetric about the midpoint differ only in the MSB. This is where the word “reflected” comes from: in the second half the lower n − 1 bits mirror the first half, and the MSB changes from 0 to 1.

Truncation condition and decoding

To obtain a cyclic code with M positions, keep the middle indices i = s … 2ⁿ − 1 − s, removing

s = (2ⁿ − M) / 2

codes at each end. The first code of the section G(s) and the last code G(2ⁿ − 1 − s) are exactly a mirror pair and differ only in the MSB, so the closure from last to first also changes only one bit; within the section, each step already changes only one bit. The number of bits is n = ⌈log₂M⌉; s must be an integer, so M must be even.

Decoding takes two steps: first convert Gray to binary, b(n−1) = g(n−1), b(k) = b(k+1) XOR g(k); then subtract the offset, p = B − s. If B < s or B > 2ⁿ − 1 − s, a removed code has been read and can be flagged directly as a read error. If the mechanical zero needs to be set elsewhere, add a constant modulo M.

Symmetric truncation is not the only possible cut. Searching the 9-bit code from every starting point, we find 4 contiguous sections of length 360 whose first and last codes differ in one bit, starting at 76, 204, 332 and 460; the last three cross the 511 → 0 seam, so decoding needs an extra modulo operation. The symmetric section has contiguous binary values and decodes with a single subtraction, which is the most convenient.

Why an odd number of positions is impossible

Regard the n-bit codes as vertices of an n-dimensional cube; “changing only one bit” is one step along an edge, and every step flips the parity of the number of 1s in the code word. After a full cycle back to the start, the parity must be restored, so the number of steps — that is, the number of positions M — must be even. This conclusion does not depend on the construction: no cyclic code that changes one bit per step can have an odd number of positions.

When an odd number of positions is needed (for example 125) there are two options: make a cyclic code with 2M positions and divide by 2 at the output — for 125 positions, a 250-section of an 8-bit code with s = 3; or allow two bits to change at once at the seam and secure the reading by synchronisation with the incremental track, which requires an additional analysis of the read tolerance at the seam.

Parameters for 360 and 1000 positions

Item360 positions1000 positions
Number of tracks n910
Offset s7612
Indices kept76…43512…1011
Angle per position1°0.36° (21.6′)
Example LSB radius15 mm18 mm
Element arc length 2πr/M261.8 μm113.1 μm
Finest bar width (2 elements)523.6 μm226.2 μm
First code / last code001101010 / 1011010100000001010 / 1000001010
Share of invalid codes152/512 = 29.7%24/1024 = 2.3%

Decoding table for 360 positions (excerpt):

Position pIndex iCode word b8…b0Binary BB − 76
076001101010760
177001101011771
179255010000000255179
180256110000000256180
359435101101010435359

The track patterns are shown in Figure 2. After truncation the number of transitions on each track drops accordingly: for 360 positions b0 has 180, b1 has 90, and b8 is still bright for half a revolution and dark for the other half.

Developed view of the 9 tracks of the truncated Gray code for 360 positions: left the full revolution, right an enlargement near the seam; only b8 changes at the seam, and the transparent segment of b4 crossing the seam is only 8 positions wide.
Figure 2 – Developed view of the 9 tracks of the truncated Gray code for 360 positions: left the full revolution, right an enlargement near the seam; only b8 changes at the seam, and the transparent segment of b4 crossing the seam is only 8 positions wide.

Two points to watch in the layout

Irregular bar widths at the seam. After truncation, the segment of each track that crosses the seam is made up of two pieces, one from the start and one from the end of the section, so its width is no longer the regular value for that track. For 360 positions the regular bar width of b4 is 32 positions, but the transparent segment crossing the seam is only 8 positions; b6 and b7 also have irregular segments of 232 and 104 positions. The finest line width is still set by the 2 elements of b0, so manufacturability is not affected, but layout verification and AOI rules cannot be written as “fixed bar width per track”; they must compare the code table position by position over the full revolution.

Limited error detection by invalid codes. Removed codes never appear in normal reading, so reading one can be flagged as an error. But for a single wrong bit, only about 9.9% of cases fall into an invalid code at 360 positions, and only about 1.4% at 1000 positions; a wrong MSB turns the code into its mirror code, which is always valid and can never be detected. If read-code diagnostics are needed, an additional check is still required.

Engineering takeaways

  • Truncation formula: n = ⌈log₂M⌉, s = (2ⁿ − M)/2, keep i = s…2ⁿ − 1 − s; for 360 positions s = 76, for 1000 positions s = 12.
  • Decoding needs only Gray-to-binary conversion followed by subtracting s; a binary value outside s…2ⁿ − 1 − s is flagged as a read error.
  • Do not simply take the first M codes: for 360 positions first and last differ in 5 bits, and a code far from the true position may be read at the seam.
  • There is no single-step cyclic code for an odd number of positions; make 2M positions and divide by 2, or synchronise with the incremental track at the seam.
  • Verify the layout position by position against the full-revolution code table, not by “fixed bar width per track”: for 360 positions, b4 has a segment only 8 positions wide at the seam.
  • Removed codes catch only about 10% or less of single-bit errors, and MSB errors are never detected; diagnostics need additional measures.

Summary

In the reflected Gray code, two codes symmetric about the midpoint differ only in the MSB; taking the symmetric middle section gives a cyclic Gray code for any even number of positions, and decoding needs just one extra subtraction. An odd number of positions cannot be realised as a single-step cyclic code because of parity. 360 and 1000 positions need 9 and 10 tracks respectively, and the irregular bar widths at the seam need special checking in the layout.


Translated from the ENC7 Chinese technical library (article 0303). Read the Chinese original. Need a disc built to your drawing? Request a quote or see our custom encoder discs.

© Langfang Jingzheng Optoelectronic Technology Co., Ltd. All rights reserved. This article was created with AI assistance.

Have a drawing? Get an engineer's review.

Send your outer diameter, bore, line count or bit count, substrate and readhead wavelength. Our engineers check manufacturability and reply with a quotation and sample lead time.

WhatsApp