Professional Documents
Culture Documents
In chapter 7, we looked at a general procedure for implementing finite state machines (FSMs) and illustrated the FSM designs with three models (Moore, Mealy, synchronous Mealy). Now we are going to discuss how to optimize or minimize the design in this chapter.
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz
state encoding with more bits (e.g., one-hot) may have simpler equations
complexity directly related to complexity of state diagram
input/output encoding may or may not be under designer control How can we minimize or optimize the FSM? Again, there are three categories of variables: state, inputs and outputs. The first thing to think about is states. In general, minimizing the number of states leads to a simple design. How about encoding for state? Even with the same number of states, encoding can be different. At first sight, the minimum # of bits to represent states seems to be best. But we have to think over other options. Inputs and outputs may not be controlled, depending or situations.
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 2
Algorithm sketch
1. place all states in one set 2. initially partition set based on output behavior 3. successively partition resulting subsets based on next state transitions 4. repeat (3) until no further partitioning is required
states left in the same set are equivalent
The first goal is to find out some redundant or duplicate states in the first naive design. That is, we need to find out equivalent states. The sketchy algorithm is described here. The first criterion for grouping states is output. The rationale behind this partitioning is that, if the outputs of states are same, there is a possibility that we may be able to combine those states into a single state. Then the next trick is to check whether some states have the same next state. VIII - Working with Sequential
Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 3
S0
1/0
1/0
Suppose there is a binary input string; one bit is coming into the system at each clock tick. What this system should do is to make output asserted when the current three bits are either 010 or 110. The state diagram with a Mealy model is on the left; this is an initial nave and ad hoc design of states. Each of the three bits will have two choices, which yields 8 cases or scenarios. That state diagram consists of 7 states and is converted to a stateVIII transition table in a little bit different form. Note that this system reads the input in - Working with Sequential Logic of 3bits. No overlapping 4 Copyright 2004, Gaetano 11010 Borriello and Randy H. Katz generate 00100 the unit is allowed. input will
( S0 S1 S2 S3 S4 S5 S6 ) ( S0 S1 S2 S3 S5 ) ( S4 S6 )
( S0 S3 S5 ) ( S1 S2 ) ( S4 S6 ) ( S0 ) ( S3 S5 ) ( S1 S2 ) ( S4 S6 )
Now lets try partitioning. First, lets see the output. S4 and S6 have the same output for both values of X. and the other states will make the same outputs. Then what states lead to S4 and S6? The right previous states of S4 and S6 are S1 and S2. So they are grouped next. Then S3 and S5 will move to S0. So S3 and S5 are grouped last. Typically, the states in the same level of the state diagram may be merged.
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 5
Minimized FSM
State minimized sequence detector for 010 or 110
Input Sequence S0 X/0 S1 0/0 S3 X/0 0/1 1/0 S4 1/0 Reset 0+1 X0 X1 Next State Present State X=0 X=1 S0 S1' S3' S4' S1' S3' S0 S0 S1' S4' S0 S0 Output X=0 X=1 0 0 0 1 0 0 0 0
Now we have a minimized FSM (Mealy model). Actually, it utilizes the common part of the inputs to be detected. As the first bit can be any value, the system needs to detect X10.
inputs here
present state S0 S1 S2 S3 S4 S5
00 S0 S0 S1 S1 S0 S1
next state 01 10 11 S1 S2 S3 S3 S1 S4 S3 S2 S4 S0 S4 S5 S1 S2 S5 S4 S0 S5
output 1 0 1 0 1 0
Lets look at a more complicated case. Now there are two input bits incoming simultaneously. Even though there are less states in the initial design, the state transition appears to be very complicated. Output-based nave checking in the previous example may not be effective due to complex transitions. That means we need a systematic way.
VIII - Working with Sequential Logic
Minimized FSM
Implication chart method
cross out incompatible states based on outputs then cross out more cells if indexed chart entries are already crossed out
S1 S0-S1 S1-S3 S2-S2 S3-S4 S0-S1 S3-S0 S1-S4 S4-S5
S2
next state 00 01 10 11 S0' S1 S2 S3' S0' S3' S1 S3' S1 S3' S2 S0' S1 S0' S0' S3' minimized state table (S0==S4) (S3==S5)
output 1 0 1 0
S4
S5 S0
S0
S4
S3
S2
The implication chart method checks the equivalence of two states systematically. Black X marks indicates two states (row and column of a cell) are not compatible. Each cell lists VIII the- next for all input values (row cell first). If any pair is not compatible, that Workingstates with Sequential Logic 8 S3. Copyright 2004, Gaetano Borriello and Randy Katz cell should be crossed out (red X). Finally S4 and S0 are H. equivalent and so are S5 and
No polynomial time algorithm exists for determining best grouping of states into equivalent sets that will yield the smallest number of final states If states A and B are equivalent and so are B and C, normally A and C are also equivalent. However, with dont care terms, that transitivity may not hold true.
0 0 0 1 1 1
0 0 1 0 0 1 1
0 1 0 0 1 0 1
0 0 0 0 1 1
0 0 0 1 0 0
Minimizing the number of states may not achieve the simplest design due to complex logic equations. In this above state diagram, we use only 3 states. However, the combinational logic may not be so simple. In this example, we assume that input X starts with 0.
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 10
This looks a more nave state diagram at first glance. However, after constructing the state transition table, we can derive much simpler logic. Q1+ = Q0, Q0+ = X, Out = Q1Q0. This example is not a general case. In most cases, the minimum number of states is favored in sequential logic system design.
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 11
State assignment
Choose bit vectors to assign to each symbolic state
with n state bits for m states there are 2n! / (2n m)! [m <= 2n] 2n codes possible for 1st state, 2n1 for 2nd, 2n2 for 3rd, huge number even for small values of n and m
intractable for state machines of any size heuristics are necessary for practical solutions
Now we finish how to decide the number of states. From now on, we will talk about what binary values will be assigned to individual states. Suppose we have m states and use n bits to represent all the states. Then the number of total possible assignments is 2nPm. There are many many ways to assign the bit vectors to states. Depending on the state assignment, the complexity of combination logic can be different. Again there can be a variety of criteria to evaluate the combinational logic.
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 12
No guarantee of optimality another intractable problem Some of the popular strategies of state assignment are listed. We already talked about one-hot encoding in the last chapter. A rule of thumb is a principle with broad application that is not intended to be strictly accurate or reliable for every situation. We can easily learn or come up with a heuristic algorithm. In any case, the optimal assignment is an NP-hard problem.
13
One hot encoding is popular since it is likely to have a simple structure of combinational logic. Also, the number of terms per next state literal is the number of incident arcs, which fits into a PAL
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 14
Now we will explain some heuristic algorithms for state assignment. A heuristic is a technique designed to solve a problem that ignores whether the solution can be proven to be optimal or best, but which usually produces a good solution. In general, we want to VIII - Working with Sequential haveLogic on-set elements adjacent to one another. 15 Copyright 2004, Gaetano Borriello and Randy H. Katz
Typically, the reset state is assigned state 0. Overall, we want to cluster 1s in the vicinity for potential application of the uniting theorem in K-maps. The three guidelines in the previous slide have the same purpose. Somehow we have to order the grouping rules. E.g., in the previous slide, the top rule has the highest priority and the bottom one has the lowest priority.
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 16
Output-based encoding
Reuse outputs as state bits - use outputs to help distinguish states
why create new functions for state bits when output can serve as well fits in nicely with synchronous Mealy implementations H1H0
Inputs C TL 0 0 1 1 1 0 0 1 Present State TS 0 1 0 1 HG HG HG HY HY FG FG FG FY FY Next State HG HG HY HY FG FG FY FY FY HG Outputs ST H 0 00 0 00 1 00 0 01 1 01 0 10 1 10 1 10 0 10 1 10 F 10 10 10 10 10 00 00 00 01 01 F1F0
HG = ST H1 H0 F1 F0 + ST H1 H0 F1 F0 HY = ST H1 H0 F1 F0 + ST H1 H0 F1 F0 FG = ST H1 H0 F1 F0 + ST H1 H0 F1 F0 HY = ST H1 H0 F1 F0 + ST H1 H0 F1 F0
Output patterns are unique to states, we do not need ANY state bits implement 5 functions (one for each output) instead of 7 (outputs plus 2 state bits)
If there are many output patterns, maybe we can substitute outputs for states. Each state is replaced by each unique output or its combination. That is, the next state is absorbed VIII - Working with Sequential by the current outputs Logic 17 Copyright 2004, Gaetano Borriello and Randy H. Katz
Output-based encoding
Present state is now represented by present outputs
No one state-bit is assigned to a state (ex) HY = 00010 + 11001 (STH1H0F1F0 + STH1H0F1F0)
C TL TS
ST = CTLHG + TSHY+ CFG + TLFG + TSFY
HG HY FG HY
H1 = FG + FY H0 = HY F1 = HG + HY F0 = FY
After identifying the states by outputs, the current state will be replaced by the outputs. Then the outputs are again encoded by the inputs and the new current states
VIII - Working with Sequential Logic Copyright 2004, Gaetano Borriello and Randy H. Katz 18
One-hot encoding
easy for small state machines generates small equations with easy to estimate complexity common in FPGAs and other programmable logic
Output-based encoding
ad hoc - no tools most common approach taken by human designers yields very small circuits for most FSMs
In general, the minimum number of states is preferred. For the encoding for each state, there can be various strategies. Each has its pros and cons.
19
State assignment
many heuristics best-of-10-random just as good or better for most machines output encoding can be attractive (especially for PAL implementations)
20