FSM Design & Implementation: CT213 - Computing System Organization
FSM Design & Implementation: CT213 - Computing System Organization
FSM Design & Implementation: CT213 - Computing System Organization
FSM Design
This presentation deals with front to end design of finite state machines, both Mealy and Moore types. Design example is provided for a modulo 6 counter
It doesnt use value 6 (110) nor 7 (111) It has an input U that controls the counter:
When U=1 the counter increments its value on the rising edge of the clock When U=0 the counter retains its value on the rising edge of the clock
The value of the count is represented as three bit value (V2V1V0) There is an additional output C (Carry) that is 1 when going from 5 to 0 and 0 otherwise (the C output remains 1 until the counter goes from 0 to 1)
For each state examine what happens for all possible values of the inputs
In state S0 input U can be either 0 or 1 If U=0 the state machine remains in state S0 and outputs C=1 and V2V1V0=000 If U=1 the state machine goes in state S1, outputs C=1 and V2V1V0=001
In the same manner, each state goes to the next state if U=1 and remains in the same state if U=0
The outputs are represented adjacent to the state The inputs are represented on the arcs
FSM Implementation
Converting a problem to equivalent state table and state diagram is just the first step in the design process The next step is to design the system hardware that implements the state machine. This section deals with the process involved to design the digital logic to implement a finite state machine. First step is to assign a uniquely binary value to each of the state that the machine can be in. The state must be encoded in binary. Next we design the hardware to go from the current state to the correct next state. This logic converts the current state and the current input values to the next state values and stores that value. The final stage would be to generate the outputs of the state machine. This is done using combinatorial logic.
Each state must be assigned to a unique binary value; for a machine with n states we have [log2n] bits; For the modulo 6 counter example, we have six states. We will assign state value 000 to S0, 001 to S1, and so on, up to 101 to S5.
Any values can be assigned to the states, some values can be better than others (in terms of minimizing the logic to create the output and the next state values) This is actually an iterative process: first the designer creates a preliminary design to generate the outputs and the next states, then modifies the state values and repeats the process. There is a rule of thumb, that simplifies the process: whenever possible, the state should be assigned the same with the output values associated with that state. In this case, same logic can be used to generate the next state and the output
specific to every system and may consist of combinatorial logic gates, multiplexers, lookup ROMs and other logic components The logic block cant include any sequential components, since it must generate its value in one clock cycle The logic block contains two parts:
One that generates the outputs (f function, CLC1) One that generates the next state (g function, CLC2)
The outputs depend only on the present state and not on its inputs Its configuration is different than the Mealy machine
The system output depends only on the present state, so the implementation of the output logic is done separately The next state is obtained from the input and the present state (same as for the Mealy machine)
To begin with, we need to setup the truth table for the next state logic
The system inputs and the present states are the inputs of the truth table Next state bits are the outputs We have to construct a Karnaugh map for each output bit and obtain its equation After that we design the logic to match the equations
U=0
Initial truth table is broken into two tables:
One for U=0 One for U=1
U=1
Create Karnaugh maps from these tables to obtain the equations for N2, N1 and N0 when U=0 and when U=1
N2
00 0 1 00 0 0 00 1 1
01 0 0 01 1 0 01 0 0
11
10
P2
U = 0 we observe that the next state is the same with current state:
N2 = P2 N1 = P1 N0 = P0
0 1
P1P0
0 x
x 11
N1
10 1
P2
0 1
P1P0
x 11
U = 1:
N2 = P2P0+P1P0 N1 = P1P0 + P2P1P0 N0 = P0
N0
10
P2
0 1
U=1
Next state logic implementation using multiplexers and logic gates. Please note that using multiplexers simplifies the combinatorial logic circuitry
Moore
Mealy
00 0 0 X
01 0 0
11
10
P2P1
P0U
00 0 1 X 0
01 0 1
11 1 0 X 0
10
00 01 11 10
0 0
00 01 11 10
1 X 0
X 1
X 0
00 0 0 X 0
01 1 1
11
10
00 1 0 X 0
01 0 0
11
10
00 01 11 10
00 01 11 10
0 0
0 0
0 X 0
X 1
X 1
X 0
V1 = P0U + P0U
C = P2P1P0U + P2P0U
Moore machine:
The counter plays the role of the register in Mealy and Moore designs, as well as a portion of the next state logic The state value is input to a decoder; each output of the decoder represents one state The decoder outputs and system inputs are input to the logic bloc that generates the system outputs and the information needed to generate the next state value
Unused States
The FSM presented so far works well if it is in a known state There will be a problem if the machine enters an unused state, also called unknown state or undefined state This could be caused by a flaw in the design but most of the times, this is happening when the machine powers-up.
When present state is 110, the next state is 110 if U=0 or 111 if U=1 When present state is 111, the next state is 111 if U=0 or 000 if U=1
If a circuit that implements this diagram powers-up in state 110 or 111 will never reach a valid state
Create dummy states for all unused states Each dummy state would go to a known state on the next clock cycle (usually to a reset state) Two dummy states: 110 and 111 By convention, the values 1 on the arcs indicate that the transfer is unconditional that is always taken Note also the output values: C=0 and 111 indicates the user that the machine is in an invalid state (it is a design decision)
Use this table to construct Karnaugh maps which yield to the following values for next state and outputs: Next state:
N2 = P2P1P0 + P2P1U + P1P0U N1 = P2P1P0 + P2P1U + P2P1P0U N0 = P2P0U + P1P0U + P1P0U
Outputs:
C = P2P1P0 V2 = P1 V1 = P1 V0 = P0 + P2P1
References
Computer Systems Organization & Architecture, John D. Carpinelli, ISBN: 0201-61253-4