Abstract:
A Gray code counter is provided having identical modular circuits with eachodular circuit providing a Gray code count sequence having a predetermined number of bits and an enable signal to enable a successive modular circuit of the Gray code counter. Each modular circuit of the Gray code counter enables a successive modular circuit only during certain predetermined counts of the Gray code count sequence. The number of modules required to implement the counter is determined by the number of binary bits per module and the total number of binary bits provided by the counter. The Gray code counter can operate either in an up mode count or a down mode count in accordance with the Gray code count sequence.

Description:
BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     This invention relates generally to binary counter circuits and, in particular, to a Gray code counter that employs a modular type of sequencing. 
     2. Description of the Prior Art 
     Binary counters are used in virtually every digital computer or programmable controller, as well as many other types of digital systems. Many binary counters count sequentially, up or down, in accordance with a normal binary sequence. However, counting in a normal binary sequence results in bit pattern changes having multiple bit transitions. Since the bits of a binary counter do not transition at exactly the same instant, a binary counter can generate undesirable transition errors e.g., &#34;glitches&#34;, at the output, for example, of decoding circuitry electrically coupled to the counter. 
     To overcome these problems, Gray code counters are often used. A Gray code is a binary code in which sequential numbers are represented by binary expressions, each of which differs from the preceding expression by one bit in one place only. Thus, Gray code counters have the advantage of providing a virtually glitch-free count sequence. Accordingly, when a low noise counter is required for a particular application, Gray code counters are typically used. For example, Gray code counters are used for applications such as the transmission of telemetry data. 
     However, Gray code counters have problems of their own. Unlike binary counters, whose individual bit transitions are dependent only upon the logical states of their immediately adjacent bits, a Gray code counter&#39;s individual bit transitions are dependent upon the logical state of all other bits within the counter. This has resulted in complex logic and circuit designs based upon complex logic equations representing the expressions or states of the counter required to define the counting sequence. Such complexity increases greatly as more bits are added, i.e., for longer count sequences. Furthermore, the complexity is exacerbated for Gray Counters designed to provide both up and down counting, i.e., incrementing and decrementing count sequences. 
     The complexity of Gray code counters has been caused by the interdependency of the individual counter bit transitions upon the logical states of all the other counter bits. Such interdependency has produced designs having interconnections for feedback and feedforward paths coupling to or across multiple counter stages. This causes the interconnections to differ from one stage to the next stage. 
     Many Gray code counter designs use clock signals for the individual counter stages which are not fully synchronous. These asynchronous counters use various means for gating the counter stages&#39; clock signals. Other Gray code counters have been designed to operate completely asynchronously with no clock signal being used by the counter. Instead, these Gray code counters operate as ripple counters. 
     A Gray code counter&#39;s interstage connections are further affected when the counter is designed to provide both incrementing and decrementing count sequences. In this case, several, if not most, counter stages must be interconnected. 
     The inter-bit dependence of Gray code counters has resulted in counter designs which tend to be unique to each particular application. These prior art Gray code counters must generally be redesigned whenever a bit or bits are to be added to or removed from the count sequence. Such redesign has been further necessitated when it is desired that the Gray code counter selectively increment or decrement during its count sequence. 
     Furthermore, the inter-bit dependence of Gray code counters has caused this uniqueness of design to extend all the way down to the individual counter stages. The interfaces among the counter stages, including the clock signals, vary from one counter stage to the next. As a result, prior art Gray code counter designs have been either non-modular or non-synchronous, or both. 
     Thus, it would be desirable to have a Gray code counter design which is modular so that bits may be simply added to or removed from the count sequence by merely adding or removing counter stage modules without affecting the respective interfaces among the remaining counter stages. It would be further desirable to have a synchronous, modular Gray code counter design which can be selectively programmed to count up or down, i.e., increment or decrement during its count sequence. 
     SUMMARY OF THE INVENTION 
     The present invention overcomes some of the disadvantages of the prior art, including those mentioned above in that it comprises a relatively simple Gray code counter design which has modular counter stages. This modular design allows additional bits or counter stages to be added to the Gray code counter or deleted from the Gray code counter. Such additions or deletions of modular counter stages have no effect upon the respective interfaces of the individual modular counter stages. 
     The present invention further provides a modular Gray code counter which is fully synchronous. A single clock signal is used to directly clock every stage of the counter. 
     The present invention still further provides a synchronous, modular Gray code counter which can be selectively programmed to increment or decrement. A single-bit count control signal is used to program the Gray code counter to count up or count down. The Gray code counter of the present invention also provides for single bit control signals which enable the Gray code counter, which clear the Gray code counter asynchronously and which clear the Gray code counter synchronously. 
     Thus, a Gray code counter in accordance with the present invention provides a synchronous, fully modular Gray code counter capable of selectively counting up or counting down and having interstage interfaces unaffected by the number of bits in the count sequence. 
     These and other objectives, features and advantages of the present invention will be readily understood upon consideration of the following detailed description of the invention and the accompanying drawings. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIGS. 1-5 illustrate a Gray code counter or portions thereof in accordance with the present invention. 
     FIG. 1 is a block circuit diagram of an eleven bit Gray code counter, illustrating the use of five modules or building blocks to implement a Gray code count sequence; 
     FIG. 2 is a block circuit diagram for each of the five modules of FIG. 1; 
     FIG. 3 is a detailed electrical schematic diagram illustrating the logic circuitry for generating the enable signal provided by each of the modules of the Gray code counter of FIG. 1; 
     FIG. 4 is a state machine diagram illustrating the sequencing of the Gray code count for each of the modules of FIG. 1; and 
     FIG. 5 illustrates a timing diagram of the operation of the eleven bit Gray code counter of FIG. 1. 
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
     Referring to FIG. 1, there is shown an eleven bit Gray code counter, designated generally by the reference numeral 9, which constitutes a preferred embodiment of the present invention. Gray code counter 9 includes five modules or building blocks 10, 16, 18, 20 and 22 with each block 10, 16, 18, 20 and 22 providing three output bits QA, QB and QC and an enable signal which is active at the logic one state. Each block 10, 16, 18, 20 and 22 also has five inputs, one input of which receives the enable signal either from a preceding sequential building block or from an external source, not shown, which may be for example a digital computer. It should be noted that block 10 of Gray code counter 9 which provides the two least significant count bits Q0 and Q1 of each count receives the enable signal of FIG. 5C from the external source. It should also be noted that the enable signals of FIGS. 5G, 5H, 5I, 5J and 5K are respectively provided to the enable (EN) input of the next sequential module of Gray code counter 9 by the preceding module of Gray code counter 9. For example, module 16 which provides the Q2, Q3 count bits supplies the enable signal (en23) of FIG. 5H to the enable input of the next sequential module 18 of counter 9 which is the module providing the Q4 and Q5 count bits of each Gray code count. 
     Each module 10, 16, 18, 20 and 22 of Gray code counter 9 also receives from the external source the remaining control signals required by Gray code counter 9 to increment or decrement a count, to clock Gray code counter 9 and to clear Gray code counter 9, either through an asynchronous mode or a synchronous mode. The control signals provided to each module 10, 16, 18, 20 and 22 of Gray code counter 9 from the external source include the clock signal (CLK) of FIG. 5E, the asynchronous clear signal (/ACLR) of FIG. 5D, the synchronous clear signal (/SCLR) of FIG. 5B. and the up/down count signal (UP/DN) of FIG. 5A. The asynchronous clear signal, FIG. 5D and the synchronous clear signal, FIG. 5B, are active at the logic zero state. When the up/down count signal of FIG. 5A is at the logic one state Gray code counter 9 operates in an up count mode. Similarly, when the up/down count signal of FIG. 5A is at the logic zero state Gray code counter 9 operates in a down count mode. 
     Referring to FIG. 2, there is shown a block circuit diagram for each of the modules 10, 16, 18, 20 and 22 of FIG. 1. Each of the modules 10, 16, 18, 20 and 22 is identical in structure and operation and thus the following discussion will be with respect to module 10 of Gray code counter 9, unless otherwise indicated. 
     Referring to FIG. 4, there is shown a state machine diagram for circuit 12 of FIG. 2. Each circuit 12 provides a three bit Gray code count having bits QA, QB and QC with the count being dependent on the logic signals provided to the /SCLR input, the EN input and the UP/DN input of circuit 12. For example, if the Gray code counting sequence to be provided at the QA, QB and QC outputs of any one of the circuits 12 of counter 9 is to be as follows: 
     
                       TABLE I______________________________________COUNTING SEQUENCE FOR CIRCUIT 12    QC          QB     QA______________________________________increment  0             0      0      0             0      1      0             1      1      0             1      0      1             1      0      1             1      1      1             0      1      1             0      0______________________________________ 
    
     the /SCLR input, the EN input and the UP/DN input of circuit are respectively 1,1,1 and the state machine of FIG. 4 transitions from state S1 through states S2, S3, S4, S5, S6, S7 and state S8 and then returns to state S1. 
     In a like manner, if the Gray code counting sequence to be provided at the QA, QB and QC outputs of any one of the circuits 12 of counter 9 is to be as follows: 
     
                       TABLE II______________________________________COUNTING SEQUENCE FOR CIRCUIT 12    QC          QB     QA______________________________________decrement  0             0      0      1             0      0      1             0      1      1             1      1      1             1      0      0             1      0      0             1      1      0             0      1______________________________________ the /SCLR input, the EN input and the UP/DN input of circuit 12 are respectively 1,1,0 and the state machine of FIG. 4 transitions from state S1 through states S8, S7, S6, S5, S4, S3 and state S2 and then returns to state S1. 
    
     Whenever the EN input to one of the modules 10, 16, 18, 20 or 22 of Gray code counter 9 transitions from the logic one state to the logic zero state, circuit 12, FIG. 2, is disabled and the state machine of FIG. 4 remains at the particular state the state machine was at when the logic one to logic zero transition occurred. 
     Whenever the /SCLR inputs to modules 10, 16, 18, 20 and 22 of Gray code counter 9 transition to the logic zero state and the clock signal of FIG. 5E then transitions from a logic zero to a logic one circuit 12, FIG. 2, is synchronously cleared and the state machine of FIG. 4 transitions from the particular state the state machine of FIG. 4 was at when the logic one to logic zero transition occurred to state S1. It should be noted that the synchronous clear signal illustrated in FIG. 5B is clock dependent, while the asynchronous clear signal illustrated in FIG. 5D is not dependent on the clock signal, that is a logic one to zero transition of the asynchronous clear signal of FIG. 5D clears circuits 12 of each module 10, 16, 18, 20 and 22 of Gray code counter 9. 
     Referring now to FIGS. 2 and 3 there is shown a circuit 14 which provides the logic one enable signal to each successive modules 10, 16, 18, 20 and 22 of Gray code counter 9. For the enable output of circuit 14 to transition to the logic one state, the enable input to circuit 14 must be at the logic one state. This, in turn, results in a logic one at the first input of AND gate 33. 
     Whenever modules 10, 16, 18, 20 and 22 of Gray code counter 9 are in an UP count mode of operation, that is the module 10 is providing at its QA, QB and QC outputs the count shown in Table I, a logic one is supplied to the UP --  DN input of circuit 14 resulting in a logic one being supplied to AND gates 19 and 25 and NOR gates 11 and 15. When the count is 0, 1, 0 a logic one is supplied to AND gate 25 which is already enabled allowing the logic one to pass through AND gate 25 to AND gate 27. Since both inputs to NOR gate 29 are at the logic zero state (QA and QC inputs of circuit 14 are logic zeros) the output of NOR gate 29 will be at the logic one state resulting in logic ones at both inputs of AND gate 27. This, in turn, results in a logic one at the output of AND gate 27 which then passes through OR gate 31 and AND gate 33 to the enable output of circuit 14. 
     As is best illustrated in the following Table, circuit 14 of each module 10, 16, 18, 20 and 22 of Gray code counter 9 will generate a logic one at its enable output under the following input conditions: 
     
                       TABLE III______________________________________Output of Circuit 14    X = Don&#39;t CareEnable Input    UP/DN    QC     QB    QA   Enable Output______________________________________1        1        0      1     0    11        1        1      0     0    11        0        1      1     0    11        0        0      0     0    10        X        X      X     X    0______________________________________ 
    
     For an N-bit Gray code counter the enable circuit of each module will generate a logic one signal at its enable output under the following conditions: 
     
                       TABLE IV______________________________________Output of Enable Circuit                   X = Don&#39;t CareEnableInput  UP/DN    Q.sub.N-1                   Q.sub.N-2                         Q.sub.N-3...0                                Enable Output______________________________________1      1        0       1     0 . . . 0                                11      1        1       0     0 . . . 0                                11      0        1       1     0 . . . 0                                11      0        0       0     0 . . . 0                                10      X        X       X     X . . . X                                0______________________________________ 
    
     Referring to FIG. 1 the following expressions may be utilized to determined the number of modules required for a particular Gray code count: 
     
         B.sub.T =N+X(N-1)                                          (1) 
    
     
         A=X+1                                                      (2) 
    
     where B T  is the total number of bits for the Gray code count, N is the bits provided by each module and A is the number of modules required for the Gray code counter. For the circuit of FIG. 1, N is three, B T  is eleven, that is Gray code counter 9 provides eleven output binary bits Q0-Q10 and A is five, that is Gray code counter 9 has five modules 10, 16, 18, 20 and 22. 
     Each output of the Gray code counter of FIG. 1, that is outputs QA, QB and QC of the state machines 12 of each of the modules 10, 16, 18, 20 and 22 of the Gray code counter 9 may be represented by the output of a D-type or JK Flip-Flop. The state machine 12 for each module of Gray code counter 9 is a Moore machine which is a state machine where an output is a function of only the present state and is independent of an external input. 
     The following expression defines the number of Flip-Flops required to implement an N-bit Gray code counter of the type illustrated in FIG. 1: 
     
         N.sub.f =B.sub.T +O.sub.MSB 
    
     where N f  is the Flip-Flops required to implement the Gray Code counter, B T  is the total number of bits for the Gray code count, O MSB  represents the most significant bit provided by each module of the counter which is not being used as an output of the Gray code counter. For the circuit of FIG. 1, O MSB  is four (bit QC of modules 10, 16, 18 and 20), B T  is eleven and N f  is fifteen. 
     It should be noted that implementing the modular Gray code counter of the present invention requires that the most significant module utilize all the output bits provided by the module as the most significant bits of the count signal provided by the Gray code counter. Thus, all the output bits QA, QB and QC of module 22 are used in the count signal provided Gray code counter 9, that is QC, QB and QA are respectively output bits Q10, Q9 and Q8 of the count signal. Only output bits QA and QB of modules 10, 16, 18 and 20 are used in the count signal provided by Gray code counter 9, that is output bits QA and QB are output bits Q0-Q7 of the count signal. 
     Referring to FIGS. 1 through 5, there is shown a timing diagram, FIGS. 5A-5K, illustrating the operation of the Gray code counter 9 of FIG. 1. When the UP/DN input of Gray code counter 9, FIG. 5A, is at the logic one state, Gray code counter 9 is in an up count mode of operation. Since only module 10 is enabled (only EN signal of FIG. 5C is a logic one), the first clock pulse of the clock signal of FIG. 5E causes the state machine of circuit 12 to transition from state S1 to state S2 which results in module 10 providing at its QC, QB and QA outputs respectively 0, 0, 1 (count 001 hexadecimal, FIG. 5F). The second clock pulse of the clock signal of FIG. 5E causes the state machine of circuit 12 to transition from state S2 to state S3 which results in module 10 providing at its QC, QB and QA outputs respectively 0, 1, 1 (count 003 hexadecimal, FIG. 5F). The third clock pulse of the clock signal of FIG. 5E causes the state machine of circuit 12 to transition from state S3 to state S4 which results in module 10 providing at its QC, QB and QA outputs respectively 0, 1, 0 (count 002 hexadecimal, FIG. 5F). 
     Since the leading edge of the third clock pulse of the clock signal of FIG. 5E results in module 10 providing at its QC, QB and QA outputs respectively 0, 1, 0, the en12 signal of FIG. 5G will transition to the logic one state enabling module 16 as is best illustrated in Table III. However, when the UP/DN input of Gray code counter 9 transitions to the logic zero state, FIG. 5A, Gray code counter 9 enters a down count mode of operation and the logic zero of FIG. 5A is provided to the enable input of circuit 14. This causes the en12 signal of FIG. 5G to transition to the logic zero state disabling module 16 (see Table III) prior to the forth clock pulse of the clock signal of FIG. 5E. 
     Since Gray code counter 9 is now in a down count mode of operation, the fourth clock pulse of the clock signal of FIG. 5E causes the state machine of circuit 12 to transition from state S4 to state S3 which results in module 10 providing at its QC, QB and QA outputs respectively 0, 1, 1 (count 003 hexadecimal, FIG. 5F). The fifth clock pulse of the clock signal of FIG. 5E causes the state machine of circuit 12 to transition from state S3 to state S2 which results in module 10 providing at its QC, QB and QA outputs respectively 0, 0, 1 (count 001 hexadecimal, FIG. 5F). 
     The sixth clock pulse of the clock signal of FIG. 5E causes the state machine of circuit 12 to transition from state S2 to state S1 which results in module 10 providing at its QC, QB and QA outputs respectively 0, 0, 0 (count 000 hexadecimal, FIG. 5F). The sixth clock pulse of the clock signal of FIG. 5E also causes circuit 14 of each of the modules 10, 16, 18, 20 and 22 of Gray code counter 9 to transition to the logic one state as best illustrated by the FIGS. 5G, 5H, 5I, 5J and 5K (see Table III). 
     Since modules 10, 16, 18, 20 and 22 of Gray code counter 9 are now enabled the seventh clock pulse of the clock signal of FIG. 5F will cause the state machine of circuit 12 of each of the modules 10, 16, 18, 20 and 22 of Gray code counter 9 to transition from state S1 to state S8. This results in a count at the QC, QB and QA outputs of modules 10, 16, 18, 20 and 22 respectively of 1, 0, 0.  Since only the QC output of module 22 is provided as an output of Gray code counter 9 the binary count at the Q10 through Q0 outputs of Gray code counter 9 is 10000000000 (hexadecimal 400, FIG. 5F). The leading edge of the seventh clock pulse of the clock signal of FIG. 5E also causes the en12, en23, en34, en45 and en56 signals of FIGS. 5G through 5K to transition to the logic zero state, thereby disabling modules 16, 18, 20 and 22 of Gray code counter 9. The eighth clock pulse of the clock signal of FIG. 5E will result in only the state machine of module 10 transitioning from state S8 to state S7 since modules 16, 18, 20 and 22 are disabled. This results in a count at the Q10 through Q0 outputs of Gray code counter 9 of 10000000001 (hexadecimal 401, FIG. 5F). 
     It should be noted that Gray code counter 9 is cleared only on the leading edge of the first clock pulse, designated as pulse 25 of FIG. 5E, which occurs after the logic one to zero transition of the /SCLR signal of FIG. 5B. Gray code counter 9 then remains in a cleared state until the logic zero to one transition of the /SCLR signal of FIG. 5B and the leading edge of the first clock pulse, designated as pulse 27 of FIG. 5E, which occurs after the zero to one transition of the /SCLR signal of FIG. 5B. The logic one to zero transition of /ACLR signal of FIG. 5D immediately clears Gray code counter 9 and the clearing of Gray code counter is not dependent upon the clock signal of FIG. 5E. 
     An erasable programmable logic device may, for example, be used to implement the embodiment of the present invention as illustrated in FIGS. 1-4. A preferred erasable programmable logic device for implementing the Gray code counter of the present invention is the Altera Corporation Model EPM5128J erasable programmable logic device. Appendix A is a program listing for the state machine of FIG. 4 which was generated using a computer software program entitled &#34;MAX+PLUS AHDL (Altera Hardware Description Language)&#34; and which is also produced by Altera Corporation of San Jose, Calif., the manufacturer of the erasable programmable logic device. 
     It should further be noted that, for example, the Gray code counter of the present invention may have modules which provide the Gray count set forth as follows: 
     
                       TABLE V______________________________________COUNTING SEQUENCE FOR FOUR BIT GRAYCODE COUNTER     Q4   Q3          Q2     Q1______________________________________increment   0      0           0    0       0      0           0    1       0      0           1    1       0      0           1    0       0      1           1    0       0      1           1    1       0      1           0    1       0      1           0    0       1      1           0    0       1      1           0    1       1      1           1    1       1      1           1    0       1      0           1    0       1      0           1    1       1      0           0    1       1      0           0    0______________________________________ 
    
     To implement the modules of a Gray code counter which would provide the Gray code count set forth in Table V would require a state machine having sixteen states S1 though S16 This state machine would provide each count of the four bit Gray code. An enable circuit of the type illustrated in FIG. 3 for each module of the Gray code counter would be required to provide a logic one enable signal during an up count whenever the count of the module is 0100 or 1000. The enable circuit for each module of the Gray code counter would also be required to provide a logic one enable signal during a down count whenever the count of the module is 0000 or 1100. The design of the state machine and the enable circuit of a four bit module for a Gray code counter is well within the purview of those skilled in the art in view of the teachings set forth above and thus will not be discussed in detail. 
     From the foregoing, it may readily be seen that the present invention comprises a new, unique and exceedingly useful Gray code counter. Obviously, many modifications and variations of the present invention are possible in light of the above teachings. It is, therefore to be understood that within the scope of the appended claims the invention may be practiced otherwise than as specifically described. 
     
         ______________________________________APPENDIX A______________________________________SUBDESIGN a4clk           : INPUT;.sub.-- aclr  : INPUT;qa,qb,qc      : OUTPUT;en            : INPUT;.sub.-- sclr  : INPUT;up.sub.-- dwn : INPUT;)VARIABLEcount :     MACHINE OF BITS                      (g2,g1,g0)       WITH STATES    (s1 = b&#34;000&#34;,                      .sup. s2 = b&#34;001&#34;,                      .sup. s3 = b&#34;011&#34;,                      .sup. s4 = b&#34;010&#34;,                      .sup. s5 = b&#34;110&#34;,                      .sup. s6 = b&#34;111&#34;,                      .sup. s7 = b&#34;101&#34;,                      .sup. s8 = b&#34;100&#34;);BEGINcount.clk = clk;count.reset = !.sub.-- aclr;qa = g0;qb = g1;qc = g2;CASE count ISWHEN s1 = &gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s1;    ELSIF up.sub.-- dwn == 0 THEN     count = s8;    ELSE     count = s2;    END IF;WHEN s2 =&gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s2;    ELSIF up.sub.-- dwn == 0 THEN     count = s1;    ELSE     count = s3;    END IF;WHEN s3 =&gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s3;    ELSIF up.sub.-- dwn == 0 THEN     count = s2;    ELSE     count = s4;    END IF;WHEN s4 =&gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s4;    ELSIF up.sub.-- dwn == 0 THEN     count = s3;    ELSE     count = s5;    END IF;WHEN s5 =&gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s5;    ELSIF up.sub.-- dwn == 0 THEN     count = s4;    ELSE     count = s6;    END IF;WHEN s6 =&gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s6;    ELSIF up.sub.-- dwn == 0 THEN     count = s5;    ELSE     count = s7;    END IF;WHEN s7 =&gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s7;    ELSIF up.sub.-- dwn == 0 THEN     count = s6;    ELSE     count = s8;    END IF;WHEN s8 =&gt;    IF .sub.-- sclr == 0 THEN     count = s1;    ELSIF en == 0 THEN     count = s8;    ELSIF up.sub.-- dwn == 0 THEN     count = s7;    ELSE     count = s1;    END IF;END CASE;END;______________________________________