The following procedure completes the finite state machine implementation, given a particular choice of flip-flops:
- Given the state assignments, derive the next-state maps from the state
- Remap the next-state maps given the excitation tables for the flip-flops
chosen to implement the state bits.
- Minimize the remapped next-state function.
9.4.1 Flip-Flop Choice for the Four-Bit Sequence DetectorLet's illustrate the procedure with the 4-bit sequence detector, using the state assignment of Figure 9.39, the encoded state transition table.
D Implementation To obtain the direct form for determining the state machine implementation with D flip-flops, represent the encoded next-state functions as K-maps. Figure 9.41 contains the four-variable K-maps for the next-state functions Q2
+, given the current state Q2, Q1, Q0 and the input I. The reduced equations that describe the inputs to the D flip-flops are
9.5 Finite State Machine PartitioningIn the preceding sections, we described the design process for a single monolithic finite state machine. The approach is reasonable for many strategies for implementing a finite state machine, such as using discrete gates.
However, when using some forms of programmable logic, we may need to partition the machine. In some cases we cannot implement a complex finite state machine with a single programmable logic component. The machine might require too many inputs or outputs, or the number of terms to describe the next-state or output functions might be too large, even after state reduction and Boolean minimization.
FSM PartitioningTo illustrate the value of state machine partitioning, suppose we have a finite state machine with 20 inputs and 10 outputs
(including next-state outputs
). But we only have programmable logic components with 15 inputs and 5 outputs. We cannot implement this finite state machine with a single component.
Suppose we can arrange the outputs in two sets of five, each of which can be computed from different 15-element subsets of the original 20 inputs. Then we could partition the output functions among two programmable logic components, as shown in Figure 9.44.
If we cannot reduce the complexity of the finite state machine by simple input/output partitioning, another way to "make it fit" is to partition the single finite state machine into smaller, less complex, communicating finite state machines. We examine this approach in the next subsection.
9.5.1 Finite State Machine Partitioning by Introducing Idle StatesPartitioning the finite state machine makes sense if the next-state logic is too complex to implement with the programmable logic components at hand. The problem is that PALs provide a fixed number of product terms per output function. We can make a trade-off between the number of flip-flops needed to encode the state and the complexity of these next-state functions. Our idea is to introduce additional "idle" states into the finite state machine in the hope of reducing the number of terms in the next-state functions.
FSM PartitioningFor example, Figure 9.45 shows a subset of a state diagram.
What happens if we partition the state diagram, but a transition must take place between the two pieces? We need to introduce idle states to synchronize the activity between the two finite state machines. In essence, the machine at the left hands control off to the machine at the right when a transition from S1 to S6 takes place. The left machine must idle in some new state until it regains control, such as when there is a transition from S6 back to S1. In this event, the machine on the right must remain idle until it regains control.
The revised state diagrams are shown in Figure 9.46.
Suppose that the right-hand machine sequences through some states, eventually returning to S6. Throughout this time, the left-hand machine remains in its idle state. If the right-hand machine is in S6 and C2 is true, it next enters its idle state, SB. At the same instant, the left-hand machine exits SA, returning to S1. While the left-hand machine sequences through states, the right-hand machine idles in SB.
Rules for Partitioning We are ready to describe the rules for introducing idle states into a partitioned finite state machine. We illustrate each rule with an example from the partitioned state machine of the previous subsection. All the rules involve transitions that cross the partition -boundary.
The first rule applies for a state that is the source of a transition that crosses the boundary. The case is shown in Figure 9.47
The second rule applies to the destination of a transition that crosses the partition boundary. This is shown in Figure 9.47
). The transition is replaced with an exit transition from the idle state, labeled with the original condition ANDed with the source state. For example, the transition from S6 to S1 is replaced with a transition from SA. We exit the idle state when both C2 is true and the right-hand state machine is in S6. Hence, the transition is labeled with the condition C2 S6.
The third rule applies when multiple transitions share the same source or destination. This case is illustrated in Figure 9.47
). If a state is the source of multiple transitions across the partition boundary, all of these are collapsed into a single transition to the idle state. The exit conditions are ORed together to label the new transition. For example, S2 has transitions to states S5 and S4. These are replaced with a single transition to SA, labeled C3
If a state is the target of multiple transitions across the boundary, a single transition is added from the idle state to this state. The transition is labeled with the OR of the conditions associated with the individual transitions in the original state machine. This case is illustrated by the transitions from S2 and S3 to S5. These are replaced by a single transition from SB to S5, labeled C3 S2
When all these rules have been applied, the final rule describes the self-loop
)condition for the idle states. Simply form the OR of all of the exit conditions and invert it. This is shown in Figure 9.47
). Consider the idle state SA. Its only exit condition is C2 S6. So its hold condition is the inverse of this, namely .
FSM PartitioningConsider the six-state finite state machine of Figure 9.48
The machine implements a simple up/down counter. When the input U is asserted, the machine counts up. When D is asserted, it counts down. Otherwise the machine stays in its current state.
The goal is to partition the machine into two communicating four-state finite state machines. We might need to do this because the underlying logic primitives provide support for two flip-flops within the logic block, as in the Xilinx CLB to be introduced in the next chapter.
)shows the result of the partitioning. States S0, S1, and S2 form the core of one machine and S3, S4, and S6 form the other. We also introduce the two idle states, SA and SB.
The machine at the left enters its idle state SA when it is in S0 and D is asserted or when it is in S2 and U is asserted. It exits the idle state when the machine at the right is in S5 with U asserted or in S3 with D asserted. Otherwise it stays in its idle state. The machine at the right works similarly.
To see how the machines communicate, let's consider an up-count sequence from S0 to S5 and back to S0. On reset, the machine on the left enters S0 while the machine on the right enters SB. With U asserted, the left machine advances from S0 to S1 to S2 to SA. It will idle in this state until the right machine is ready to exit S5.
Meanwhile, the right machine holds in SB until the left machine enters S2. At the same time that the left machine changes to SA, the right one exits SB to S3. On subsequent clock transitions, it advances from S3 to S4 to S5 to SB, where it holds. When the right machine changes from S5 to SB, the left machine exits SA to S0, and the process repeats itself. Down-count sequences work in an analogous way.