Finite State Machines CS 64: Computer Organization and Design Logic Lecture #15 Fall 2018

Similar documents
ENGG 1203 Tutorial. Solution (b) Solution (a) Simplification using K-map. Combinational Logic (II) and Sequential Logic (I) 8 Feb Learning Objectives

Combinatorial Logic Design Multiplexers and ALUs CS 64: Computer Organization and Design Logic Lecture #13

EECS Components and Design Techniques for Digital Systems. FSMs 9/11/2007

Finite State Machine (FSM)

Sequential Logic. Handouts: Lecture Slides Spring /27/01. L06 Sequential Logic 1

State and Finite State Machines

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

Lecture 10: Synchronous Sequential Circuits Design

State Graphs FSMs. Page 1

Synchronous Sequential Circuit Design. Digital Computer Design

FSM model for sequential circuits

Exam for Physics 4051, October 31, 2008

Synchronous Sequential Circuit Design

Lecture 14 Finite state machines

Last lecture Counter design Finite state machine started vending machine example. Today Continue on the vending machine example Moore/Mealy machines

Karnaugh Maps for Combinatorial Logic CS 64: Computer Organization and Design Logic Lecture #12

CS221: Digital Design. Dr. A. Sahu. Indian Institute of Technology Guwahati

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

Parity Checker Example. EECS150 - Digital Design Lecture 9 - Finite State Machines 1. Formal Design Process. Formal Design Process

Sequential Logic (3.1 and is a long difficult section you really should read!)

CSE140: Components and Design Techniques for Digital Systems. Midterm Information. Instructor: Mohsen Imani. Sources: TSR, Katz, Boriello & Vahid

Models for representing sequential circuits

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 7 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

EGR224 F 18 Assignment #4

Sequential Logic. Road Traveled So Far

FSM Optimization. Counter Logic Diagram Q1 Q2 Q3. Counter Implementation using RS FF 10/13/2015

6. Finite State Machines

Lecture 7: Logic design. Combinational logic circuits

Ch 7. Finite State Machines. VII - Finite State Machines Contemporary Logic Design 1

Lecture 8: Sequential Networks and Finite State Machines

From Sequential Circuits to Real Computers

Philadelphia University Student Name: Student Number:

CPE100: Digital Logic Design I

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 9 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

Synchronous Sequential Circuit Design. Dr. Ehab A. H. AL-Hialy Page 1

University of Toronto Faculty of Applied Science and Engineering Edward S. Rogers Sr. Department of Electrical and Computer Engineering

Fundamentals of Digital Design

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

14.1. Unit 14. State Machine Design

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 Solutions

CS61C : Machine Structures

Different encodings generate different circuits

State & Finite State Machines

Finite State Machine. By : Ali Mustafa

Total time is: 1 setup, 2 AND, 3 XOR, 1 delay = (1*1) + (2*2) + (3*3) + (1*1) = 15ns

CS61c: Representations of Combinational Logic Circuits

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING BENG (HONS) ELECTRICAL & ELECTRONICS ENGINEERING EXAMINATION SEMESTER /2017

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3

Problem Set 9 Solutions

Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec09 Counters Outline.

Topic 8: Sequential Circuits

Philadelphia University Student Name: Student Number:

ENGG 1203 Tutorial _03 Laboratory 3 Build a ball counter. Lab 3. Lab 3 Gate Timing. Lab 3 Steps in designing a State Machine. Timing diagram of a DFF

From Sequential Circuits to Real Computers

State & Finite State Machines

Chapter 3. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 3 <1>

Generalized FSM model: Moore and Mealy

14:332:231 DIGITAL LOGIC DESIGN

Digital Logic and Design (Course Code: EE222) Lecture 19: Sequential Circuits Contd..

CS61C : Machine Structures

Lab #10: Design of Finite State Machines

Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec 09 Counters Outline.

Example: vending machine

Sequential Circuit Design

Synchronous Logic. These must be the slings and arrows of outrageous fortune. Comp 411 Fall /18/06. L14 Synchronous Logic 1

Latches. October 13, 2003 Latches 1

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

Unit 8: Sequ. ential Circuits

Adders allow computers to add numbers 2-bit ripple-carry adder

CE1911 LECTURE FSM DESIGN PRACTICE DAY 1

Synchronous Sequential Logic

Lab 3 Revisited. Zener diodes IAP 2008 Lecture 4 1

CPE100: Digital Logic Design I

Sequential Synchronous Circuit Analysis

Review for Final Exam

Appendix B. Review of Digital Logic. Baback Izadi Division of Engineering Programs

Department of Electrical and Computer Engineering University of Wisconsin Madison. Fall Final Examination

Logical design of digital systems

CS/COE1541: Introduction to Computer Architecture. Logic Design Review. Sangyeun Cho. Computer Science Department University of Pittsburgh

ALU, Latches and Flip-Flops

EECS150 - Digital Design Lecture 23 - FSMs & Counters

UNIVERSITY OF WISCONSIN MADISON

Topic 8: Sequential Circuits. Bistable Devices. S-R Latches. Consider the following element. Readings : Patterson & Hennesy, Appendix B.4 - B.

The Design Procedure. Output Equation Determination - Derive output equations from the state table

ELCT201: DIGITAL LOGIC DESIGN

Appendix A: Digital Logic. Principles of Computer Architecture. Principles of Computer Architecture by M. Murdocca and V. Heuring

EEE2135 Digital Logic Design

Lecture 14: State Tables, Diagrams, Latches, and Flip Flop

Chapter 3. Chapter 3 :: Topics. Introduction. Sequential Circuits

Floating Point Representation and Digital Logic. Lecture 11 CS301

ELCT201: DIGITAL LOGIC DESIGN

Review for B33DV2-Digital Design. Digital Design

Sequential Logic Design: Controllers

Sequential Logic Circuits

5. Sequential Logic x Computation Structures Part 1 Digital Circuits. Copyright 2015 MIT EECS

COE 202: Digital Logic Design Sequential Circuits Part 3. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Boolean Algebra and Digital Logic 2009, University of Colombo School of Computing

ECE380 Digital Logic. Synchronous sequential circuits

Mealy & Moore Machines

Introduction to Digital Logic

Transcription:

Finite State Machines CS 64: Computer Organization and Design Logic Lecture #15 Fall 2018 Ziad Matni, Ph.D. Dept. of Computer Science, UCSB

Administrative The Last 2 Weeks of CS 64: Date L # Topic Lab Lab Due 11/26 13 Combinatorial Logic, Sequential Logic 11/28 14 Sequential Logic 8 (CL+SL) Sun. 12/2 12/3 15 FSM 9 (FSM) Fri. 12/7 12/5 16 FSM, CS Ethics & Impact 10 (Ethics) Fri. 12/7 12/3/18 Matni, CS64, Fa18 2

Administrative New Lab #9 issued tomorrow Due Friday Practice Exam will be online v. soon Look for Piazza announcement Your final exam is on Wednesday, Dec. 12 th at 8:00 AM In this classroom Be ON TIME! Arrive 10 minutes EARLY! 12/3/18 Matni, CS64, Fa18 3

Lecture Outline Finite State Machines Moore vs. Mealy types State Diagrams Figuring out a circuit for a FSM 12/3/18 Matni, CS64, Sp18 4

If a combinational logic circuit is an implementation of a Boolean function, then a sequential logic circuit can be considered an implementation of a finite state machine. 12/3/18 Matni, CS64, Fa18 5

Finite State Machines (FSM) An abstract machine that can be in exactly one of a finite number of states at any given time It s a very simple model of a computational machine, unlike Pushdown Automatons and Turing Machines You ll discover these in other CS upper-div classes 12/3/18 Matni, CS64, Fa18 6

Finite State Machines (FSM) The FSM can change from one state to another in response to some external inputs The change from one state to another is called a transition. Starting point STATE A Transition A->B Transition B->A STATE B An FSM is defined by a list of its states, its initial state, and the conditions for each transition. 12/3/18 Matni, CS64, Fa18 7

Example of a Simple FSM: The Turnstile initial state State Transition Table Current State Input Next State Output Locked Coin Unlocked Unlocks the turnstile so that the customer can push through. Locked Push Locked Nothing you re locked! J Unlocked Coin Unlocked Nothing you just wasted a coin! J Unlocked Push Locked When the customer has pushed through, locks the turnstile. 12/3/18 Matni, CS64, Fa18 8 Source: Wikipedia

Example of a Simple FSM: The Turnstile This is called a state diagram initial state State Transition Table Current State à Input Next State Output Locked Coin Unlocked Unlocks the turnstile so that the customer can push through. Locked Push Locked Nothing you re locked! J Unlocked Coin Unlocked Nothing you just wasted a coin! J Unlocked Push Locked When the customer has pushed through, locks the turnstile. 12/3/18 Matni, CS64, Fa18 9 Source: Wikipedia

General Form of FSMs 12/3/18 Matni, CS64, Fa18 10

Example Output-to-input feedback Combinatorial logic A CLK Clock signal Qo State register Q* Q* = Q O.A On the next rising edge of the clock, the output of the D-FF Q (Q*) will become the previous value of Q (Q O ) AND the value of input A 12/3/18 Matni, CS64, Fa18 11

FSM Types There are 2 types/models of FSMs: Moore machine Output is function of present state only Mealy machine Output is function of present state and present input 12/3/18 Matni, CS64, Fa18 12

Moore Machine Output is function of present state only 12/3/18 Matni, CS64, Fa18 13

Example of a Moore Machine (with 1 state) Output is function of present state only A Q Z CLK Z = (Q* + B) = (Q O.A + B) On the next rising edge of the clock, the output of the entire circuit (Z) will become (the previous value of Q (Q O ) AND the value of input A) NOR B NOTE: CLK is NOWHERE IN THE EQUATION!!! B 12/3/18 Matni, CS64, Fa18 14

Mealy Machine Output is function of present state and present input 12/3/18 Matni, CS64, Fa18 15

Example of a Mealy Machine (with 1 state) Output is function of present state and present input A CLK Q Z B Z = (Q* + A + B) = (Q O XOR A) + (A + B) On the next rising edge of the clock, the output of the entire circuit (Z) will become etc 12/3/18 Matni, CS64, Fa18 16

Example of a Moore Machine WASHER_DRYER Let s build a sequential logic FSM that acts as a controller to a simplistic washer/dryer machine This machine takes in various inputs in its operation (we ll only focus on the following sensor-based ones): Coin is in (vs it isn t in) Soap is present (vs it s used up) Clothes are still wet (vs clothes are dry) This machine also issues 1 output while running: Done indicator 12/3/18 Matni, CS64, Fa18 17

Machine Design We want this machine to have 4 distinct states that we go from one to the next in this sequence: 1. Initial State Where we are when we are waiting to start the wash 2. Wash Where we wash with soap and water 3. Dry Where we dry the clothes 4. Done 12/3/18 Matni, CS64, Fa18 18

Combining the Inputs Coin is in (vs it isn t in) Soap is no longer detected (vs it s still there) Clothes are now dry (vs clothes are still wet) Let s create a variable called GTNS (i.e. Go To Next State) GTNS is 1 if any of the following is true: Coin is in Soap is no longer detected Clothes are now dry I assume that these 3 inputs to be mutually exclusive 12/3/18 Matni, CS64, Fa18 19

What s Going to Happen? 1/2 Coin is in (vs it isn t in) Soap is no longer detected (vs it s still there) Clothes are now dry (vs clothes are still wet) We start at an Initial state whenever we start up the machine Let s also assume this stage is when you d put in the soap and clothes Once input Coin is in is 1, GTNS is now 1 This event triggers leaving the current state to go to the next state This is followed by the next state, Wash Coin inserted is now 0 at this point (so GTNS goes back to 0) While soap is still present, GTNS goes back to 0 When the input Soap is no longer present goes to 1, GTNS goes to 1 This event triggers leaving the current state to go to the next state 12/3/18 Matni, CS64, Fa18 20

What s Going to Happen? 2/2 Coin is in (vs it isn t in) Soap is no longer detected (vs it s still there) Clothes are now dry (vs clothes are still wet) This is followed by the next state, Dry This new state sets an output that triggers a timer The input Soap is no longer present goes to 0, so GTNS is 0 also While the input Clothes are now dry is 0, GTNS remains at 0 too When the input Clothes are now dry is 1, GTNS changes to 1 This event triggers leaving the current state to go to the next state This is followed by the next and last state, Done When you re here, you go back to the initial state No inputs to consider: you do move this regardless 12/3/18 Matni, CS64, Fa18 21

State Diagram for Washer-Dryer Machine inputs outputs transition state GTNS = COIN_IN + NO_SOAP + CLTHS_DRY GTNS GTNS GTNS Wash GTNS Dry Initial State DONE = 0 1 Done DONE = 1 12/3/18 Matni, CS64, Fa18 22

Unconditional Transitions Sometimes the transition is unconditional Does not depend on any input it just happens We then diagram this as a 1 (for always does this ) K = 0 State 1 1 K = 1 State 0 K = 1 State 2 K = 0 12/3/18 23

Representing The States How many bits do I need to represent all the states in this Washer-Dryer Machine? There are 4 unique states (including init ) So, 2 bits If my state machine will be built using a memory circuit (most likely, a D-FF), how many of these should I have? 2 bits = 2 D-FFs There is another scheme to do this called One Hot Method. More on this later State S1 S0 Initial 0 0 Wash 0 1 Rinse 1 0 Dry 1 1 12/3/18 Matni, CS64, Fa18 24

Example of a Moore Machine 2 DETECT_1101 Let s build a sequential logic FSM that always detects a specific serial sequence of bits: 1101 We ll start at an Initial state (S0) We ll first look for a 1. We ll call that State 1 (S1) Don t go to S1 if all we find is a 0! We ll then keep looking for another 1. We ll call that State 11 (S2) 12/3/18 Matni, CS64, Fa18 25

Example of a Moore Machine 2 DETECT_1101 Then a 0. We ll call that State 110 (S3) Then another 1. We ll call that State 1101 (S4) this will also output a FOUND signal We will always be detecting 1101 (it doesn t end) So, as SOON as S4 is done, we keep looking for 1s or 0s Example: if the input stream is 111101110101101000011111011011 we detect 1101 at ñ ñ ñ ñ ñ 12/3/18 Matni, CS64, Fa18 26

State Diagram 2 Input = 1 Input = 0 Input = 1 1 11 S1 S2 Initial State S0 Input = 0 Input = 0 1101 S4 Input = 1 110 S3 FOUND = 1 12/3/18 Matni, CS64, Fa18 27

Representing The States How many bits do I need to represent all the states in this Detect 1101 Machine? State There are 5 unique states Initial 0 0 0 (including init ) Found 1 0 0 1 So, 3 bits Found 11 0 1 0 How many D-FFs should I have to build this machine? 3 bits = 3 D-FFs B2 B1 B0 Found 110 0 1 1 Found 1101 1 0 0 12/3/18 Matni, CS64, Fa18 28

Designing the Circuit for the FSM 1. We start with a T.T Also called a State Transition Table 2. Make K-Maps and simplify Usually give your answer as a sum-of-products form 3. Design the circuit Have to use D-FFs to represent the state bits 12/3/18 Matni, CS64, Fa18 29

1. The Truth Table (The State Transition Table) CURRENT STATE INPUT(S) NEXT STATE State B2 B1 B0 I B2* B1* B0* FOUND Initial 0 0 0 0 0 0 0 0 1 0 0 1 0 Found 1 0 0 1 0 0 0 0 0 1 0 1 0 0 Found 11 0 1 0 0 0 1 1 0 1 0 1 0 0 Found 110 0 1 1 0 0 0 0 0 1 1 0 0 0 Found 1101 1 0 0 0 0 0 0 1 1 0 1 0 1 OUTPUT(S) 12/3/18 Matni, CS64, Fa18 30

2. K-Maps for B2* and B1* You need to do this for all 3 state outputs B2* =!B2.B1.B0.I No further simplification B1* =!B2.!B1.B0.I + B2.!B1.!B0.I +!B2.B1.!B0 B2.B1 B0.I 00 01 00 01 11 10 11 1 10 B2.B1 B0.I 00 01 11 10 00 1 01 1 1 11 1 10 12/3/18 Matni, CS64, Fa18 31

2. K-Map for B0* Output FOUND B0* =!B2.!B1.!B0.I +!B2.B1.!B0.!I B2.B1 B0.I 00 01 11 10 00 1 01 1 11 10 FOUND = B2.!B1.!B0 Note that FOUND does not need a K-Map. It is always 1 (i.e. True) when we are in state S4 (i.e. when B2=1, B1=0, B0=0) 12/3/18 Matni, CS64, Fa18 32

3. Design the Circuit Note that CLK is the input to ALL the D-FFs clock inputs. This is a synchronous machine. Note the use of labels (example: B2 or B0-bar) instead of routing wires all over the place! Note that I issued both Bn and Bnbar from all the D-FFs it makes it easier with the labeling and you won t have to use NOT gates! Note that the sole output (FOUND) does not need a D-FF because it is NOT A STATE BIT! 12/3/18 Matni, CS64, Fa18 33

12/3/18 Matni, CS64, Fa18 34