Chapter 11 State Machine Design

Similar documents
WEEK 10. Sequential Circuits: Analysis and Design. Page 1

Section 6.8 Synthesis of Sequential Logic Page 1 of 8

Universidad Carlos III de Madrid Digital Electronics Exercises

Chapter 9 Introduction to Sequential Logic

UNIT III. Combinational Circuit- Block Diagram. Sequential Circuit- Block Diagram

1. Convert the decimal number to binary, octal, and hexadecimal.

CSE Latches and Flip-flops Dr. Izadi. NOR gate property: A B Z Cross coupled NOR gates: S M S R Q M

CPS311 Lecture: Sequential Circuits

Chapter 5 Flip-Flops and Related Devices

Final Exam review: chapter 4 and 5. Supplement 3 and 4

Asynchronous (Ripple) Counters

MC9211 Computer Organization

ELCT201: DIGITAL LOGIC DESIGN

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District UNIT-III SEQUENTIAL CIRCUITS

Chapter 4. Logic Design

ASYNCHRONOUS COUNTER CIRCUITS

Using minterms, m-notation / decimal notation Sum = Cout = Using maxterms, M-notation Sum = Cout =

Computer Architecture and Organization

Combinational vs Sequential

Chapter 7 Counters and Registers

Logic and Computer Design Fundamentals. Chapter 7. Registers and Counters

CHAPTER 4: Logic Circuits

Lecture 11: Synchronous Sequential Logic

Chapter 6. Flip-Flops and Simple Flip-Flop Applications

Chapter 5 Synchronous Sequential Logic

EE292: Fundamentals of ECE

Chapter 9 Counters. Clock Edge Output Q 2 Q 1 Q

Chapter 3. Boolean Algebra and Digital Logic

Chapter 5: Synchronous Sequential Logic

11.1 As mentioned in Experiment 10, sequential logic circuits are a type of logic circuit where the output

EKT 121/4 ELEKTRONIK DIGIT 1

MODULE 3. Combinational & Sequential logic

Sequential Logic Circuits

Counters

Vignana Bharathi Institute of Technology UNIT 4 DLD

The reduction in the number of flip-flops in a sequential circuit is referred to as the state-reduction problem.

RS flip-flop using NOR gate

Introduction. NAND Gate Latch. Digital Logic Design 1 FLIP-FLOP. Digital Logic Design 1

Digital Circuit And Logic Design I. Lecture 8

Digital Circuit And Logic Design I

EET2411 DIGITAL ELECTRONICS

UNIT IV. Sequential circuit

Combinational / Sequential Logic

Digital Fundamentals: A Systems Approach

Experiment 8 Introduction to Latches and Flip-Flops and registers

Sequential Circuits. Output depends only and immediately on the inputs Have no memory (dependence on past values of the inputs)

Digital Design, Kyung Hee Univ. Chapter 5. Synchronous Sequential Logic

Chapter 3: Sequential Logic Systems

Flip-Flops and Sequential Circuit Design

CHAPTER 4: Logic Circuits

CPE 200L LABORATORY 3: SEQUENTIAL LOGIC CIRCUITS UNIVERSITY OF NEVADA, LAS VEGAS GOALS: BACKGROUND: SR FLIP-FLOP/LATCH

EECS150 - Digital Design Lecture 19 - Finite State Machines Revisited

MODEL QUESTIONS WITH ANSWERS THIRD SEMESTER B.TECH DEGREE EXAMINATION DECEMBER CS 203: Switching Theory and Logic Design. Time: 3 Hrs Marks: 100

Unit 11. Latches and Flip-Flops

Logic Design ( Part 3) Sequential Logic- Finite State Machines (Chapter 3)

YEDITEPE UNIVERSITY DEPARTMENT OF COMPUTER ENGINEERING. EXPERIMENT VIII: FLIP-FLOPS, COUNTERS 2014 Fall

RS flip-flop using NOR gate

Introduction to Sequential Circuits

FLIP-FLOPS AND RELATED DEVICES

B.Tech CSE Sem. 3 15CS202 DIGITAL SYSTEM DESIGN (Regulations 2015) UNIT -IV

IT T35 Digital system desigm y - ii /s - iii

Synchronous Sequential Logic. Chapter 5

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

Digital Logic Design Sequential Circuits. Dr. Basem ElHalawany

Logic Design II (17.342) Spring Lecture Outline

Principles of Computer Architecture. Appendix A: Digital Logic

Experiment # 12. Traffic Light Controller

Switching Theory And Logic Design UNIT-IV SEQUENTIAL LOGIC CIRCUITS

`COEN 312 DIGITAL SYSTEMS DESIGN - LECTURE NOTES Concordia University

Figure 30.1a Timing diagram of the divide by 60 minutes/seconds counter

CS8803: Advanced Digital Design for Embedded Hardware

Logic Gates, Timers, Flip-Flops & Counters. Subhasish Chandra Assistant Professor Department of Physics Institute of Forensic Science, Nagpur


Logic Design Viva Question Bank Compiled By Channveer Patil

Logic. Andrew Mark Allen March 4, 2012

Lecture 8: Sequential Logic

SEQUENTIAL LOGIC. Satish Chandra Assistant Professor Department of Physics P P N College, Kanpur

Digital Logic Design ENEE x. Lecture 19

Digital Logic Design I

CHAPTER 6 COUNTERS & REGISTERS

Traffic Light Controller

Chapter 5 Sequential Circuits

DIGITAL TECHNICS II. Dr. Bálint Pődör. Óbuda University, Microelectronics and Technology Institute

UNIT-3: SEQUENTIAL LOGIC CIRCUITS

Counter dan Register

The basic logic gates are the inverter (or NOT gate), the AND gate, the OR gate and the exclusive-or gate (XOR). If you put an inverter in front of

Sequential Logic. Analysis and Synthesis. Joseph Cavahagh Santa Clara University. r & Francis. TaylonSi Francis Group. , Boca.Raton London New York \

MODU LE DAY. Class-A, B, AB and C amplifiers - basic concepts, power, efficiency Basic concepts of Feedback and Oscillation. Day 1

North Shore Community College

DIGITAL ELECTRONICS: LOGIC AND CLOCKS

Decade Counters Mod-5 counter: Decade Counter:

Counters. ENT 263 Digital Electronics

Subject : EE6301 DIGITAL LOGIC CIRCUITS

ME 515 Mechatronics. Introduction to Digital Electronics

10.1 Sequential logic circuits are a type of logic circuit where the output of the circuit depends not only on

D Latch (Transparent Latch)

Unit 9 Latches and Flip-Flops. Dept. of Electrical and Computer Eng., NCTU 1

St. MARTIN S ENGINEERING COLLEGE

problem maximum score 1 28pts 2 10pts 3 10pts 4 15pts 5 14pts 6 12pts 7 11pts total 100pts

Fig1-1 2-bit asynchronous counter

Transcription:

Chapter State Machine Design CHAPTER OBJECTIVES Upon successful completion of this chapter, you will be able to: Describe the components of a state machine. Distinguish between Moore and Mealy implementations of state machines. Draw the state diagram of a state machine from a verbal description. Use the state table method of state machine design to determine the Boolean equations of the state machine. Translate the Boolean equations of a state machine into a schematic. Determine whether the output of a state machine is vulnerable to asynchronous changes of input. Design state machine applications, such as a traffic light controller. Troubleshoot state machines by examining next state tables.

PHOTO: istockphoto.com/inok. Aspecial type of counter circuit is a finite state machine, a circuit that counts through a specific sequence of numbers. These circuits don t have to count up or down, but just have to count in a predictable sequence. For example, imagine an elevator controller: if you are on the 5th floor, which floor is next? It depends on whether you plan to go up or down, but once we know that, we can figure out which is next. We can design a finite state machine to count through any sequence we would like. A state machine is a digital circuit that goes through a predictable sequence of states depending on the current state and current inputs. Counters are special examples of state machines: a MOD- down counter that is currently on state 7 will go to state 6 on a clock edge. We can add inputs that will control the next state: for example, if we added an UP/DOWN input to a counter that told the circuit to count up, and the current state was 7, the next state would be 8. For this type of counter, its next state depends on its current state and the state of the UP/DOWN input. Two types of state machines are Moore machines and Mealy machines. In a Moore machine, the next state and output of the circuit depend only on its present state. The output of a Mealy machine depends on the present state and the state of one or more control inputs. The dependence on input states can lead to the output accidentally changing asynchronously, that is, not on a clock edge. However, this problem is easy to fix and a Mealy machine can often be done more efficiently than a Moore machine. 38

. STATE MACHINES KEY TERMS State machine A synchronous sequential circuit, consisting of a sequential logic section and a combinational logic section, whose outputs and internal flip-flops progress through a predictable sequence of states in response to a clock and other input signals. Moore machine A state machine whose output is determined only by the sequential logic of the machine. State variables The variables held in the flip-flops of a state machine that determine its present state. The number of state variables in a machine is equivalent to the number of flip-flops. Mealy machine A state machine whose output is determined by both the sequential logic and the combinational logic of the machine. The synchronous counters and shift registers we examined in Chapter are examples of a larger class of circuits known as state machines. As described for synchronous counters in Section.2, a state machine consists of a memory section that holds the present state of the machine and a control section that determines the machine s next state. These sections communicate via a series of command and status lines. Depending on the type of machine, the outputs will either be functions of the present state only or of the present and next states. Figure. shows the block diagram of a Moore machine. The outputs of a Moore machine are determined solely by the present state of the machine s memory section. The output may be directly connected to the Q outputs of the internal flip-flops, or the Q outputs might pass through a decoder circuit. The output of a Moore machine is synchronous to the system clock, because the output can change only when the machine s internal state variables change. The block diagram of a Mealy machine is shown in Figure.2. The outputs of the Mealy machine are derived from the combinational (control) and FIGURE. Moore-Type State Machine Outputs 382 Digital Electronics

FIGURE.2 Mealy-Type ype State Machine. Outputs the sequential (memory) parts of the machine. Therefore, the outputs can change asynchronously when the combinational circuit inputs change out of phase with the clock. (When we say that the outputs change asynchronously, we generally do not mean a change such as asynchronous reset directly on the machine s flip-flops. We simply mean a change that is not synchronized to the system clock.) Your Turn. What is the main difference between a Moore-type state machine and a Mealy-type state machine?.2 STATE MACHINES WITH NO CONTROL INPUTS KEY TERM Bubble A circle in a state diagram containing the state name and values of the state variables. A state machine can be designed using a classical technique, also called a state table design technique, similar to that used to design a synchronous counter. We will design several state machines using classical techniques. It is also possible to design a state machine with a specialized programming language, but we will not examine this method. As an example of the classical design technique, we will design a state machine whose output depends only on the clock input: a 3-bit counter with a Gray code count sequence. A 3-bit Gray code, shown in Table., changes only one bit between adjacent codes and is therefore not a binary-weighted sequence. TABLE. 3-Bit Gray Code Sequence Q 2 Q Q Chapter : State Machine Design 383

FIGURE.3 Gray Code on a Shaft Encoder Gray code is often used in situations where it is important to minimize the effect of single-bit errors. For example, suppose the angle of a motor shaft is measured by a detected code on a Gray-coded shaft encoder, shown in Figure.3. The encoder indicates a 3-bit number for each of eight angular positions by having three concentric circular segments for each code. A dark band indicates a and a trans parent band indicates a, with the most significant bit (MSB) as the outermost band. The dark or trans parent bands are detected by three sensors that detect light shining through a transparent band. (A real shaft encoder has more bits to indicate an angle more precisely. For example, a shaft encoder that measures an angle of degree would require nine bits, because there are 36 degrees in a circle and 2 8 # 36 # 2 9.) For most positions on the encoder, the error of a single bit results in a positional error of only one-eighth of the circle. This is not true with binary coding, where single bit errors can give larger positional errors. For example, if the positional decoder reads instead of, this is a difference of 4 in binary, representing an error of one-half of the circle. These same codes differ by only one position in Gray code. Classical Design Techniques We can summarize the classical design technique for a state machine as follows:. Define the problem. 2. Draw a state diagram. 3. Make a state table that lists all possible present states and inputs, and the next state and output state for each present state/input combination. List the present states and inputs in binary order. 4. Use flip-flop excitation tables to determine at what states the flip-flop synchronous inputs must be to make the circuit go from each present state to its next state. The next state variables are functions of the inputs and present state variables. 5. Write the output value for each present state/input combination. The output variables are functions of the inputs and present state variables. 6. Simplify the Boolean expression for each output and synchronous input. 7. Use the Boolean expressions found in Step 6 to draw the required logic circuit. Let us follow this procedure to design a 3-bit Gray code counter. We will modify the procedure to acknowledge there are no inputs other than the clock and no outputs that must be designed apart from the counter itself. FIGURE.4 State Diagram for a 3-Bit Gray Code Counter S6 S7 S5 S S4 S S3 S2. Define the problem. Design a counter whose outputs progress in the sequence defined in Table.. 2. Draw a state diagram. The state diagram is shown in Figure.4. In addition to the values of state variables shown in each circle (or bubble), we also indicate a state name, such as s, s, s2, and so on. This name is independent of the value of state variables. We use numbered states (s, s,...) for convenience, but we could use any names we wanted to. 3. Make a state table. The state table, based on D flip-flops, is shown in Table.2. Because there are eight unique states in the state diagram, we require three state variables (2 3 5 8), and hence three flip-flops. Note that the present states are in binary-weighted order, even though the count does not progress in this order. In such a case, it is essential to have an accurate state diagram, from which we derive each next state. For example, if the present state is, the next state is not, as we would expect, but, which we derive by examining the state diagram. 384 Digital Electronics

TABLE.2 State Table for a 3-Bit Gray Code Counter Present State Next State Synchronous Inputs Q 2 Q Q Q 2 Q Q D 2 D D Why list the present states in binary order, rather than the same order as the output sequence? By doing so, we can easily simplify the equations for the D inputs of the flip-flops by using a series of Karnaugh maps. This is still possible, but harder to do, if we list the present states in order of the output sequence. 4. Use flip-flop excitation tables to determine at what states the flip-flop synchronous inputs must be to make the circuit go from each present state to its next state. This is not necessary if we use D flip-flops, because Q follows D. The D inputs are the same as the next state outputs. This is easily verified in Table.2. For JK flip-flops, we would follow the same procedure as for the design of synchronous counters outlined in Chapter. 5. Simplify the Boolean expression for each synchronous input. Figure.5 shows three Karnaugh maps, one for each D input of the circuit. The K-maps yield three Boolean equations: D 2 5 Q Q _ Q 2 Q D 5 Q Q _ Q_ 2 Q D 5 Q _ 2 Q_ Q 2 Q 6. Draw the logic circuit for the state machine. Figure.6 shows the circuit for a 3-bit Gray code counter drawn in Multisim. The Set inputs of the flip-flops are disabled by tying them HIGH. The flip-flop Reset inputs are all connected to a pushbutton that allows the counter to be manually reset to at any time. A timing diagram for this circuit is shown in Figure.7, with the outputs shown as individual waveforms and as a group with a binary value. FIGURE.5.5 Karnaugh Maps for 3-Bit Gray Code Counter Q 2 Q Q Q 2 Q Q Q 2 Q Q D 2 Q Q Q 2 Q D Q 2 Q Q Q D Q 2 Q Q 2 Q Chapter : State Machine Design 385

FIGURE.6 Logic Diagram of a 3-Bit Gray Code Counter V CC Q nq Q2 Q D Q CLK ~Q Q2 Q Q Q nq nq2 Q D Q CLK ~Q J V CC R kω R2 kω nq2 nq Q2 Q D Q CLK ~Q GND J2 Key = R Key = C FIGURE.7.7 3-Bit Gray Code Waveforms Clock Q 2 Q Q Q[2..] Your Turn.2 Write the Boolean equations for the J and K inputs of the flip-flops in a 3-bit Gray code counter based on JK flipflops. The solution requires the use of the flip-flop excitation table shown in Table.7 of the previous chapter. 386 Digital Electronics

.3 STATE MACHINES WITH CONTROL INPUTS KEY TERMS Control input A state machine input that directs the machine from state to state. Conditional transition A transition between states of a state machine that occurs only under specific conditions of one or more control inputs. Unconditional transition A transition between states of a state machine that occurs regardless of the status of any control inputs. As an extension of the techniques used in the previous section, we will examine the design of state machines that use control inputs, and the clock, to direct their operation. Outputs of these state machines will not necessarily be the same as the states of the machine s flip-flops. As a result, this type of state machine requires a more detailed state diagram notation, such as that shown in Figure.8. The state machine represented by the diagram in Figure.8 has two states, and thus requires only one state variable. Each state is represented by a bubble (circle) containing the state name and the value of the state variable. For example, the bubble containing the notation start indicates that the state called start corresponds to a state variable with a value of. Each state must have a unique value for the state variable(s). Transitions between states are marked with a combination of input and output values corresponding to the transition. The inputs and outputs are labeled in, in2,..., inx/ out, out2,..., outx. The inputs and outputs are sometimes FIGURE.8 State Diagram Notation simply indicated by the value of each variable for each transition. In this case, a legend indicates which variable corresponds to which position in the label. For example, the legend in the state diagram of Figure.8 indicates that the inputs and outputs are labeled in the order in/out, out2. Thus, if the machine is in the start state and the input in goes to, there is a transition to the state continue. During this transition, out goes to and out2 goes to. This is indicated by the notation / beside the transitional arrow. This is called a conditional transition because the transition depends on the state of in. The other possibility from the start state is a no-change transition, with both outputs at, if in 5. This is shown as /. If the machine is in the state named continue, the notation X/ indicates that the machine makes a transition back to the start state, regardless of the value of in, and that out 5 and out2 5 upon this transition. Because the transition always happens, it is called an unconditional transition. What does this state machine do? We can determine its function by analyzing the state diagram: X / Unconditional transition start continue / State name / in/out, out2 State variable Input value Output value Conditional transition Legend. There are two states, called start and continue. The machine begins in the start state and waits for a LOW input on in. As long as in is HIGH, the machine waits and the outputs out and out2 are both LOW. 2. When in goes LOW, the machine makes a transition to continue in one clock pulse. Output out goes HIGH. Chapter : State Machine Design 387

FIGURE.9 Ideal Operation of State Machine in Figure.8 Clock in out out2 state start continue start 3. On the next clock pulse, regardless of the values of the input, the machine goes back to start. The output out2 goes HIGH and out goes back LOW. 4. If in is HIGH, the machine waits for a new LOW on in, and both outputs are LOW again. If in is LOW, the cycle repeats. In summary, the machine waits for a LOW input on in, then generates a pulse of one clock cycle duration on out, then on out2. A timing diagram describing this operation is shown in Figure.9. TABLE.3 Figure.8 Present State State Table for State Diagram in Input Next State Sync. Inputs Oututs Q in Q JK Out Out2 X X X X TABLE.4 JK Flip-Flop Excitation Table Transition JK X X X X Classical Design of State Machines with Control Inputs We can use the classical design technique of the previous section to design a circuit that implements the state diagram of Figure.8.. Define the problem. Implement a digital circuit that generates a pulse on each of two outputs, as previously described. For this implementation, let us use JK flip-flops for the state logic. If we so chose, we could also use D flip-flops. 2. Draw a state diagram. The state diagram is shown in Figure.8. 3. Make a state table. The state table is shown in Table.3. The combinations of present state and input are listed in binary order, thus making Table.3 into a truth table for the next state and output functions. Because there are two states, we require one state variable, Q. The next state of Q, a function of the present state and the input in, is determined by examining the state diagram. (Thus, if you are in state, the next state is if in 5 and if in 5. If you are in state, the next state is always.) 4. Use flip-flop excitation tables to determine at what states the flip-flop synchronous inputs must be to make the circuit go from each present state to its next state. Table.4 shows the flip-flop excitation table for a JK flip-flop, specifying the necessary values of J and K to give the transition shown. The synchronous inputs are derived from the present-to-next state transitions in Table.4 and entered into Table.3. (Refer to Table.7 and the synchronous counter design process in Chapter for more detail about using flip-flop excitation tables.) 5. Write the output values for each present state/input combination. These can be determined from the state diagram and are entered in the last two columns of Table.3. 6. Simplify the Boolean expression for each output and synchronous input. The following equations represent the next state and output logic of the state machine: J 5 Q _. in Q. in 5 (Q _ Q)in 5 in K 5 out 5 Q _. in out2 5 Q. in Q. in 5 Q(in in) 5 Q 7. Use the Boolean expressions found in Step 6 to draw the required logic circuit. Figure. shows the circuit of the state machine. Because out is a function 388 Digital Electronics

FIGURE.. Logic Circuit of the State Machine Described in Figure.8 U3 out V CC V CC AND2 J Key = R kω in U2 NOT J CLK Q out2 GND V Hz + GND V CC K ~Q VCC of the control section and the memory section of the machine, we can categorize the circuit as a Mealy machine. (All counter circuits that we have previously examined have been Moore machines because their outputs are derived solely from the flip-flop outputs of the circuit.) The circuit is a Mealy machine, so it is vulnerable to asynchronous changes of output due to asynchronous input changes. This is shown in the simulation waveforms of Figure.. Ideally, out should not change until the first positive clock edge after in goes LOW. However, out is derived from a combinational output, so it will change FIGURE. Simulation of State Machine Circuit of Figure. Showing an Asynchronous Pulse Error CLOCK in out out2 Chapter : State Machine Design 389

FIGURE.2 State Machine with Synchronizing Flip-Flops on the Outputs V CC U3 AND2 D Q out GND J Key = R kω in U2 NOT V CC J Q CLK K ~Q CLK ~Q D Q CLK ~Q out2 V Hz + GND FIGURE.3 Properly Synchronized Outputs of the State Machine in Figure.2 CLOCK in out out2 as soon as in goes LOW, after allowing for a short propagation delay. If in is not held LOW past the first positive clock edge, out will still pulse asynchronously, but the machine will not move on to the next state. If output synchronization is a problem (and it may not be), it can be fixed by adding a synchronizing D flip-flop to each output, as shown in Figure.2. The state variable is stored as the state of the JK flip-flop. This state is clocked through a D flip-flop to generate out2 and combined with in to generate out via another flip-flop. The simulation for this circuit, shown in Figure.3, indicates that the two outputs are synchronous with the clock, with each output pulse lasting for the full time of one clock cycle. Example. A state machine called a single-pulse generator operates as follows:. The circuit has two states: seek and find, an input called sync, and an output called pulse. 2. The state machine resets to the state seek. If sync 5, the machine remains in seek and the output, pulse, remains LOW. continued... 39 Digital Electronics

FIGURE.4 Example.: State Diagram for a Single- Pulse Generator / seek find / / sync/pulse / FIGURE.5 Example.: Single-Pulse Generator Key = S GND J V CC R kω sync U2 NOT V Hz + GND TABLE.5 Generator D CLK Q ~Q U3 AND2 State Table for Single-Pulse pulse 3. When sync 5, the machine makes a transition to find. In this transition, pulse goes HIGH. 4. When the machine is in state find and sync 5, the machine remains in find and pulse goes LOW. 5. When the machine is in find and sync 5, the machine goes back to seek and pulse remains LOW. Design the circuit for the single-pulse generator, using D flip-flops for the state logic. Use Multisim to draw the state machine circuit. Create a simulation to verify the design operation. Briefly describe what this state machine does. Present State Input Next State Sync. Input Output Q sync. Q D pulse Solution Figure.4 shows the state diagram derived from the description of the state machine. The state table is shown in Table.5. Because Q follows D, the D input is the same as the next state of Q. The next-state and output equations are: D 5 Q _. sync Q. sync 5 sync pulse 5 Q _. sync Figure.5 shows the state machine circuit derived from these Boolean equations. The simulation for this circuit is shown in Figure.6. The simulation shows that the circuit generates one pulse when the input sync goes LOW, regardless of the length of time that sync is LOW. The circuit could be used in conjunction with a debounced pushbutton to produce exactly one pulse, regardless of how long the pushbutton was held down. Figure.7 shows such a circuit. FIGURE.6 Example.: Simulation Waveforms for a Single-Pulse Generator CLOCK SYNC PULSE continued... Chapter : State Machine Design 39

FIGURE.7 Example.: Single-Pulse Generator Used with a Debounced Pushbutton N.O. V CC Debouncer CLK SYNC Single-pulse generator PULSE Example.2 The state machine of Example. is vulnerable to asynchronous input changes. How do we know this from the circuit schematic and from the simulation waveform? Modify the circuit to eliminate the asynchronous behavior and show the effect of the change on a simulation of the design. How does this change improve the design? Solution The output, pulse, in the state machine of Figure.5 is derived from the state flip-flop and the combinational logic of the circuit. The output can be affected by a change that is purely combinational, thus making the output asynchronous. This is demonstrated on the first pulse of the simulation in Figure.6, where pulse momentarily goes HIGH between clock edges. Because no clock edge was present when either the input, sync, changed or when pulse changed, the output pulse must be due entirely to changes in the combinational part of the circuit. The circuit output can be synchronized to the clock by adding an output flip-flop, as shown in Figure.8. A simulation of this circuit is shown in Figure.9. With the synchronized output, the output pulse is always the same width: one clock period. This gives a more predictable operation of the circuit. FIGURE.8.88 Example.2: Single-Pulse Generator with a Synchronizing Flip-FlopFlop V CC U3 D Q pulse Key = S GND J R kω sync U2 NOT D Q CLK ~Q AND2 CLK ~Q V Hz + GND continued... 392 Digital Electronics

FIGURE.9 Example.2: Simulation Waveforms for a Single-Pulse Generator with a Synchronizing Flip-FlopFlop CLOCK SYNC PULSE Your Turn.3 Briefly explain why the single-pulse circuit in Figure.8 has a flip-flop on its output..4 UNUSED STATES IN STATE MACHINES In our study of counter circuits in Chapter, we found that when a counter modulus is not equal to a power of 2 there are unused states in the counter s sequence. For example, a mod- counter has six unused states, as the counter requires four bits to express ten states and the maximum number of 4-bit states is sixteen. The unused states (,,,,, and ) have to be accounted for in the design of a mod- counter. The same is true of state machines whose number of states does not equal a power of 2. For instance, a machine with five states requires three state variables. There are up to eight states available in a machine with three state variables, leaving three unused states. Figure.2 shows the state diagram of such a machine. Unused states can be dealt with in two ways: they can be treated as don t care states, or they can be assigned specific destinations in the state diagram. In the latter case, the safest destination is the first state, in this case the state called start. Chapter : State Machine Design 393

FIGURE.2.2 State Diagram for a Two-Pulse Generator / X / start / in/out, out2 pulse2 wait / X / pulse / wait2 / / Example.3 Redraw the state diagram of Figure.2 to include the unused states of the machine s state variables. Set the unused states to have a destination state of start. Briefly describe the intended operation of the state machine. Solution Figure.2 shows the revised state diagram. The machine begins in state start and waits for a HIGH on in. The machine then makes a transition to wait and stays there until in goes LOW FIGURE.2 Example.3: State Diagram for a Two-Pulse Generator Showing Unused States unused3 X / / unused unused2 X / X / X / start / in/out, out2 pulse2 wait / X / pulse / wait2 / / continued... 394 Digital Electronics

again. The machine goes to wait2 and stays there until in goes HIGH and then makes an unconditional transition to pulse on the next clock pulse. Until this point, there is no change in either output. The machine makes an unconditional transition to pulse2 and makes out go HIGH. The next transition, also unconditional, is to start, when out goes LOW and out2 goes HIGH. If in is LOW, the machine stays in start. Otherwise, the cycle continues as outlined. In either case, out2 goes LOW again. Thus, the machine waits for a HIGH-LOW-HIGH input sequence and generates a pulse sequence on two outputs. Example.4 Design the state machine described in the modified state diagram of Figure.2. Draw the state machine in Multisim and verify its function with a simulation. Solution Table.6 shows the state table of the state machine represented by Figure.2. Figure.22 shows the Karnaugh maps used to simplify the next-state equations for the state variable flip-flops. The output equations can be simplified by inspection. The next-state and output equations for the state machine are: D 2 5 Q _ Q Q 2 D 5 Q _ Q Q_ Q_ Q_ Q in 2 2 D 5 Q _ Q_ in Q_ Q_ in 2 2 out 5 Q _ Q Q 2 out2 5 Q 2 Q _ Q_ TABLE.6 State Table for State Machine of Figure.2 Present State Input Next State Outputs Q 2 Q Q in Q 2 Q Q Out Out2 continued... Chapter : State Machine Design 395

V CC FIGURE.22 Example.4: Karnaugh Maps for Two-Pulse Generator Showing Unused States Q in Q 2 Q Q in Q 2 Q Q in Q 2 Q D 2 D D Figure.23 shows the Multisim schematic for the state machine. Figure.24 shows the simulation waveforms. FIGURE.23 Example.4: Two-Pulse Generator GND Key = R kω in D Q >CLK ~Q Q2 nq2 D Q >CLK ~Q Q nq D Q >CLK ~Q Q nq out out2 V Hz + GND continued... 396 Digital Electronics

FIGURE.24.24 Example.4: Simulation of a Two-Pulse Generator CLOCK in out out2 state pulse pulse2 start wait wait2 start Your Turn.4 Is the state machine designed in Example.4 a Moore machine or a Mealy machine? Why?.5 TRAFFIC LIGHT CONTROLLER A simple traffic light controller can be implemented by a state machine with a state diagram such as the one shown in Figure.25. The control scheme assumes control over a north-south road and an east-west road. The north-south lights are controlled by outputs called nsr, nsy, and nsg (north-south red, yellow, green). The east-west road is controlled by similar outputs called ewr, ewy, and ewg. A HIGH controller output turns on a light. Thus, an output corresponds to the north-south red and east-west green lights. An input called TIMER controls the length of the two green-light cycles. When TIMER 5, there is a transition from s to s or from s2 to s3 on the next positive clock edge (s represents the EW green; s2 the NS green). This transition accompanies a change from green to yellow on the active road. The light on the other road stays red. An unconditional transition follows, changing the yellow light to red on one road and the red light to green on the other. FIGURE.25 State Diagram for a Traffic Light Controller X/ s3 / s / TIMER/ nsr,nsy,nsg, s ewr,ewy,ewg s2 / / X/ Chapter : State Machine Design 397

FIGURE.26.26 Demonstration Circuit for a Traffic Light Controller in Multisim North-South Road Clock Timer SC SC2 TRAFFIC_LIGHT_SINGLE CLOCK Q2 Q Q Cycle Timer MOD-5 Counter Timer CLOCK nsr nsy nsg ewr ewy ewg East-West Road + V Traffic Control State Machine Hz Note: Hz clock is chosen for simulation, GND but does not reflect real-time value. TRAFFIC_LIGHT_SINGLE The cycle can be set to any length by changing the signal on the TIMER input. (The yellow light will always be on for one clock pulse in this design.) For ease of observation, we will use a cycle of ten clock pulses. For either direction, the cycle consists of 4 clocks GREEN, clock YELLOW, and 5 clocks RED. This cycle can be generated by the most significant bit of a mod-5 counter, as shown in Figure.26. Figure.27 shows a simulation of the mod-5 counter and output controller. The MSB of the counter goes HIGH for one clock period, then LOW for four. When applied to the TIMER input of the output controller, this signal directs the controller from state to state. The north-south lights are red for five clock pulses (shown by in the north_south waveform). At the same time, the east-west lights are green for four clock pulses (east_west 5 ), followed by yellow for one clock pulse (east_west 5 ). The cycle continues with an east-west red and north-south green and then yellow. FIGURE.27.27 Timing Diagram for a Traffic Light Controller CLOCK Q[2..] Q2 State ns[r,y,g] ew[r,y,g] s2 s3 s s s2 s3 398 Digital Electronics

Example.5 Multisim Example Multisim File:.8 Traffic Light Controller.ms Open the Multisim file for this example and run it as a simulation. a. How many times does the Clock light pulse when the Timer light is off? How many times does the Clock light pulse when the Timer light is on? b. When does one of the yellow lights turn on relative to the Timer light? c. How can you make the overall traffic cycle longer with the components shown? Adjust the value of a FIGURE.28 Example.5: Adjusting the component to make the traffic cycle twice as long. d. What change would need to be made to the circuit Frequency of the Clock Voltage Generator in the to change the traffic cycle to: GREEN for eight Traffic fic Light Controller of Figure.26.26 pulses, YELLOW for one pulse, and RED for nine pulses? Solution a. The Clock light pulses four times when the Timer light is off and once when it is on. b. Either the north-south yellow or the east-west yellow light turns on when the Timer light is on. Which light turns on depends on which green light (north-south or east-west) was last on. c. The overall cycle can be made longer or shorter by adjusting the frequency of the clock signal. If you double-click on the clock voltage generator, you will see a dialog box like the one shown in Figure.28. To make the overall cycle twice as long, change the clock frequency to 5 Hz. d. The mod-5 counter could be replaced by a mod-9 counter. This counter has a most significant bit that is LOW for eight pulses and HIGH for one pulse, which meets the requirements of the circuit. Chapter : State Machine Design 399

SUMMARY. A state machine is a synchronous sequential circuit with a memory section (flip-flops) to hold the present state of the machine and a control section (gates) to determine the machine s next state. 2. The number of flip-flops in a state machine s memory section is the same as the number of state variables. 3. Two main types of state machine are the Moore machine and the Mealy machine. 4. The outputs of a Moore machine are entirely dependent on the states of the machine s flipflops. Output changes will always be synchronous with the system clock. 5. The outputs of a Mealy machine depend on the states of the machine s flip-flops and the gates in the control section. A Mealy machine s outputs can change asynchronously, relative to the system clock. 6. A state machine can be designed using a classical, or state table, technique using the same method as in designing a synchronous counter, as follows: a. Define the problem and draw a state diagram. b. Construct a table of present and next states. c. Use flip-flop excitation tables to determine the flip-flop inputs for each state transition. d. Use Boolean algebra or K-maps to find the simplest Boolean expression for flip-flop inputs (D or JK) in terms of outputs (Q). e. Draw the logic diagram of the state machine. 7. The state names in a state machine can be named numerically (s, s, s2,...) or literally (start, idle, read, write), depending on the machine function. State names are independent of the values of the state variables. 8. Notation for a state diagram includes a series of bubbles (circles) containing state names and state name values of state variables in the form state variables. 9. The inputs and outputs of a state machine are labeled in, in2,..., inx/out, out2,..., outx.. Transitions between states can be conditional or unconditional. A conditional transition happens only under certain conditions of a control input and is labeled with the relevant input condition. An unconditional transition happens under all conditions of input and is labeled with an X for each input variable.. Mealy machine outputs are susceptible to asynchronous output changes if a combinational input changes out of synchronization with the clock. This can be remedied by clocking each output through a separate synchronizing flip-flop. 2. A maximum of 2 n states can be assigned to a state machine that has n state variables. If the number of states is less than 2 n, the unused states must be accounted for. Either they can be treated as don t care states, or they can be assigned a specific destination state, usually the reset state. 4 Digital Electronics

BRING IT HOME. State Machines. Is the state machine in Figure.29 a Moore machine or a Mealy machine? Explain your answer..2 Is the state machine in Figure.3 a Moore machine or a Mealy machine? Explain your answer. FIGURE.29 Problem.: State Machine Circuit in INPUT clk INPUT XOR DFF PRN D Q CLRN AND2 OUTPUT PULSE FIGURE.3 Problem.2: State Machine Circuit in clk INPUT INPUT XOR DFF D PRN Q CLRN XOR DFF D PRN Q CLRN OUTPUT OUTPUT out out.2 State Machines with No Control Inputs.3 A 4-bit Gray code sequence is shown in Table.7. Use classical design methods to design a counter with this sequence, using D flip-flops. Draw the resulting circuit diagram in Multisim and verify the circuit operation..4 Use classical state machine design techniques to design a counter whose output sequence is shown in Table.8. (This is a divide-by-twelve counter in which the MSB output has a duty cycle of 5%.) Draw the state diagram, derive synchronous equations of the flip-flops, draw the circuit implementation in Multisim, and verify the circuit s function..3 State Machines with Control Inputs.5 Use classical state machine design techniques to find the Boolean next state and output equations for the state machine represented TABLE.7 4-Bit Gray Code Sequence for Problem.3 Q 3 Q 2 Q Q continues... Chapter : State Machine Design 4

continued... TABLE.8 Counter Sequence for Problem.4 Q 3 Q 2 Q Q.6 Using classical design techniques, find the Boolean expressions for the next state and output for the state diagram shown in Figure.4. Use JK flip-flops..4 Unused States in State Machines.7 Refer to the state diagram in Figure.32. a. How many state variables are required to implement this state machine? Why? b. How many unused states are there for this state machine? List the unused states. c. Complete the partial timing diagram shown in Figure.33 to illustrate one complete cycle of the state machine represented by the state diagram of Figure.32. FIGURE.32 Problem.7: State Diagram by the state diagram in Figure.3. Draw the state machine circuit in Multisim and verify the operation of the circuit. Briefly explain the intended function of the state machine. FIGURE.3 Problem.5: State Diagram s3 X/, X/, /, s s2 in/out, out2 /, /, s /, X,/ s4 X,X / X,X / in,in2/out s X,/ X,X / s3 s2 s,x /,X /.8 Use classical state machine design techniques to implement the state machine described by the state diagram of Figure.32 using Multisim. Verify the operation of the circuit by running the Multisim files as a simulation. FIGURE.33 Problem.7: Partial Timing Diagram CLOCK in in2 out state s s 42 Digital Electronics

EXTRA MILE.3 State Machines with Control Inputs.9 Referring to the simulation for the state machine in Problem.5, briefly explain why it is susceptible to asynchronous input changes. Modify the state machine circuit to eliminate the asynchronous behavior of the outputs. Verify the function of the modified state machine.. A state machine is used to control an analogto-digital converter, as shown in the block diagram of Figure.34. FIGURE.34 Problem.: Analog-to- Digital Converter and Controller Analog-to-digital Controller converter E F Use classical state machine design techniques to design the controller. Draw the required circuit in Multisim and verify its operation. Is this machine vulnerable to asynchronous input change?.4 Unused States in State Machines. Use classical state machine design techniques to design a state machine described by the state diagram of Figure.35. Briefly describe the intended operation of the circuit. Verify the operation of the state machine design. Unused states may be treated as don t care states, but unspecified outputs should always be assigned to. go reset clk go reset sc oe eoc sc oe eoc FIGURE.35 Problem.: State Diagram /, s /, in/out,out2 /, The controller has four states, defined by state variables Q and Q as follows: idle (), start (), waiting (), and read (). There are two outputs: sc (Start Conversion; active-high) and oe (Output Enable; active-low). There are four inputs: clock, go (active-low), eoc (End of Conversion), and asynchronous reset (active- LOW). The machine operates as follows: a. In the idle state, the outputs are: sc 5, oe 5. The machine defaults to the idle state when the machine is reset. b. Upon detecting a at the go input, the machine makes a transition to the start state. In this transition, sc 5, oe 5. c. The machine makes an unconditional transition to the waiting state; sc 5, oe 5. It remains in this state, with no output change, until input eoc 5. d. When eoc 5, the machine goes to the read state; sc 5, oe 5. e. The machine makes an unconditional transition to the idle state; sc 5, oe 5. /, s4 X/, s3 X/, X /, s2 s.2 Determine the next state for each of the unused states of the state machine designed in Problem.. Use this analysis to redraw the state diagram of Figure.35 so that it properly includes the unused states. (There is more than one right answer, depending on the result of the Boolean simplification process used in Problem. to simplify the equation for D.).5 Traffic Light Controller.3 Use classical state machine design techniques to design the state machines for the mod-5 counter and traffic light controller shown in Figure.26. Chapter : State Machine Design 43