Abstract:
A synchronous programmable binary counter has a parallel section and a serial section, with the length (in bits) of the serial section being the same as the modulus of the parallel section. The parallel section counts on system clocks and produces two outputs. A parallel terminal count output is produced each time the parallel section count reaches a programmed value. A frame output is generated every time the parallel section reaches its maximum count and starts counting again. The serial counter section decrements its programmed value by one each time it receives a frame signal from the parallel section. This subtraction is accomplished by a half-adder and associated borrow flip-flop. The borrow flip-flop is set by each arrival of the frame signal. Between frame signals, the decremented programmed value is circulated in a shift register as the serial subtraction process is performed. When the serial section completes its countdown, it detects the all zeros condition in its circulating shift register and sets a flip-flop indicating that it has reached its terminal count. The overall counter will complete its count and will generate a terminal count output when the parallel counter section reaches its next terminal count. The maximum count possible from this counter is S * 2 S+S, where S is the length of the serial section and the maximum count of the parallel section.

Description:
BACKGROUND OF THE INVENTION 
     This invention relates to the field of binary counters, and more particularly to the field of synchronous programmable two-stage hybrid counters having a parallel part and a serial part for maximum speed and efficiency. 
     Synchronous parallel counters are fast, but require an increasing amount of gating logic for each additional stage. This makes them too expensive and inefficient for use in very long counters. 
     Linear feedback shift registers (LFSR) are very fast and efficient, but complex to program, since the sequence of numbers in the count is pseudo-random and programming of an LFSR requires an initialization value which must be looked up in a table as long as the maximum count of the LFSR or calculated by an algorithm which is non-trivial. 
     Very long counters have therefore frequently been implemented as ripple counters. However, ripple counters cannot easily produce a terminal count indication sychronously with the signal being counted. 
     What is desired is a binary counter that can be made very long, that can count fast, that is easily programmable, and that is capable of producing a terminal count indication that is synchronous with the signal being counted. 
     SUMMARY OF THE INVENTION 
     The present invention provides a synchronous binary counter that can be made very long, that can operate at relatively high speeds, that is easily programmable, and that produces a terminal count indication that is synchronous with the signal being counted. This counter is a hybrid, having a parallel counter section and a serial counter section, with the parallel section output being used as input to the serial section. Both sections operate synchronously with a system clock. The length (in bits) of the serial section is the same as the modulus of the parallel section. 
     Both portions of the counter are supplied with programming values. Every time the count in the parallel section reaches its programmed data value, it generates a parallel terminal count signal output. And, every time the parallel section of the counter counts through its initial state, it generates a FRAME signal output. The serial counter section decrements (or increments) its programmed value by one each time it receives a FRAME signal from the parallel section. This subtraction (or addition) is accomplished by a half-adder and associated borrow (or carry) flip-flop. The borrow flip-flop is set by each arrival of a FRAME signal. Between FRAME signals, the currently stored value is circulated in a shift register as a serial subtraction process is performed. 
     When the serial section completes its countdown, it detects the all zeros condition in its circulating shift register and sets a flip-flop indicating that it has reached its terminal count. Then, when the parallel counter section reaches its next terminal count, the whole hybrid counter has completed its count and a terminal count signal appears at its output. The maximum count possible from this counter is S*2 S+S, where S is the length of the serial section and the maximum count of the parallel section. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIG. 1 is a block diagram of the synchronous programmable parallel/serial counter of the present invention. 
     FIG. 2 is a schematic diagram of one embodiment of the synchronous programmable parallel/serial counter of the present invention. 
    
    
     DETAILED DESCRIPTION 
     Referring to FIG. 1, a serial counter section 10 receives as one of its inputs a FRAME signal from the output of a parallel counter section 20. An AND gate 30 produces a terminal count signal TC when its inputs are both true at the same time. One of the inputs to this AND gate 30 is the serial terminal count STC output of the serial counter section 10. The other input to this AND gate 30 is the parallel terminal count PTC output of the parallel counter section 20. 
     An initializing signal LOAD is an input to both counter sections 10 and 20. The serial count data signals SDATA are another input to the serial counter section 10. The parallel count data signals PDATA are another input to the parallel counter section 20. The serial counter section 10 has one additional input, the force serial terminal count signal FSTC. A system clock (not shown) provides synchronization to all of the flip-flops within both counter sections 10 and 20. 
     The length of the serial counter section 10 is the same as the modulus of the parallel counter section 20. Thus, every time the parallel counter section 20 produces the signal FRAME indicating that it has just counted through its all zeros condition again, the serial counter section 10 will have circulated the contents of its internal shift register by one full cycle. 
     At initialization, the signal LOAD resets the parallel counter section 20 to a predetermined initial state that is independent of PDATA and loads the contents of the serial count data signals SDATA into the serial counter section 10. This signal LOAD is synchronous with the system clock (not shown). The serial counter section 10 contains a shift register, zero detection logic, and a half-adder connected to subtract a least significant bit from the contents of the shift register every time the value stored in the shift register circulates. Obviously, an alternative version of this circuit could be based on addition instead of subtraction, in which case the SLOAD value would have to be the complement of the value required for the subtracting version. 
     Because the length of the serial counter section 10 is equal to the modulus of the parallel counter section 20, the contents of the serial section will have the right amount of time to circulate around the circular shift register once for every FRAME pulse from the parallel counter section. The serial counter section 10 can be configured to count up or down from the value initially loaded by the LOAD signal on every FRAME pulse from the parallel section. Either way, it will eventually reach a zero count and produce the serial terminal count signal STC. 
     The parallel counter section 20 receives the parallel count data PDATA. PDATA specifies the state within the parallel counter&#39;s count sequence during which it asserts the parallel count signal PTC. The PTC signal occurs for one state during each pass of the parallel counter through its count sequence. The parallel counter also generates the FRAME signal during a state of the parallel count sequence that is independent of PDATA. FRAME will typically be generated during the first or last state of the parallel count sequence, but either way it will be synchronized with a known state of the serial section. This is because both sections are initialized to known relative states by the LOAD signal. 
     The circulation within the serial counter section is synchronized to the FRAME signal, counting down once for each time it occurs. Thus, when the parallel counter section has reached its full count a number of times equal to the initialization value of the serial section, that section produces its terminal count, STC. The active state of STC enables one side of the AND gate 30. The next time that the count of the parallel counter coincides with the value of the parallel count data PDATA, another parallel terminal count signal PTC occurs, and the output of the AND gate 30, the terminal count TC signal, goes active, indicating that the overall counter has reached its terminal count. 
     Referring now to FIG. 2, a simplified version of the invention is shown for clarity. A full-size, practical version of this counter has a 32-bit serial section and a 5-bit parallel section (2 5=32), for a maximum count capacity of 32*2 32+32, or approximately 137×10 9. However, for ease of discussion, the example shown in the schematic of FIG. 2 has been truncated to contain an 8-bit serial section and a 3-bit parallel section (2 3=8), giving it the limited total count capacity of 8*2 8+8, or 2056. Note that the number (eight) of flip-flops S0-S7 in the counter proper portion of the serial counter section 10 is equal to the modulus of the parallel counter section 20. This number will be referred to later as the value of &#34;S&#34;. 
     The parallel counter section 20 in FIG. 2 can be seen to comprise three flip-flops P0-P2. These three flip-flops P0-P2 are the counter proper. All of their outputs are connected to AND gate G15 which is one source of input to the OR gate FRAME. The FRAME signal is therefore produced by a full count of the parallel counter section. LOAD also produces a FRAME signal through that OR gate FRAME. The parallel counter section 20 also contains XOR gates G12-G14 and AND gate PTC, which cooperate to detect the parallel terminal count condition supplied by parallel data lines PD0-PD2. 
     Continuing to refer to FIG. 2, the serial counter section 10 can be seen to comprise eleven flip-flops S0-S7, BORROW, CATCH, and STC. The first eight of these flip-flops S0-S7 are the shift register. This shift register S0-S7 receives a value to be counted down from at initialization time and circulates decrementing intermediate data values as the count is decremented. Because this shift register is as long as the maximum count of the parallel counter section 20, the contents of this shift register circulate and are decremented once during each complete count of the parallel counter section 20. 
     As the contents of the shift register S0-S7 circulate, the contents of flip-flop S1 are monitored by gate G4. If any of the bits in the value being circulated are a &#34;1&#34;, the flip-flop CATCH is set, indicating that the present value in the shift register S0-S7 is non-zero. Each FRAME signal from the parallel counter section 20 resets this flip-flop CATCH if it is set. After the contents of the shift register has been decremented to all zeros, the flip-flop CATCH will not be set at the end of that circulation cycle and its low output will set the serial terminal count flip-flop STC through the MUX G5 when the next FRAME signal activates that path. 
     AND gate G1 and XOR gate G2 are a half-adder. They are connected to the BORROW flip-flop as a subtractor. When a FRAME signal is generated by the parallel counter section 20, the borrow flip-flop BORROW is set through OR gate G3. 
     If the flip-flip S0 contains a &#34;1&#34;, XOR gate G2 will pass a &#34;0&#34; to flip-flop S7 on the next clock. The &#34;1&#34; from S0 will be inverted and therefore will disable G1 causing the BORROW flip-flop to reset on that (same) clock. 
     If, on the other hand, the flip-flop S0 contains a zero, the BORROW flip-flop will remain set and a &#34;1&#34; will be passed on to flip-flop S7 by XOR gate G2. This outcome will be repeated each time another consecutive &#34;0&#34; appears in flip-flop S0. The first time a &#34;1&#34; appears in flip-flop S0, it will be replaced by a &#34;0&#34; in flip-flop S7 and the BORROW flip-flop will then be reset, completing the borrowing process. 
     The initializing signal LOAD is an input to both the parallel counter section 20 and the serial counter section 10. Within the parallel counter section 20, the LOAD signal is connected to the low-input AND gates on the inputs of each flip-flop P0-P2, so that on the next clock after LOAD goes high all of the flip-flops in the parallel section are reset to &#34;000&#34;. (On this same clock edge, LOAD goes low.) The LOAD signal also generates a FRAME signal through the OR gate FRAME. 
     Within the serial counter section 10, the initializing signal LOAD switches all of the input MUXes on the counter flip-flops S0-S7 to their data input positions, so that the data on SD0-SD7 is loaded into the flip-flops S0-S7. The LOAD signal also loads the SD0 data into the CATCH flip-flop, as part of the initialization process. 
     When the total number to be counted is less than or equal to the capacity of the parallel counter section, the force serial terminal count signal FSTC is used to bypass the serial counter section 10. For these short counts, the force serial terminal count signal FSTC places the serial counter section 10 Serial Terminal Count flip-flop STC in a set condition, thus enabling the AND gate TC and causing the terminal count signal TC to go true as soon as the parallel terminal count signal PTC next does so. The value to be counted to is then determined entirely by the data applied to the parallel terminal count recognition gates G12-G14 by the parallel data signals PD0-PD2, and all of the S0-S7 data is &#34;don&#39;t care&#34;. 
     In general, to program the overall counter, the number to be counted to is first decremented by one, then divided by &#34;S&#34;, which we have defined as the length in bits of the serial section and the maximum count of the parallel section. The whole number quotient minus one is the value to be applied to the serial data lines S0-SX. If the quotient is zero, FSTC is asserted and the serial data is &#34;don&#39;t care&#34;. The remainder is the value to be applied to the parallel data lines. 
     Let us trace the operation of the invention using an example. Assume that we want to count the decimal 34. We subtract 34, yielding 33, then divide 33 by 8, the &#34;S&#34; value of the circuit in FIG. 2. The quotient is four, with a remainder of one. Therefore, the serial load data is a &#34;three&#34;; that is four minus one. So, SD0=1 and SD1=1, and all of the other serial data=0. The parallel load data will be the remainder of &#34;one&#34;. Therefore, P0=1, P1=0, and P2=0. 
     With these values loaded, the overall counter will count up to a decimal value of &#34;34&#34;, or 4*8+2. The serial counter section will have to cycle around a total of four times; three times to subtract out the three that it was loaded with and one additional time to detect the all zeros condition and set the Serial Terminal Count flip-flop STC. Note that the parallel data PD0-PD2 doesn&#39;t actually get loaded into the parallel flip-flops P0-P2 the way that the serial data SD0-SD7 gets loaded into the serial flip-flops S0-S7. Instead, the LOAD signal puts the parallel counter section flip-flops P0-P2 in an all 0&#39;s state, and it counts up to match the applied data values. 
     The following example shows the counter of the present invention in action, counting to a decimal value of thirty-four per the example above. (The missing line after every eight lines of activity is only a visual aid for humans, indicating that both counters have each completed one cycle of activity. In reality, the counter runs continuously through these apparent pauses.) 
     
                                           TABLE 1__________________________________________________________________________COUNTING TO 34P0  P1 P2   PR PTC         S0           S1             S2               S3                 S4                   S5                     S6                       S7                         BOR                            CAT                               STC                                  TC__________________________________________________________________________1 0 0 0 0  0  1 1 0 0 0 0 0 0 1  1  0  02 1 0 0 0  1  1 0 0 0 0 0 0 0 0  1  0  03 0 1 0 0  0  0 0 0 0 0 0 0 1 0  1  0  04 1 1 0 0  0  0 0 0 0 0 0 1 0 0  1  0  05 0 0 1 0  0  0 0 0 0 0 1 0 0 0  1  0  06 1 0 1 0  0  0 0 0 0 1 0 0 0 0  1  0  07 0 1 1 0  0  0 0 0 1 0 0 0 0 0  1  0  08 1 1 1 1  0  0 0 1 0 0 0 0 0 0  1  0  09 0 0 0 0  0  0 1 0 0 0 0 0 0 1  0  0  010  1 0 0 0  1  1 0 0 0 0 0 0 1 1  1  0  011  0 1 0 0  0  0 0 0 0 0 0 1 0 0  1  0  012  1 1 0 0  0  0 0 0 0 0 1 0 0 0  1  0  013  0 0 1 0  0  0 0 0 0 1 0 0 0 0  1  0  014  1 0 1 0  0  0 0 0 1 0 0 0 0 0  1  0  015  0 1 1 0  0  0 0 1 0 0 0 0 0 0  1  0  016  1 1 1 1  0  0 1 0 0 0 0 0 0 0  1  0  017  0 0 0 0  0  1 0 0 0 0 0 0 0 1  1  0  018  1 0 0 0  1  0 0 0 0 0 0 0 0 0  1  0  019  0 1 0 0  0  0 0 0 0 0 0 0 0 0  1  0  020  1 1 0 0  0  0 0 0 0 0 0 0 0 0  1  0  021  0 0 1 0  0  0 0 0 0 0 0 0 0 0  1  0  022  1 0 1 0  0  0 0 0 0 0 0 0 0 0  1  0  023  0 1 1 0  0  0 0 0 0 0 0 0 0 0  1  0  024  1 1 1 1  0  0 0 0 0 0 0 0 0 0  1  0  025  0 0 0 0  0  0 0 0 0 0 0 0 0 1  0  0  026  1 0 0 0  1  0 0 0 0 0 0 0 1 1  0  0  027  0 1 0 0  0  0 0 0 0 0 0 1 1 1  0  0  028  1 1 0 0  0  0 0 0 0 0 1 1 1 1  0  0  029  0 0 1 0  0  0 0 0 0 1 1 1 1 1  0  0  030  1 0 1 0  0  0 0 0 1 1 1 1 1 1  0  0  031  0 1 1 0  0  0 0 1 1 1 1 1 1 1  0  0  032  1 1 1 1  0  0 1 1 1 1 1 1 1 1  0  0  033  0 0 0 0  0  1 1 1 1 1 1 1 1 1  1  1  034  1 0 0 0  1  1 1 1 1 1 1 1 0 0  1  1  1__________________________________________________________________________ 
    
     Line 1 of Table 1 shows the state of the counter following initialization for the example of counting to decimal &#34;34&#34;. The serial section has been loaded with the data value of &#34;00000011&#34;. The parallel section has been set to all zeros, &#34;000&#34;. The parallel data lines are waiting to recognize a &#34;001&#34;, on the next clock. The CATCH flip-flop has been set by the SD0 value of &#34;1&#34;. The BORROW flip-flip has been set by the FRAME signal generated by the LOAD signal through the OR gate FRAME. A high LOAD signal also disabled low-input AND gate G6, causing the serial terminal count flip-flop STC to be reset. 
     After another clock, at line 2 of Table 1, the &#34;1&#34; in the S1 flip-flop circulates to the S0 position and the &#34;1&#34; in S0, in combination with the feedback from the BORROW flip-flop, causes a &#34;0&#34; to be put in S7 through XOR gate G2. The &#34;1&#34; from the S0 flip-flop also disables low-input AND gate G1, causing the BORROW flip-flop to reset. On this same clock, the parallel section increments to &#34;001&#34;. That value in the parallel section produces a parallel terminal count PTC indication, but AND gate TC is disabled by a low from the serial count flip-flop STC. 
     From lines 3 to 7, the parallel section is counting and the serial section is shifting. At line 8, the full count of the parallel section produces a FRAME signal. At line 9, the FRAME signal from the previous line has now caused BORROW to set and CATCH to reset. The &#34;1&#34; which has been shifting has now reached its reference location in the serial counter and the counter can now be seen to have concluded its decrement to &#34;00000010&#34;. 
     At line 10, the CATCH flip-flop has been set again by the &#34;1&#34; in S1 on the preceeding clock, line 9. S7 is set by the absence of a &#34;1&#34; in S0 in combination with the presence of a &#34;1&#34; in the BORROW flip-flop, as determined by XOR gate G2. The low from S0 also enables AND gate G1 because that input to that gate is inverted, keeping the BORROW flip-flop set. The &#34;1&#34; in S1 moves to S0. 
     At line 11, the &#34;1&#34; in S0 during the last state now disables AND gate G1 and the BORROW flip-flop is reset. The &#34;1&#34; from S0 last time, in conjunction with the BORROW flip-flop having been set, causes a &#34;0&#34; to be put in S7. This completes this borrowing operation, and the one remaining &#34;1&#34; is now going to be in S0, the LSB, when the serial counter reaches its reference condition at line 17. 
     At line 17, the BORROW bit has just been set. But this time, the presence of a &#34;1&#34; in S1 keeps CATCH set. On the next clock the S0 bit and the BORROW bit will annihilate each other due to the operation of the half-subtractor gates, G1 and G2, and the only remaining activity in the rest of this cycle is the counting of the parallel section which produces a FRAME signal at line 16. 
     At line 25, the FRAME signal on the preceeding line has now caused BORROW to set and CATCH to reset again. During this cycle the absence of a &#34;1&#34; in S1 will prevent the CATCH bit from being set until line 33 at the beginning of the last (partial) cycle. During this cycle, the set BORROW bit and the absence of anything to borrow from causes S7 to be repeatedly set, filling up the serial counter with &#34;1&#34;s as the register shifts. 
     At line 33, the serial terminal count flip-flop STC sets due to the absence of a &#34;1&#34; in the CATCH flip-flop at the time of the FRAME signal. When FRAME is high, the MUX G5 passes the &#34;0&#34; from the CATCH flip-flop through to low-input AND gate G6 whose other side is enabled by the low on LOAD. With STC set, one side of the terminal count AND gate TC is enabled. On the next count, line 34, the parallel terminal count signal PTC goes true, generating the desired TC output. 
     Table 2 shows an example of the invention counting to 5, a number less than the maximum count of the parallel section, and thus one that requires the use of the Force Serial Terminal Count FSTC signal to set the STC flip-flop as part of the initialization process. With STC set, all of the other serial section circuitry is irrelevant to the critical activity, and this is indicated &#34;X&#34;s for &#34;don&#39;t care&#34;. The parallel data PDx lines are programmed with &#34;100&#34; to look for the fifth count: 
     
                                           TABLE 2__________________________________________________________________________COUNTING TO 5P0  P1 P2   PR PTC         S0           S1             S2               S3                 S4                   S5                     S6                       S7                         BOR                            CAT                               STC                                  TC__________________________________________________________________________1 0 0 0 0  0  X X X X X X X X X  X  1  02 1 0 0 0  0  X X X X X X X X X  X  1  03 0 1 0 0  0  X X X X X X X X X  X  1  04 1 1 0 0  0  X X X X X X X X X  X  1  05 0 0 1 0  1  X X X X X X X X X  X  1  1__________________________________________________________________________ 
    
     The counter of the present invention may be implemented in a variety of ways, only one of which has been described in detail. It will be apparent to those skilled in the art that many changes and modifications can be made without departing from the essence of the invention in its broader aspects. The following claims are therefore intended to cover all such changes and modifications as fall within the true scope and spirit of the invention.