Design: a mod-8 Counter A mod-8 counter stores a integer value, and increments that value (say) on each clock tick, and wraps around to 0 if the previous stored value was 7. So, the stored value follows a cycle: 000 00 00 0 00 0 0
Design: State Machine 2 We need eight different states for our counter, one for each value from 0 to 7. We can describe the operation by drawing a state machine. The nodes represent states and the edges represent transitions and are labeled with the input (clock in this case) that causes the transition to occur. 000 00 00 0 0 0 00
Design: State Table 3 A state table summarizes the state machine and is useful in deriving equations later: Current State Input Next State ------------------------------------ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 000 00 00 0 0 0 00
Design: Deriving Equations We will derive an equation for each of the next state functions: Current State Input Next State C2 C C0 N2 N N0 ------------------------------------ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 N0= C2 C C0+ C2 C C0+ C2 C C0+ C2 C C0= C0 4 N= C2 C C0+ C2 C C0+ C2 C C0+ C2 C C0= C C0+ C C0 N 2= C2 C C0+ C2 C C0+ C2 C C0+ C2 C C0 = C2 C C0+ C2 C+ C2 C0
Design: Mapping to D Flip-flops 5 Since each state is represented by a 3-bit integer, we can represent the states by using a collection of three flip-flops (more-or-less a mini-register). We will implement the circuit using D flip-flops, which make for a simple translation from the state table because a D flip-flop simply accepts its input value. D Q ~Q ------------ 0 0 0 0 0 0 So, we just need to feed each of the flip-flops the value of the appropriate next-state function equation derived earlier
D Flip-flop 6 The D flip-flop takes one data input and updates its state Q, on a clock tick, according to the table: D Q ~Q ------------ 0 0 D CK Q ~Q In the following Logisim diagrams, the D flip-flops update state on the falling edge (when the clock goes from high to low).
JK Flip-flop 7 The JK flip-flop takes two data inputs and updates its state Q, on a clock tick, according to the table: J K Q ~Q ---------------------- 0 0 no change 0 0 0 0 opposite J K CK Q ~Q In the following Logisim diagrams, the JK flip-flops update state on the falling edge (when the clock goes from high to low).
Implementation 8 N 2= C2 C C0+ C2 C+ C2 C0 N= C C0+ C C0 N0= C0
Design: Mapping to JK Flip-flops We could also implement the circuit using JK flip-flops. 9 J K Q ~Q ---------------------- 0 0 no change 0 0 0 0 opposite This will require a little more effort, since the inputs to the JK flip-flops cannot merely be set to equal the next state functions.
Design: Deriving JK Inputs 0 We must examine each current/next state pair and determine how/if the relevant flip-flop needs to change state: Flip-flop Inputs Current State Next State J2 K2 J K J0 K0 ------------------------------------------------------ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 For this simple circuit, we either want the JK flip-flop to hold state (both inputs 0) or to toggle state (both inputs ).
Design: Deriving JK Input Equations We can derive equations in the usual manner from the previous table: J 0= K0= Flip-flop Inputs Current State J2 K2 J K J0 K0 C2 C C0 ---------------------------------------- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 J= K= C2 C C0+ C2 C C0+ C2 C C0+ C2 C C0 = C0 J 2= K 2= C2 C C0+ C2 C C0= C C0
Implementation 2 J= K= C0 J 2= K 2= C C0 J 0= K0=
A mod-6 Counter 3 We can use JK flip-flops to implement a 4-bit counter: Note that the J and K inputs are all set to the fixed value, so the flip-flops "toggle". As the clock signal runs, the circuit will cycle its outputs through the values 0000, 000, 000,..., and then repeat the pattern. So, it counts clock ticks, modulo 6.
mod-6 Counter: first tick 4 Suppose the counter is in the initial state shown below (output is 0000). When the clock cycles from high to low: - the right-most sees its (inverted) clock signal go from low to high, and so it toggles its state to - the next flip-flop sees its clock signal go from high to low, and so it doesn't toggle - and so, neither do the other flip-flops So, the output is 000:
mod-6 Counter: second tick 5 Suppose the counter is now in the state shown below (output is 000). When the clock cycles from high to low (2 nd cycle): - the right-most sees its (inverted) clock signal go from low to high, and so it toggles its state to 0 - the next flip-flop sees its clock signal go from low to high, and so it toggles its state to - the next flip-flop sees its clock signal go from high to low, so it doesn't toggle So the output is 000.
mod-6 Counter: third tick 6 Suppose the counter is now in the state shown below (output is 000). When the clock cycles from high to low (3rd cycle): - the right-most sees its (inverted) clock signal go from low to high, and so it toggles its state to - the next flip-flop sees its clock signal go from high to low, and so it doesn't toggle So the output is 00.
mod-6 Counter: fourth tick 7 Suppose the counter is now in the state shown below (output is 00). When the clock cycles from high to low (4th cycle): - the right-most sees its (inverted) clock signal go from low to high, and so it toggles its state to 0 - the next flip-flop sees its clock signal go from low to high, and so it toggles its state to 0 - the next flip-flop sees its clock signal go from low to high, and so it toggles its state to So the output is 000.