Use three positive-edge-triggered D flip-flops, all driven by the same clock signal . Write the current binary representation as , with the least significant bit. The next state is the current value plus one when and minus one when , in each case modulo eight. A bit toggles under exclusive or with a one.
For upward counting, toggles when , while toggles when , the respective carry conditions. For downward counting the corresponding borrow conditions are and . Define the shared inverted direction and the two direction-match signals
Each is one exactly when : it equals for upward counting and for downward counting. Thus the Boolean functions for the three D inputs are
Implement this with two NOT gates for , four two-input exclusive or gates for , and one two-input AND gate. Connect to the D flip-flop whose output is ; feed the three outputs back into the indicated gates. All three flip-flops capture simultaneously, so each equation uses the old state.
Figure 1.
Synchronous three-bit up-down binary counter: common clock signal, explicit D inputs and feedback
. Details.
Current Next for Next for
000001111
001010000
010011001
011100010
100101011
101110100
110111101
111000110
Every three-bit state is valid. A reset may initialize the binary counter to zero if required; counting itself needs no extra state. The direction input must meet the setup time and hold time requirements at the active clock edge.