EECS150 - Digital Design Lecture 19 - Finite State Machines Revisited

Similar documents
EECS150 - Digital Design Lecture 15 Finite State Machines. Announcements

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

Universidad Carlos III de Madrid Digital Electronics Exercises

Lecture 11: Synchronous Sequential Logic

Chapter 5 Synchronous Sequential Logic

Chapter 5. Introduction

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

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

Digital Logic Design I

Logic Design II (17.342) Spring Lecture Outline

Digital Fundamentals: A Systems Approach

Chapter 5: Synchronous Sequential Logic

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

ELCT201: DIGITAL LOGIC DESIGN

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science SOLUTIONS

FPGA Implementation of Sequential Logic

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science. EECS 150 Spring 2000

Two types of state machine as classified by output formation

Chapter 3. Boolean Algebra and Digital Logic

Section 6.8 Synthesis of Sequential Logic Page 1 of 8

Advanced Digital Logic Design EECS 303

Chapter 5 Synchronous Sequential Logic

Software Engineering 2DA4. Slides 9: Asynchronous Sequential Circuits

Counters

CS3350B Computer Architecture Winter 2015

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

More design examples, state assignment and reduction. Page 1

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

Finite State Machine Design

Sequential Logic Circuits

Sequential Logic. E&CE 223 Digital Circuits and Systems (A. Kennings) Page 1

Asynchronous (Ripple) Counters

Digital Circuit And Logic Design I. Lecture 8

Digital Circuit And Logic Design I

Introduction to Sequential Circuits

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

Switching Circuits & Logic Design, Fall Final Examination (1/13/2012, 3:30pm~5:20pm)

Synchronous Sequential Logic

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

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 6 COUNTERS & REGISTERS

Sequential Design Basics

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

Laboratory Exercise 7

CS8803: Advanced Digital Design for Embedded Hardware

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


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

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

ECE 301 Digital Electronics

2 Sequential Circuits

Objectives. Combinational logics Sequential logics Finite state machine Arithmetic circuits Datapath

L5 Sequential Circuit Design

Figure 1 shows a simple implementation of a clock switch, using an AND-OR type multiplexer logic.

EECS 270 Final Exam Spring 2012

CSE115: Digital Design Lecture 23: Latches & Flip-Flops

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

Read-only memory (ROM) Digital logic: ALUs Sequential logic circuits. Don't cares. Bus

First Name Last Name November 10, 2009 CS-343 Exam 2

P U Q Q*

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

Chapter 5 Sequential Circuits

CS61C : Machine Structures

Combinational / Sequential Logic

Analysis of Clocked Sequential Circuits

More on Flip-Flops Digital Design and Computer Architecture: ARM Edition 2015 Chapter 3 <98> 98

1.b. Realize a 5-input NOR function using 2-input NOR gates only.

ECE 25 Introduction to Digital Design. Chapter 5 Sequential Circuits ( ) Part 1 Storage Elements and Sequential Circuit Analysis

Universal Asynchronous Receiver- Transmitter (UART)

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

CSE140L: Components and Design Techniques for Digital Systems Lab. FSMs. Tajana Simunic Rosing. Source: Vahid, Katz

CS 110 Computer Architecture. Finite State Machines, Functional Units. Instructor: Sören Schwertfeger.

EECS150 - Digital Design Lecture 10 - Interfacing. Recap and Topics

Note that none of the above MAY be a VALID ANSWER.

Review of digital electronics. Storage units Sequential circuits Counters Shifters

CS61C : Machine Structures

Digital Logic Design Sequential Circuits. Dr. Basem ElHalawany

Chapter. Synchronous Sequential Circuits

Logic Design. Flip Flops, Registers and Counters

EE292: Fundamentals of ECE

DEPARTMENT OF ELECTRICAL &ELECTRONICS ENGINEERING DIGITAL DESIGN

California State University, Bakersfield Computer & Electrical Engineering & Computer Science ECE 3220: Digital Design with VHDL Laboratory 7

ASYNCHRONOUS COUNTER CIRCUITS

The outputs are formed by a combinational logic function of the inputs to the circuit or the values stored in the flip-flops (or both).

CHAPTER 4: Logic Circuits

ELE2120 Digital Circuits and Systems. Tutorial Note 8

Counter dan Register

CHAPTER 4: Logic Circuits

Synchronous Sequential Logic

Sequential logic. Circuits with feedback. How to control feedback? Sequential circuits. Timing methodologies. Basic registers

EECS 373 Design of Microprocessor-Based Systems

Problems with D-Latch

Sequential Circuits. Sequential Logic. Circuits with Feedback. Simplest Circuits with Feedback. Memory with Cross-coupled Gates.

(CSC-3501) Lecture 7 (07 Feb 2008) Seung-Jong Park (Jay) CSC S.J. Park. Announcement

Chapter 1: Switching Algebra Chapter 2: Logical Levels, Timing & Delays. Introduction to latches Chapter 9: Binary Arithmetic

Unit 11. Latches and Flip-Flops

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

! Two inverters form a static memory cell " Will hold value as long as it has power applied

Synchronous Sequential Logic. Chapter 5

Transcription:

EECS150 - Digital Design Lecture 19 - Finite State Machines Revisited April 2, 2013 John Wawrzynek Spring 2013 EECS150 - Lec19-fsm Page 1 Finite State Machines (FSMs) FSM circuits are a type of sequential circuit: output deps on present and past inputs effect of past inputs is represented by the current state Behavior is represented by State Transition Diagram: traverse one edge per clock cycle. Spring 2013 EECS150 - Lec19-FSM Page 2

FSM Implementation Flip-flops form state register number of states 2number of flip-flops CL (combinational logic) calculates next state and output Remember: The FSM follows exactly one edge per cycle. So far we have learned how to implement in Verilog. Now we learn how to design by hand to the gate level. Spring 2013 EECS150 - Lec19-FSM Page 3 Parity Checker Example A string of bits has even parity if the number of 1 s in the string is even. Design a circuit that accepts a bit-serial stream of bits and outputs a 0 if the parity thus far is even and outputs a 1 if odd: Next we take this example through the formal design process. But first, can you guess a circuit that performs this function? Spring 2013 EECS150 - Lec19-FSM Page 4

Formal Design Process State Transition Diagram circuit is in one of two states. transition on each cycle with each new input, over exactly one arc (edge). Output deps on which state the circuit is in. Spring 2013 EECS150 - Lec19-FSM Page 5 State Transition Table: present state Formal Design Process next OUT IN state EVEN 0 0 EVEN EVEN 0 1 ODD ODD 1 0 ODD ODD 1 1 EVEN Invent a code to represent states: Let 0 = EVEN state, 1 = ODD state present state (ps) OUT IN next state (ns) 0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 Derive logic equations from table (how?): OUT = PS NS = PS xor IN Spring 2013 EECS150 - Lec19-FSM Page 6

Logic equations from table: OUT = PS NS = PS xor IN Formal Design Process Circuit Diagram: XOR gate for NS calculation DFF to hold present state no logic needed for output in this example. ps ns Spring 2013 EECS150 - Lec19-FSM Page 7 Review of Design Steps: Formal Design Process 1. Specify circuit function (English) 2. Draw state transition diagram 3. Write down symbolic state transition table 4. Write down encoded state transition table 5. Derive logic equations 6. Derive circuit diagram Register to hold state Combinational Logic for Next State and Outputs Spring 2013 EECS150 - Lec19-FSM Page 8

Combination Lock Example Used to allow entry to a locked room: 2-bit serial combination. Example 01,11: 1. Set switches to 01, press ENTER 2. Set switches to 11, press ENTER 3. OPEN is asserted (OPEN=1). If wrong code, ERROR is asserted (after second combo word entry). Press Reset at anytime to try again. Spring 2013 EECS150 - Lec19-FSM Page 9 Combinational Lock STD Assume the ENTER button when pressed generates a pulse for only one clock cycle. Spring 2013 EECS150 - Lec19-FSM Page 10

Symbolic State Transition Table RESET ENTER COM1 COM2 Preset State Next State OPEN ERROR 0 0 * * START START 0 0 0 1 0 * START BAD1 0 0 0 1 1 * START OK1 0 0 0 0 * * OK1 OK1 0 0 0 1 * 0 OK1 BAD2 0 0 0 1 * 1 OK1 OK2 0 0 0 * * * OK2 OK2 1 0 0 0 * * BAD1 BAD1 0 0 0 1 * * BAD1 BAD2 0 0 0 * * * BAD2 BAD2 0 1 1 * * * * START 0 0 Decoder logic for checking combination (01,11): Spring 2013 EECS150 - Lec19-FSM Page 11 Encoded ST Table Assign states: START=000, OK1=001, OK2=011 BAD1=100, BAD2=101 Omit reset. Assume that primitive flip-flops has reset input. Rows not shown have don t cares in output. Correspond to invalid PS values. NS2 NS1 NS0 What are the output functions for OPEN and ERROR? Spring 2013 EECS150 - Lec19-FSM Page 12

State Encoding In general: # of possible FSM state = 2 # of Flip-flops Example: state1 = 01, state2 = 11, state3 = 10, state4 = 00 However, often more than log 2 (# of states) FFs are used, to simplify logic at the cost of more FFs. Extreme example is one-hot state encoding. Spring 2013 EECS150 - Lec19-FSM Page 13 One-hot encoding of states. One FF per state. State Encoding Why one-hot encoding? Simple design procedure. Circuit matches state transition diagram (example next page). Often can lead to simpler and faster next state and output logic. Why not do this? Can be costly in terms of Flip-flops for FSMs with large number of states. FPGAs are Flip-flop rich, therefore one-hot state machine encoding is often a good approach. Spring 2013 EECS150 - Lec19-FSM Page 14

Even Parity Checker Circuit: One-hot encoded FSM Circuit generated through direct inspection of the STD. In General: FFs must be initialized for correct operation (only one 1) Spring 2013 EECS150 - Lec19-FSM Page 15 One-hot encoded combination lock Spring 2013 EECS150 - Lec19-FSM Page 16

General FSM form: FSM Implementation Notes All examples so far generate output based only on the present state: Commonly name Moore Machine (If output functions include both present state and input then called a Mealy Machine) Spring 2013 EECS150 - Lec19-FSM Page 17 Finite State Machines Example: Edge Detector Bit are received one at a time (one per cycle), such as: 000111010 time CLK Design a circuit that asserts its output for one cycle when the input bit stream changes from 0 to 1. IN FSM OUT Try two different solutions. Spring 2013 EECS150 - Lec19-FSM Page 18

State Transition Diagram Solution A ZERO CHANGE ONE IN PS NS OUT 0 00 00 0 1 00 01 0 0 01 00 1 1 01 11 1 0 11 00 0 1 11 11 0 Spring 2013 EECS150 - Lec19-FSM Page 19 Solution A, circuit derivation ZERO CHANGE ONE IN PS NS OUT 0 00 00 0 1 00 01 0 0 01 00 1 1 01 11 1 0 11 00 0 1 11 11 0 Spring 2013 EECS150 - Lec19-FSM Page 20

Solution B Output deps not only on PS but also on input, IN Let ZERO=0, ONE=1 IN PS NS OUT 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 NS = IN, OUT = IN PS What s the intuition about this solution? Spring 2013 EECS150 - Lec19-FSM Page 21 Edge detector timing diagrams Solution A: output follows the clock Solution B: output changes with input rising edge and is asynchronous wrt the clock. Spring 2013 EECS150 - Lec19-FSM Page 22

FSM Comparison Solution A Moore Machine output function only of PS maybe more states (why?) synchronous outputs no glitches one cycle delay full cycle of stable output Solution B Mealy Machine output function of both PS & input maybe fewer states asynchronous outputs if input glitches, so does output output immediately available output may not be stable long enough to be useful (below): If output of Mealy FSM goes through combinational logic before being registered, the CL might delay the signal and it could be missed by the clock edge. Spring 2013 EECS150 - Lec19-FSM Page 23 FSM Recap Moore Machine Mealy Machine Both machine types allow one-hot implementations. Spring 2013 EECS150 - Lec19-FSM Page 24

Final Notes on Moore versus Mealy 1. A given state machine could have both Moore and Mealy style outputs. Nothing wrong with this, but you need to be aware of the timing differences between the two types. 2. The output timing behavior of the Moore machine can be achieved in a Mealy machine by registering the Mealy output values: Spring 2013 EECS150 - Lec19-FSM Page 25 General FSM Design Process with Verilog Implementation Design Steps: 1. Specify circuit function (English) 2. Draw state transition diagram 3. Write down symbolic state transition table 4. Assign encodings (bit patterns) to symbolic states 5. Code as Verilog behavioral description! Use parameters to represent encoded states.! Use separate always blocks for register assignment and CL logic block.! Use case for CL block. Within each case section assign all outputs and next state value based on inputs. Note: For Moore style machine make outputs depent only on state not depent on inputs. Spring 2013 EECS150 - Lec19-FSM Page 26

Mealy Machine FSMs in Verilog Moore Machine always @(posedge clk) if (rst) ps <= ZERO; else ps <= ns; always @(ps in) case (ps) ZERO: if (in) begin out = 1 b1; ns = ONE; else begin out = 1 b0; ns = ZERO; ONE: if (in) begin out = 1 b0; ns = ONE; else begin out = 1 b0; ns = ZERO; default: begin out = 1 bx; ns = default; always @(posedge clk) if (rst) ps <= ZERO; else ps <= ns; always @(ps in) case (ps) ZERO: begin out = 1 b0; if (in) ns = CHANGE; else ns = ZERO; CHANGE: begin out = 1 b1; if (in) ns = ONE; else ns = ZERO; ONE: begin out = 1 b0; if (in) ns = ONE; else ns = ZERO; default: begin out = 1 bx; ns = default; Spring 2013 EECS150 - Lec19-FSM Page 27