Decoded counter with error check and self-correction
CROSS-REFERENCE TO RELATED APPLICATION 
     This application claims priority from European application 93830264.3, filed Jun. 21, 1993, which is hereby incorporated by reference. 
     BACKGROUND AND SUMMARY OF THE INVENTION 
     The present invention relates to a decoded (ring) counter (e.g. based on a shift register) which is capable of self-correcting any invalid state that may accidentally be assumed by the counter. 
     The field of the application of shift registers (SR) is extremely wide and differentiated and includes also counters. In fact, if for example the output of the last edge-triggered, D, flip-flop (FF) of a shift register (SR) is connected to the input of the first flip-flop and if to a reset input of any one of the flip-flops is fed a logic &#34;1&#34;, a so-called, &#34;N-module&#34; counter is implemented, where N is the number of flip-flops that form the shift register. A shift-register-based ring counter of this type is schematically shown in FIG. 1. 
     It is also well known that the above is not a widely used solution for realizing a counter because of several drawbacks, including: 
     i) Silicon area requirements. An N-module binary counter is normally implemented with a number of flip-flops equal to the integer portion of log 2  (N)+1 (if N is a multiple of 2, a number given by log 2  (N) of flip-flops would be sufficient). By contrast an equivalent counter, made with a shift register, would require an N number of flip-flops. 
     ii) Power consumption. Because a ring counter requires a larger number of flip-flops, it will more heavily load the timing system (clock signal). 
     iii) Number of possible states. An N-module, binary counter has 2 k possible states (k is the minimum whole number such that 2 k be ≧N). Conversely, a ring counter has 2N possible states. In particular, if, because of a disturbance, a unique &#34;1&#34; is lost, or if a second &#34;1&#34; is introduced, the ring counter is no longer capable of &#34;cleaning&#34; itself and to return in a correct state. 
     Notwithstanding these intrinsic drawbacks and disadvantages, a ring counter may be, and is, advantageously used when extremely fast responses and symmetrical clock/output delays are required. In fact, if we have N signals that must cyclically become &#34;high&#34;, one at the time, a solution could be that of using a binary counter followed by a K→N decoder, as depicted in FIG. 2. However, an alternative solution could be that of using an N-module ring counter like the one depicted in FIG. 1. 
     The latter solution requires a larger number of flip-flops, but in this case, the silicon area that would be required is not much different from the area that would be required by the first solution, as long as N is not too large. In fact, according to the first solution besides K flip-flops, it is necessary to implement a decoder, whose architecture is generally not modularly structured as the circuit of the second solution is. Moreover, the K→N decoder that is required in the case of a binary counter, will introduce delays and will be hard to correctly size so that the outputs will switch-on and off with the same switching times (in other words, symmetry of outputs is difficult to procure). 
     There is also another problem (which in certain applications assumes a fundamental importance): this is the necessity of ensuring that the outputs do not undergo spurious transitions, i.e. that an output signal should be free of spikes following the switching of other outputs. 
     Unless an appropriate counting code (e.g. the well known Grey code) is used, it is not easy to ensure that a decoder will be totally exempt from this problem. On the other hand, the use of counting codes which are different from the normal binary representation of numbers complicates the remaining circuitry of the counter. 
     By contrast, by using a ring counter instead, one could not exclude the possibility that (even though this might be improbable) the ring counter could assume an illegal (invalid) state, as mentioned at point iii) above. 
     In other words, a ring counter such as the one depicted in FIG. 1 may incur one of the following problems: 
     A) because of an accidental disturbance, more than a single flip-flop of the shift register may store a logic &#34;1&#34;. In this case, the synchronous machine would evolve through a sequence of states that never includes a correct one (that is a single flip-flop storing a logic &#34;1&#34;), and therefore the machine would continue to count, but incorrectly; 
     B) because of an accidental disturbance, the only logic &#34;1&#34; that shifts through the flip-flop chain forming the shift register may be accidentally erased. In such a case, the synchronous machine would enter a stable state and, unless it is acted upon through a suitable reset signal, the counting process would stop. 
     In both cases, a ring counter may be thought of as becoming &#34;dirty&#34;, and being unable to return to a &#34;clear&#34; condition. 
     The present invention, in a disclosed embodiment, avoids the first problem by using a set/reset mechanism, rather than the data loopback of the prior art, to provide feedback from the end of the chain to the beginning. The data output of the last stage in the chain drives a set/reset line which is connected to a set input of the first stage, and to reset inputs of all other stages. Thus when a &#34;1&#34; propagates through to the last stage, any other propagating &#34;1&#34; bits are extinguished. The second problem is solved by a wired-OR arrangement which is driven by an additional output of each stage, to detect a stable all-zeros state. 
     Thus the present invention, in a disclosed embodiment, provides a decoded counter employing a shift register and a zero-detect circuit in order to return to a correct state within a limited number of clock cycles whenever an invalid state is accidentally assumed by the counter. One of the flip-flops is provided with synchronous set while all the other flip-flops of the shift register are provided with synchronous reset. The output of the last flip-flop of the register drives a single set-reset line common to all the flip-flops and the pull-up line of the zero-detect circuit is connected to the input of the first flip-flop of the register. Optionally, one of the flip-flops may be provided with asynchronous set and the others with an asynchronous reset, for initializing the counter in a certain state through a single clear-load line. 
     According to a disclosed class of innovative embodiments, there is provided: A decoded counter circuit, comprising: a plurality of flip-flops chained together, with each intermediate one of the flip-flops having a data input which is connected to a data output of an immediately preceding stage, and a set/reset line which is operatively connected to all of the flip-flops, in a configuration which drives the respective data outputs of the first flip-flop in the chain into a first state when the set/reset line is in an active state, and which drives the respective data outputs of all other the flip-flops in the chain into a second state when the set/reset line is in an active state; the last the flip-flop in the chain having the data output thereof connected to drive the set/reset line. 
     According to another disclosed class of innovative embodiments, there is provided: A decoded counter circuit, comprising: a plurality of data storage stages chained together, with each intermediate one of the stages having a clock input, a data input, and a data output which corresponds to the data input when the clock input receives a predetermined clock waveform portion, the data input thereof being connected to a data output of an immediately preceding stage, and a set/reset line which is operatively connected to all of the stages, in a configuration which drives the respective data outputs of the first stage in the chain into a first state when the set/reset line is in an active state, and which drives the respective data outputs of all other the stages in the chain into a second state when the set/reset line is in an active state; the last the stage in the chain having the data output thereof connected to drive the set/reset line. 
     According to another disclosed class of innovative embodiments, there is provided: A decoded counter circuit, comprising: a plurality of logic stages chained together, with each intermediate one of the stages having a data output which corresponds to a clocked version of a data input thereof, the data input being connected to the data output of an immediately preceding stage, and an additional output which is inactive whenever neither the data input nor the data output have the first state; and a set/reset line which is operatively connected to all of the stages, in a configuration which drives the respective data outputs of the first stage in the chain into a first state when the set/reset line is in an active state, and which drives the respective data outputs of all other the stages in the chain into a second state when the set/reset line is in an active state; the last stage in the chain having the data output thereof connected to drive the set/reset line; a wired-logic combining stage which is connected to receive the additional outputs of all of the stages, and which drives the set/reset line active if all of the additional outputs remain inactive. 
     According to another disclosed class of innovative embodiments, there is provided: A decoded counter circuit, comprising: a plurality of multiplexed-input-flip-flops chained together, with each intermediate one of the flip-flops having a first data input which is connected to a data output of an immediately preceding stage, and a second data input which is connected to a data output of an immediately succeeding stage, and a select input which selects between the first and second data inputs; an up/down line which is operatively connected to the select inputs of all of the flip-flops; a set/reset line which is operatively connected to all of the flip-flops, in a configuration which drives the respective data outputs of the first flip-flop in the chain into a first state when the set/reset line is in an active state, and which drives the respective data outputs of all other the flip-flops in the chain into a second state when the set/reset line is in an active state; the set/reset line being operatively connected to be driven by the data output of a first one of the flip-flops in the chain when the up/down line is in a first state, and by the data output of another one of the flip-flops in the chain when the up/down line is in a second state. 
     According to another disclosed class of innovative embodiments, there is provided: A decoded counter with self-correction capability, comprising: a shift register composed of an n flip-flops, one of which is provided with a synchronous set while all the others are provided with respective synchronous re-set inputs and wherein the output of the last flip-flop of the shift register drives a single set-reset line common to all the flip-flops; and a zero-detect circuit having a pull-up line functionally connected to an input of the first flip-flop of the register. 
    
    
     BRIEF DESCRIPTION OF THE DRAWING 
     The disclosed inventions will be described with reference to the accompanying drawings, which show important sample embodiments of the invention and which are incorporated in the specification hereof by reference, wherein: 
     FIG. 1 is a schematic illustration of the structure of a ring counter made with a shift register, as already described above; 
     FIG. 2 is a schematic illustration of an equivalent binary counter provided with a decoder, as already described above; 
     FIG. 3 shows the signals that may be obtained either with the ring counter of FIG. 1, or with the binary counter of FIG. 2; 
     FIG. 4 is a functional diagram of an N-module, self-correcting, decoded counter made with a shift register, according to the present invention; 
     FIG. 5 is the diagram of a static-type, zero-detect circuit usable in the counter of FIG. 4; 
     FIG. 6 is the diagram of a dynamic-type, zero-detect circuit usable in the counter of FIG. 4; 
     FIG. 7 shows a complete circuit diagram of a 23-module, Up-Down, self-correcting, decoded counter made according to the present invention; 
     FIG. 8 shows the equivalent functional diagram of a FF-shift block used for making the counter of FIG. 7; 
     FIG. 9 shows the result of a simulated operation of the counter of FIG. 7. 
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     The numerous innovative teachings of the present application will be described with particular reference to the presently preferred embodiment (by way of example, and not of limitation), in which: 
     In the functional diagram of an innovative ring counter of the invention, in the sample embodiment shown in FIG. 4, all but one of the flip-flops are edge-triggered, D-type, with synchronous reset; the remaining one, for example the first of the chain, is provided instead with a synchronous set. 
     All but one of the flip-flops may be provided also with an asynchronous reset (clear) input, with the exception of e.g. the first of the chain, which may be provided also with an asynchronous set (load) input. The output of a flip-flop is assumed to go high when the signal applied to a set input is high. 
     In practice, no asynchronous set-reset (clear-load) circuitry is needed unless the counter is required to start from a predefined state (as will be described later). For clearer illustration, the clock line is not shown in FIGS. 1, 2 and 4. It should be understood that the clock signal is the same for all the flip-flops. 
     It may be assumed that at the switching-on instant or at any other given instant, a circuit (not shown in the figures) will introduce a single logic &#34;1&#34; in the chain of flip-flops. Such a circuitry could be functionally represented by a generator of a &#34;clear&#34; signal, acting through an asynchronous &#34;set-reset&#34; line simultaneously on all the flip-flops, thus resetting all of them, with the exception of the single flip-flop, mentioned above, which would be set instead. Alternatively, such a circuitry could be functionally represented by a circuit that would generate a signal forcing the synchronous set-reset line at a high logic value, so that, in the first flip-flops of the chain, a &#34;1&#34; will be loaded, while a &#34;0&#34; will be loaded in all the other flip-flops of the chain. 
     It should be remarked again that, as will be seen later, such an initialization is not intrinsically necessary for the operation of the ring counter of the invention. 
     The operating principle of the ring counter of the invention may be summarized as follows. 
     In absence of disturbances, there is a single &#34;1&#34; that circulates through the counter structure. When it arrives at the output of the last flip-flops of the chain, which, instead of being connected to the D input of the first flip-flop of the chain as it would be in a ring counter of a conventional type, is connected instead to a common set-reset line, this imposes the reset of all the flip-flops with the exception of the first flip-flop of the chain, which instead is forced (through its synchronous set terminal) to assume the value &#34;1&#34;. Obviously, this takes place only at the subsequent active edge of the clock signal, because the set-reset inputs are synchronous. Moreover, the D input of the first flip-flop (the flip-flop provided with set) as will be shown later, is generally at a logic &#34;zero&#34;. Therefore, under normal conditions the whole system evolves as in a normal cyclic shift register (SR) in which the output of the last flip-flop of the chain fed back to the input of the first flip-flop (functionally in a manner equivalent to the one schematically shown in FIG. 1). 
     SOLUTION TO THE ABOVE-IDENTIFIED PROBLEM A. 
     If more than one flip-flop contains a &#34;1&#34;, then when the first of these &#34;1&#34; values reaches the last flip-flop of the chain it will automatically trigger the synchronous set-reset procedure mentioned above, and at that time all of the &#34;1&#34; values will be cancelled (except that the first flip-flop will be forced to &#34;1&#34; through its set input). 
     SOLUTION TO THE ABOVE-IDENTIFIED PROBLEM B. 
     If none of the flip-flops contain a &#34;1&#34;, then all the switches driven by the respective flip-flops (at their outputs P --  Dw) will be open, and therefore the pull-up line assumes a high logic level through its pull-up device. In this way, at a following active edge of the clock signal, the first flip-flop of the chain will load a &#34;1&#34; through its D input, and therefore a correct state of operation of the ring counter will be re-established. It should be observed that the ring counter of the present invention does not require any circuitry for initializing the counter (obviously if the starting condition is of no interest) because, in any event, after N-2 clock cycles at most, the counter assumes a correct operating state (i.e. at the Nth active edge of the clock signal, the ring counter will positively be in a correct state). 
     The zero-detect circuit schematically shown in FIG. 4 may be implemented in different ways. Two examples of alternative ways of realizing the zero-detect circuit are schematically shown in FIGS. 5 and 6. In FIG. 5, the functional diagram of a so-called static-type zero-detect circuit is shown. The operation of the circuit is evident and does not require any explanation. 
     The zero-detect circuit shown in FIG. 6 is of a so-called dynamic-type and employs a phase-control line (f), which allows a precharge of the pull-up line. This type of dynamic, zero-detect circuit may be used conveniently when the flip-flops that are employed for making the counter are of the Master-Slave type. During an interval of the clock period, the Master latch is in a storing state (i.e. is not in a &#34;read&#34; state), and therefore nothing will happen if its input changes state. During this interval of the cycle, the pull-up device (for example the p-MOS, driven by the phase signal f) precharges the pull-up line, which is momentarily decoupled from the switches functionally driven by the respective outputs Q i  of the flip-flops that compose the counter, by a second plurality of switches (in the example shown n-MOS transistors) that are controlled by the phase signal f. In the depicted example, this happens for f=0. 
     When the Master latch passes to a reading phase (f=1), if one of the outputs Qi of one of the flip-flops that compose the counter is at &#34;1&#34;, the respective transistor (switch) is ON (closed) and, through the relative n-MOS that in this phase is conducting, the pull-up line is discharged. In this way a logic &#34;0&#34; is fed to the input D of the first flip-flop of the chain. When a dynamic zero-detect circuit such as the one shown in FIG. 6 is used, particular care must be exercised when designing the circuit in order to avoid charge redistribution phenomena. 
     Of course, from the point of view of circuit design, the solution represented by a static-type zero-detect circuit is simpler, although slower in operation. In particular, the pull-up device (a p-MOS in the example shown) is preferably a transistor having a relatively long channel. 
     On the other hand, if the system is not required to recognize the absence of a &#34;1&#34; within a single clock cycle, the use of a static-type, zero-detect circuit will not significantly limit the clock frequency. 
     A 23 module, Up-Down, self-correcting, decoded counter of the invention is depicted in FIG. 7. (In this Figure the intermediate stages 3-10 and 13-19 have been omitted for clarity, but their configuration and connections are the same as the remaining stages 2-21.) The operation of the ring counter shown in FIG. 7 is similar to the one described for the ring counter of FIG. 4, with the difference that the ith flip-flop receives the data on its D input from the (ith-1) flip-flop, or from the (ith+1) flip-flop, depending upon the value present on the Up-Down select pin. As a consequence, the set-reset line is driven either by the 23rd flip-flop or by the second flip-flop of the chain, depending on the up-down polarity. 
     Two clock phases (fi and fi|) are directly applied to each flip-flop stage (FF-D or FF --  shift). The clock signal is generated by an appropriate driver (not depicted in the figure) that may be specifically designed for ensuring symmetry of the output transitions. 
     The synchronous set-reset signal is generated by an appropriate buffer (contained within the multiplexer structure shown in the figure to the left of stage FF-D). This signal is connected to a synchronous-set input of stage FF-D, and to a synchronous-reset input of all the stages FF --  shift. 
     The counter is capable of reversing the direction of counting through a command that may be applied through a dedicated pin Up-Down. Note that the corresponding line selects between the two data inputs to each of the FF --  shift stages, and also selects whether the set/reset line will be driven by the output of stage 22 or stage 1. Each FF --  shift stage has a DA input connected to the Q output of the preceding FF --  shift stage, and has a DR input connected to the Q output of the following FF --  shift stage; except that the first FF --  shift stage (stage 1) has its DA input connected to the Q output of the FF-D stage (stage 0), and the last FF --  shift stage has a DR input connected to the Q output of the FF-D stage (stage 0). Similarly, the added multiplexer selects which stage&#39;s Q output will drive the set/reset line. 
     Each stage is provided with an output buffer, to provide the required drive and pulse shape on the output lines. 
     The zero-detection circuit is connected to drive the data input D of the FF-D stage. 
     Moreover, the counter, in the presently preferred embodiment, is also provided with an asynchronous initialization pin (Clear|), which, when it goes low, resets in an asynchronous mode all the flip-flops with the exception of the first (stage 0) which, on the contrary, is forced (Load 1) to store a &#34;1&#34;. All the flip-flops are static, as is the zero-detect network. The relatively slow signal on the pull-up line is regenerated by the use of a Schmitt trigger. 
     FIG. 8 shows the equivalent block diagram of a single FF --  shift stage used in all but one of the stages of the counter of FIG. 7. Note that the data input DA or DR is selected by the selection line SA or SR respectively. 
     FIG. 9 is a table representing the result of a simulated operation of the 23 module, up-down, ring counter of FIG. 7. 
     It should be noted that a comparable ring counter of the prior art (FIG. 1a), without any self-correcting capability, would have occupied a silicon area practically identical to the area occupied by the ring counter of the invention. In practice, between a ring without any state control and a self-correcting ring counter of the present invention, there is a difference of only three &#34;minimum-size&#34; MOS transistors for each flip-flop. In general, the difference in the number of transistors will depend on the architecture of the flip-flops used. 
     The disclosed ring counter is particularly advantageous in applications where transition noise on unselected lines must be avoided. For example, this is particularly advantageous in an inkjet printer head driver, to avoid activation of more than one line at a time. This circuit can also be used advantageously in applications such as high-speed PLAs, high-speed multiplexing in video conversion, front ends to a fiber optic data link, or various comparable applications. 
     The innovative disclosed ideas are not limited to the specific disclosed embodiments, but can be implemented in a wide variety of other embodiments as well. For one example, the flip-flop stages could be replaced by other stage configurations. (For example, logic with complementary outputs could be used, or multi-bit stage configurations could be used instead, or an &#34;interleaved&#34; architecture could be used with a multi-phase clock.) 
     For another example, for the zero-detect circuit, it is not strictly necessary to have an output from every stage to the wired-NOR detector, IF the time constant of the wired-NOR detector stage is sufficiently long. 
     For another example, the innovative set+reset feedback (instead of the data loopback of the prior ring counter structures) could also (alternatively and less preferably) be used WITHOUT the zero-detection function. (In such embodiments the zero-detection function would be handled by other circuit implementations instead, e.g. by a &#34;watchdog&#34;-type circuit). 
     For another example, the use of asynchronous as well as synchronous set/reset inputs is also optional, as mentioned above. Moreover, in an alternative and less preferable class of embodiments, some of the advantages of the presently preferred embodiment can still be realized by feeding back the last stage&#39;s output to asynchronous rather than synchronous set/reset inputs. This would produce a phase shift every time recirculation of the counter occurred, but in some applications this might be tolerable. 
     For another example, the characteristics of the buffers which produce the buffered outputs Qbuf can be adjusted not only for the required loading, but also for the degree of overlap (or non-overlap) required.