CSE 27 Introduction to igital Systems Supplementary Reading Symbolic State inimization and An Example Symbolic State inimization In constructing state diagrams, it often occurs that the number of symbolic states that we use is not the minimum possible to perform the required function. When a designer has to design a more complex FS, it is likely that the initial attempt will result in a state diagram with more symbolic states than actually required. inimizing the number of states is of interest because fewer flip-flops may be needed to represent the symbolic states and the complexity of the combinational circuit needed in the FS may be reduced. If the number of symbolic states can be reduced, then some symbolic states in the original state diagram must be equivalent to other symbolic states in their contribution to the overall behavior of the FS. Let us express this more formally by introducing the following definition. efinition. Two symbolic states S i and S j are said to be equivalent if and only if for every possible input sequence, the same output sequence will be produced regardless of whether S i or S j is the initial state. It is possible to define a minimization procedure that searches for any symbolic states that are equivalent. However such a procedure is quite tedious. In the following, we will present an alternative approach, which is much more efficient but not quite as broad in scope. Instead of trying to show that some symbolic states in a given state diagram are equivalent, it is often easier to show that some symbolic states are definitely not equivalent. Let us exploit this idea to define a simple minimization procedure. Suppose that a FS has a single input W. Then if the input signal W = is applied to this machine in symbolic state S i and the result is that the machine moves to symbolic state S u, we will say that S u is a -successor of S i. Similarly, if W = is applied in S i and it causes the machine to move to symbolic state S v, we will say that S v is a -successor of S i. In general, we will refer to the successors of S i as k-successors. When the FS has only one input, k can be either or. But if there are multiple inputs to the FS, then k represents the set of all possible combinations (valuations) of the inputs. From the above definition, it follows that if the symbolic states S i and S j are equivalent, then their corresponding k-successors (for all k) are also equivalent. sing this fact, we can formulate a minimization procedure that involves considering the symbolic states of the machine as a set and then breaking the set into partitions that comprise subsets that are definitely not equivalent. efinition. A partition consists of one or more blocks, where each block comprises a subset of symbolic states that may be equivalent, but the symbolic states in a given block are definitely not equivalent to the symbolic states in other blocks. Let us assume initially that all symbolic states are equivalent; this forms the initial partition, P,in which all symbolic states are in the same block. As the next step, we will form the partition P 2 in which the set of symbolic states is partitioned into blocks such that the symbolic states in each block generate the same output values. Obviously, the symbolic states that generate different outputs cannot possibly be equivalent. Then we will continue to form new partitions by testing whether the k-successors of the symbolic states in each block are contained in one block. Those symbolic states whose k-successors are in different blocks cannot be in one block. Thus new blocks are formed in each new partition. The process ends when a new partition is the same as the previous partition. Then all symbolic states in any one block are equivalent. In the following, we will consider an example to illustrate the procedure.
A Vending achine esign Example As an example of minimization, let us consider the design of a simple vending machine. Suppose that a coin-operated vending machine dispenses candy under the following conditions: The machine accepts nickels and dimes. It takes 5 cents for a piece of candy to be released from the machine. If 2 cents is deposited, the machine will not return the change, but it will credit the buyer with 5 cents and wait for the buyer to make a second purchase. All electronic signals in the vending machine are synchronized to the positive edge of a clock signal, named Clock. Assume that the clock period is ns. The vending machine s coin-receptor mechanism generates two signals, sense and sense, which are asserted when a dime or a nickel is detected. Because the coin receptor is a mechanical device and thus very slow compared to an electronic circuit, inserting a coin causes sense or sense to be set to for a large number of clock cycles. We will assume that the coin receptor also generates two other signals, named and. The signal is set to for one clock cycle after sense becomes, and is set to for one clock cycle after sense becomes. The timing relationships between Clock, sense, sense,, and are illustrated in Figure. The hash marks on the waveforms indicate that sense or sense may be for many clock cycles. Also, there may be an arbitrarily long time between the insertion of two consecutive coins. ote that since the coin receptor can accept only one coin at a time, it is not possible to have both and set to at once. Figure 2 illustrates how the signal may be generated from the sense signal. Clock sense sense Time Figure. A timing diagram for the inputs of the vending machine. sense Clock Figure 2. A circuit that generates. Based on the above descriptions of the functionality of the vending machine, we can choose the inputs and output of the FS as shown in the following table (the meaning of and for each input and output is also listed). 2
Inputs Output Z -adimeissensed -anickelissensed - sufficient money to release candy -adimeisnotsensed -anickelisnotsensed - insufficient money We can then develop an initial state diagram in a fairly straightforward manner, as indicated in Figure 3. The inputs to the FS are and, and the starting symbolic state is S. As long as = =,the machine remains in symbolic state S, which is indicated by the arc labeled. Inserting a dime leads to symbolic state S2, while inserting a nickel leads to symbolic state S3. In both cases the deposited amount is less than 5 cents, which is not sufficient to release the candy. This is indicated by the output, Z, being equal to, as in S2/ and S3/. The machine will remain in state S2 or S3 until another coin is deposited because = =. In state S2 a nickel will cause a transition to S4 andadimetos5. In both of these states, sufficient money is deposited to activate the output mechanism that releases the candy; hence the state nodes have the labels S4/ and S5/. In S4 the deposited amount is 5 cents, which means that on the next active clock edge the machine should return to the reset state S. The condition on the arc leaving S4 is guaranteed to be true because the machine remains in state S4 for only ns, which is far too short a time for a new coin to have been deposited. Reset (state/z) S/ S4/ S2/ S3/ S7/ S5/ S6/ S8/ S9/ Figure 3. A state diagram for the vending machine. The state S5 denotes that an amount of 2 cents has been deposited. The candy is released, and on the next clock edge the FS makes a transition to state S3, which represents a credit of 5 cents. A similar reasoning when the machine is in state S3 leads to states S6 through S9. This completes the state diagram for the desired FS. Remark. In Figure 3, the transition arc from S/ tos3/ is labeled by. Tobemoreaccurate,itshould be labeled by. However, since is impossible to occur, here we simply label the transition by (which indicates that a nickel has been detected) without causing any confusion. Such simplified labeling is often used in drawing state diagrams in digital design. nder the assumption that is impossible, when constructing the state table, we will still translate the transition labeled by as the information in the cell corresponding to = while leaving the cell corresponding to = asdon tcare. A state table for the state diagram in Figure 3 is given below. 3
Present ext State Output State = Z S S S3 S2 S2 S2 S4 S5 S3 S3 S6 S7 S4 S S5 S3 S6 S6 S8 S9 S7 S S8 S S9 S3 In the above table, note that the condition = = is denoted as don t care. ote also other don t cares in states S4, S5, S7, S8, and S9. They correspond to cases where there is no need to check the and signals because the machine changes to another state in an amount of time that is too short for a new coin to have been inserted. The state diagram in Figure 3 obviously contains more states than necessary. ow let us apply the minimization procedure to obtain the following partitions P = (S,S2,S3,S4,S5,S6,S7,S8,S9) P 2 = (S,S2,S3,S6)(S4,S5,S7,S8,S9) P 3 = (S)(S3)(S2,S6)(S4,S5,S7,S8,S9) P 4 = (S)(S3)(S2,S6)(S4,S7,S8)(S5,S9) P 5 = (S)(S3)(S2,S6)(S4,S7,S8)(S5,S9) The final partition has five blocks. Let S2 denote its equivalent to S6, let S4 denote the same with respect to S7 and S8, and let S5 represent S9. This leads to the minimized state diagram shown in Figure 4 below. Reset (state/z) S/ S3/ S2/ S5/ S4/ Figure 4. inimized state diagram for the vending machine. The state table for the state diagram in Figure 4 is given below. 4
Present ext State Output State = Z S S S3 S2 S2 S2 S4 S5 S3 S3 S2 S4 S4 S S5 S3 Looking at the optimized state diagram in Figure 4, it can be seen that for this example, it may have been quite feasible to derive the optimized state diagram directly, using the following reasoning. Suppose that the symbolic states correspond to the various amounts of money deposited. In particular, the symbolic states, S, S3, S2, S4, and S5 correspond to the amounts of, 5,, 5, and 2 cents, respectively. With this interpretation of the states, it is not difficult to derive the transition arcs that define the desired FS as in Figure 4. In practice, the designer can often produce initial designs that do not have a large amount of superfluous states. In the following, let us design an FS based on the optimized state diagram (or, equivalently, the minimized state table shown above). We will apply two methods to accomplish the design. ethod (sing inimum State Variables). In view of the state table, there are 5 symbolic states. Therefore the minimum number of state variables needed is 3. Let us adopt the following state assignment table. Symbolic State = 2 S S2 S3 S4 S5 Such state assignments consequently lead to the following state-assigned table. Present State ext State = 2 Output = 2 = Z Based on the above state-assigned table, we can use Espresso to obtain the following next-state and output expressions (it may be better to use a separate Espresso file for each expression) = = 2 2 = Z = 2 and then implement the vending machine by the circuit shown in Figure 5. 5
Z 2 2 Clock Reset Figure 5. A circuit for the vending machine with asynchronous active low Reset. ethod 2 (One-Hot Encoding). Another method for implementing the circuit is to use the one-hot encoding of the states, which is based the following state assignment table. Symbolic State = 5 4 3 2 S S2 S3 S4 S5 ote that here we choose 5 state variables as, 2, 3, 4,and 5 (instead of,, 2, 3, 4 )so that the subscript in each state variable name is the same as the numbering of the corresponding symbolic states. As discussed in class, in the one-hot encoding method, we can derive the next-state and output expressions simply by inspecting the state diagram in Figure 4 (hence it is not necessary to write out the state-assigned table and resort to K-maps or Espresso to derive the expressions). The next-state and output expressions can be obtained as = 4 2 = 2 3 3 = 3 5 4 = 2 3 5 = 2 Z = 4 5 which leads to the implement the vending machine by the circuit shown in Figure 6. 6
s Z 2 s 2 3 s 3 4 s 4 Reset Clock 5 s 5 Figure 6. A one hot encoded circuit for the vending machine with synchronous active low Reset. Remark. The inspection method used in the case of one-hot encoding can quickly lead to expressions of next-state and output. However, the expressions thus obtained may not be the optimal ones. To optimize the expression, we still need to write the state-assigned table as below. Present State ext State = 5 4 3 2 Output = 5 4 3 2 = Z The remaining 27 valuations of the state variables are not used and hence not shown in the above table. They can be treated as don t cares in the derivation of the next-state and output expressions. sing Espresso, It should be noted that the inspection method corresponds to one specfic instance of assigning s and s to the don t cares. However, it may not necessarily provide us with the optimal expressions. 7
we can obtain the following optimized next-state and output expressions. = 5 3 2 2 = 2 3 3 = 3 5 4 = 2 3 5 = 2 Z = 4 5 For this example, it appears that the optimization of the expressions does not introduce big advantages over the inspection method. 8