|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SYNCHRONOUS: 4-BIT COUNTER MODULO-16 D FLIPFLOP
|
Present State | NEXT STATE | |
---|---|---|
E = 0 | E = 1 | |
0000 | 0000 | 0001 |
0001 | 0001 | 0010 |
0010 | 0010 | 0011 |
0011 | 0011 | 0100 |
0100 | 0100 | 0101 |
0101 | 0101 | 0110 |
0110 | 0110 | 0111 |
0111 | 0111 | 1000 |
1000 | 1000 | 1001 |
1001 | 1001 | 1010 |
1010 | 1010 | 1011 |
1011 | 1011 | 1100 |
1100 | 1100 | 1101 |
1101 | 1101 | 1110 |
1110 | 1110 | 1111 |
1111 | 1111 | 0000 |
Table 1
Just as we would in a truth table, we must label the bits of the state transition table so as to be able to derive Boolean expressions from the table. So we recreate the table as Table 2, with the bits labeled. We use lower cases for the present states and upper cases for the next states.
Present State | NEXT STATE | |
---|---|---|
E = 0 | E = 1 | |
wxyz | WXYZ | WXYZ |
0000 | 0000 | 0001 |
0001 | 0001 | 0010 |
0010 | 0010 | 0011 |
0011 | 0011 | 0100 |
0100 | 0100 | 0101 |
0101 | 0101 | 0110 |
0110 | 0110 | 0111 |
0111 | 0111 | 1000 |
1000 | 1000 | 1001 |
1001 | 1001 | 1010 |
1010 | 1010 | 1011 |
1011 | 1011 | 1100 |
1100 | 1100 | 1101 |
1101 | 1101 | 1110 |
1110 | 1110 | 1111 |
1111 | 1111 | 0000 |
Table 2
Once we have determined the state transition table of a design problem, the natural next step is to derive the switching expressions for the circuit. Before we do, however, we typically use a shortcut: decide on which type of flipflops to use. The explanation for why this shortcut is useful follows.
First and foremost, you must realize that a counter is a sequential logic circuit; which means the output of the circuit depends not just on the input but also on the past behavior of the circuit. For example, if the present state of our four-bit counter is 1010, then we know that the previous state must have been 1001 and that the next state will be 1011; in fact, from Figure 1 or the interactive circuit above, you should see that if all you know of a counter is the value of the input signals Clk and E, then you have no idea what the next state is going to be.
Now that we have established a counter as a sequencer, the next time-saving observation is to realize that all sequential circuits inevitably comprise flipflops and latches; otherwise sequencers could not store information. And since the set of flipflops and latches is very small (i.e. RS, D, JK, T), we could as well pick which flipflops we wish to use from the outset and design around that type of flipflop. Of course, the choice of flipflop is not so arbitrary when you recall that T flipflops are built with JK flipflops, which are built with D flipflops, which are built with RS flipflops, which in turn are the most basic useful storage elements (this list of relations is not exhaustive, but it is representative). In general, we tend to design with D flipflops. For instance, VHDL, Verilog, and all other major integrated circuit design software use D flipflops to build sequencers. There are many reasons D flipflops are preferred; one is because they simply clock the input signal without changing it (i.e. for all D flipflops, Q = D as time passes). So for example, if Y is the input to and y is the output of a D flipflop, then y will be equal to Y as time passes. You will develop a greater appreciation for this fact as we formulate the Boolean expressions for our four-bit counter.
Having chosen to use D-flipflops to synthesize our four-bit counter, all we really have left to do is find the flipflop input equations. The input equations are actually the equations for the next states W, X, Y, and Z. We refer to them as input equations because W, X, Y, and Z are the inputs to the D flipflops (see Figure 1). These input equations are combinational circuits and so are easy to formulate: each next state variable is a function of E, w, x, y, and z.
For output W:
E = 0 | E = 1 | |
![]() |
![]() |
Table 2: Karnaugh Map for W
W = wE + (wy + wx + wz + wxyz)EFor output X:
E = 0 | E = 1 | |
![]() |
![]() |
Table 3: Karnaugh Map for X
X = xE + (xy + xz + xyz)EFor output Y:
E = 0 | E = 1 | |
![]() |
![]() |
Table 4: Karnaugh Map for Y
Y = yE + (yz + yz)EFor output Z:
E = 0 | E = 1 | |
![]() |
![]() |
Table 5: Karnaugh Map for Z
Z = zE + zE
Rewriting the four input equations together, we get:
W | = | wE + (wy + wx + wz + wxyz)E | |||
X | = | xE + (xy + xz + xyz)E | |||
Y | = | yE + (yz + yz)E | |||
Z | = | zE + zE |
At first glance there seems to be no pattern but madness in these equations. After rearranging the equations, however, you should see how you can easily extend the techniques you learn here to create counters of any size whatsoever. So let's rearrange the expressions, starting with the least significant bit.
For Z:
Z | = zE + zE | |||||
= z ![]() |
Y | = yE + (yz + yz)E | |||||
= yE + yzE + yzE | After expanding the E | |||||
= y(E + zE) + yzE | After factoring out the y | |||||
= y(E + z) + yzE | After applying DeMorgans | A + AB = A + B | ||||
= y (zE) + y(zE) | After applying DeMorgans | A + B = (A + B) | ||||
= y ![]() |
After rewriting in XOR form. |
X | = xE + (xy + xz + xyz)E | |||||
= xE + xyE + xzE + xyzE | After expanding the E | |||||
= x(E + yE + zE) + xyzE | After factoring out the x | |||||
= x(E + y + zE) + xyzE | After applying DeMorgans to | E + yE = E + y | ||||
= x(E + y + z) + xyzE | After applying DeMorgans to | E + zE = E + z | ||||
= x(yzE) + xyzE | After applying DeMorgans to | E + y + z = (yzE) | ||||
= x ![]() |
After rewriting in XOR form. |
W | = wE + (wy + wx + wz + wxy)E | |||||
= wE + wyE + wxE + wzE + wxyE | After expanding the E | |||||
= w(E + yE + xE + zE) + wxyzE | After factoring out the w | |||||
= w(E + y + xE + zE) + wxyzE | After applying DeMorgans to | E + yE = E + y | ||||
= w(E + y + x + zE) + wxyzE | After applying DeMorgans to | E + xE = E + x | ||||
= w(E + y + x + z) + wxyzE | After applying DeMorgans to | E + zE = E + z | ||||
= w(zyxE) + wxyzE | After applying DeMorgans to | E + y + x + z = (zyxE) | ||||
= w ![]() |
After rewriting in XOR form. |
So the equations from least significant bit to most significant bit are:
Z | = | z ![]() |
||
Y | = | y ![]() |
||
X | = | x ![]() |
||
W | = | w ![]() |
D0 | = | Q0 ![]() |
||
D1 | = | Q1 ![]() |
||
D2 | = | Q2 ![]() |
||
D3 | = | Q3 ![]() |
||
… | ||||
Dn | = | Qn ![]() |
At the beginning we said that a counter will run through a predetermined sequence of numbers continuously as long as time exists. What this means in practice is that the essential input to a counter circuit is a clock signal. In other words, a clock signal (Clk) must serve as the driving impetus moving the circuit from state to state. This clock signal is incorporated into the circuit through the clock input of the flipflop: all the flipflops are directly wired to the clock input switch Clk; the clock signal also serves to synchronize the flipflops.
From here on we will assemble the circuit, starting with the least significant bit. We show you the steps so you may follow the practice of testing your work as you build so as to catch errors early in the synthesis process.
Here is the circuit for the least significant bit Z. Notice that this circuit is also a one-bit counter that counts from 0 to 1 (2¹-1) and back again to 0, 1, etc.
I am going to trust you to allow me to show you one final trick. Circuit 5 uses D-latches instead of D-flipflops. Therefore, it is not really the same as the main interactive circuit at the top of the page. Can you guess the difference? For one thing Circuit 5 is cheaper to build, because latches are cheaper than flipflops. But thats not the main concern. The problem with Circuit 5 is that if the Enable switch flickers OFF and ON while the clock signal is risen (i.e. ON), the counting values will change. Thats not supposed to happen. Therefore, unless you can guarantee that the Enable signal will not change while the clock signal is HIGH, use flipflops instead of latches.