State & Finite State Machines

Similar documents
State & Finite State Machines

State and Finite State Machines

Numbers and Arithmetic

Numbers and Arithmetic

Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C.

CPE100: Digital Logic Design I

Topic 8: Sequential Circuits

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

CPE100: Digital Logic Design I

ALU, Latches and Flip-Flops

Synchronous Sequential Circuit Design. Digital Computer Design

6. Finite State Machines

ELCT201: DIGITAL LOGIC DESIGN

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

Chapter 7 Sequential Logic

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

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

Different encodings generate different circuits

Sequential Logic. Road Traveled So Far

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

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

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

ALU A functional unit

Example: vending machine

Finite State Machine (FSM)

CPE100: Digital Logic Design I

Timing Constraints in Sequential Designs. 63 Sources: TSR, Katz, Boriello & Vahid

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

ELEC Digital Logic Circuits Fall 2014 Sequential Circuits (Chapter 6) Finite State Machines (Ch. 7-10)

or 0101 Machine

Synchronous Sequential Logic

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

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

EECS150 - Digital Design Lecture 23 - FSMs & Counters

Clocked Sequential Circuits UNIT 13 ANALYSIS OF CLOCKED SEQUENTIAL CIRCUITS. Analysis of Clocked Sequential Circuits. Signal Tracing and Timing Charts

Lecture 10: Synchronous Sequential Circuits Design

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

CS61C : Machine Structures

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

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

EGR224 F 18 Assignment #4

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

CS61C : Machine Structures

Laboratory Exercise #11 A Simple Digital Combination Lock

Lecture 13: Sequential Circuits, FSM

Latches. October 13, 2003 Latches 1

Digital Circuits ECS 371

Memory Elements I. CS31 Pascal Van Hentenryck. CS031 Lecture 6 Page 1

Written exam with solutions IE1204/5 Digital Design Monday 23/

Generalized FSM model: Moore and Mealy

Preparation of Examination Questions and Exercises: Solutions

Lecture 3 Review on Digital Logic (Part 2)

CpE358/CS381. Switching Theory and Logical Design. Summer

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

UNIVERSITY OF WISCONSIN MADISON

EECS 270 Midterm 2 Exam Answer Key Winter 2017

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

CSE140: Digital Logic Design Registers and Counters

ELCT201: DIGITAL LOGIC DESIGN

Combinational vs. Sequential. Summary of Combinational Logic. Combinational device/circuit: any circuit built using the basic gates Expressed as

Laboratory Exercise #8 Introduction to Sequential Logic

Sequential Circuits. Circuits with state. Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T. L06-1

Sequential vs. Combinational

EECS150 - Digital Design Lecture 11 - Shifters & Counters. Register Summary

Sequential Logic Circuits

Lecture 7: Logic design. Combinational logic circuits

Models for representing sequential circuits

Lecture 13: Sequential Circuits, FSM

EECS150 - Digital Design Lecture 25 Shifters and Counters. Recap

Sequential Circuits Sequential circuits combinational circuits state gate delay

CprE 281: Digital Logic

ECE 341. Lecture # 3

PAST EXAM PAPER & MEMO N3 ABOUT THE QUESTION PAPERS:

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

P2 (10 points): Given the circuit below, answer the following questions:

CSE 140 Midterm 3 version A Tajana Simunic Rosing Spring 2015

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

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

Digital Logic Design - Chapter 5

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

Chapter 4. Sequential Logic Circuits

Synchronous Sequential Circuit Design

ELEN Electronique numérique

Design at the Register Transfer Level

Menu. Part 2 of 3701: Sequential Digital Machines Latches and Flip-Flops: >S-R latches >D latches >T latches. Comb. n. Logic. m Q.

Introduction EE 224: INTRODUCTION TO DIGITAL CIRCUITS & COMPUTER DESIGN. Lecture 6: Sequential Logic 3 Registers & Counters 5/9/2010

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

Problem Set 9 Solutions

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

Unit 7 Sequential Circuits (Flip Flop, Registers)

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

Sequential Logic. Rab Nawaz Khan Jadoon DCS. Lecturer COMSATS Lahore Pakistan. Department of Computer Science

Philadelphia University Student Name: Student Number:

Logic Design II (17.342) Spring Lecture Outline

Chapter 3 Digital Logic Structures

10/12/2016. An FSM with No Inputs Moves from State to State. ECE 120: Introduction to Computing. Eventually, the States Form a Loop

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

EECS150 - Digital Design Lecture 17 - Sequential Circuits 3 (Counters)

FSM model for sequential circuits

Clocked Synchronous State-machine Analysis

Transcription:

State & Finite State Machines Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H Appendix C.7. C.8, C.10, C.11

Big Picture: Building a Processor memory inst register file alu PC +4 +4 new pc offset target imm control extend =? cmp addr d in d out memory A Single cycle processor 2

Stateful Components Until now is combinatorial logic Output is computed when inputs are present System has no internal state Nothing computed in the present can depend on what happened in the past! Inputs N Combinational circuit M Need a way to record data Need a way to build stateful circuits Need a state holding device Outputs Finite State Machines 3

How can we store and change values? B detect enc 7LED 8 3 decode 7 (a) Ballots C How do we create vote counter machine (b) (c) A A S B R (d) All the above (e) None 4

Unstable Devices B C A 5

Bistable Devices Stable and unstable equilibria? A B A Simple Device A In stable state, A = B 0 1 1 0 B A How do we change the state? B

SR Latch R S S R 0 0 0 1 Set-Reset (S-R) Latch Stores a value and its complement 1 0 1 1

SR Latch R S S R 0 0 0 1 1 0 Set-Reset (S-R) Latch Stores a value and its complement S=1 and R=1? 1 1

SR Latch S R R S S R 0 0 0 1 0 1 1 0 1 0 Set-Reset (S-R) Latch Stores a value and its complement S=1 and R=1? 1 1??

(Unclocked) D Latch D S R R D S Data (D) Latch Easier to use than an SR latch No possibility of entering an undefined state D 0 1 When D changes, changes immediately ( after a delay of 2 Ors and 2 NOTs) Need to control when the output changes

(Unclocked) D Latch D S R R D S Data (D) Latch Easier to use than an SR latch No possibility of entering an undefined state D 0 0 1 1 1 0 When D changes, changes immediately ( after a delay of 2 Ors and 2 NOTs) Need to control when the output changes

Clocks Clock helps coordinate state changes Usually generated by an oscillating crystal Fixed period; frequency = 1/period 1 0

Edge-triggering Can design circuits to change on the rising or falling edge Trigger on rising edge = positive edge-triggered Trigger on falling edge = negative edge-triggered Inputs must be stable just before the triggering edge input clock

Level sensitive Clock Disciplines State changes when clock is high (or low) Edge triggered State changes at clock edge positive edge-triggered negative edge-triggered

D Latch with Clock D clk S R S R 0 0 0 1 0 1 1 0 1 0 1 1 forbidden clk D 0 0 0 1 1 0 0 1 1 1 1 0 15

D clk D Latch with Clock S R Level Sensitive D Latch Clock high: set/reset (according to D) Clock low: keep state (ignore D) clk D clk D 0 0 0 1 1 0 0 1 1 1 1 0 16

D clk D L Edge-Triggered D Flip-Flop X c c D L D Flip Flop Edge Triggered Data is captured when clock is high Outputs change only on falling edges clk D X 17

Registers D0 D1 D2 Register D flip flops in parallel shared clock extra clocked inputs: write_enable, reset, D3 clk 4 bit 4 reg 4 18

Clock Methodology Clock Methodology Negative edge, synchronous clk t combinational t setup t hold compute save compute save compute Signals must be stable near falling clock edge Positive edge synchronous Asynchronous, multiple clocks,... 19

Metastability and Asynchronous Inputs : What happens if select input changes near clock edge? A) Multiplexor selects input 0 B) Multiplexor selects input 1 C) Multiplexor chooses either input D) Unknown E) None above 0 1 select 1 bit reg Clk A: Google Buridan s Principle by Leslie Lamport 20

An Example: What will this circuit do? Reset Run WE R Decoder 32 bit reg +1 Clk 21

Recap We can now build interesting devices with sensors Using combinatorial logic We can also store data values In state holding elements Coupled with clocks 22

Administrivia Make sure partner in same Lab Section this week Lab2 is out Due in one week, next Monday, start early Work alone But, use your resources Lab Section, Piazza.com, Office Hours, Homework Help Session, Class notes, book, Sections, CSUGLab No Homework this week 23

Administrivia Check online syllabus/schedule http://www.cs.cornell.edu/courses/cs3410/2012sp/schedule.html Slides and Reading for lectures Office Hours Homework and Programming Assignments Prelims (in evenings): Tuesday, February 28 th Thursday, March 29 th Thursday, April 26 th Schedule is subject to change 24

Collaboration, Late, Re-grading Policies Black Board Collaboration Policy Can discuss approach together on a black board Leave and write up solution independently Do not copy solutions Late Policy Each person has a total of four slip days Max of two slip days for any individual assignment Slip days deducted first for any late assignment, cannot selectively apply slip days For projects, slip days are deducted from all partners 20% deducted per day late after slip days are exhausted Regrade policy Submit written request to lead TA, and lead TA will pick a different grader Submit another written request, lead TA will regrade directly Submit yet another written request for professor to regrade. 25

Finite State Machines

Revisit Voting Machine detect enc 7LED decode 8 3 7 Ballots How do we create a vote counter machine 27

Revisit Voting Machine D 3 32 mux LED dec 32 32 mux +1 reg reg reg... reg 32 WE WE WE WE decoder (3 to 8) detect V enc 3 28

Finite State Machines An electronic machine which has external inputs externally visible outputs internal state Output and next state depend on inputs current state 29

Abstract Model of FSM Machine is M = ( S, I, O, ) S:Finite set of states I: Finite set of inputs O: Finite set of outputs : State transition function Next state depends on present input and present state 30

Revisit Voting Machine 3 32 mux mux LED dec 32 32 +1 reg reg reg... reg 32 WE WE WE WE decoder (3 to 8) detect enc 3 31

Finite State Machine Registers Automata Model Current State Input Comb. Logic Output Next State inputs from external world outputs to external world internal state combinational logic 32

FSM Example input/output state start state up/off A down/on B down/on Legend up/off C up/off up/off D Input: up or down Output: on or off States: A, B, C, or D down/off down/off 33

FSM Example input/output state start state up/off A down/on B down/on Legend up/off Input: = up or = down Output: = on or = off States: = A, = B, = C, or = D C up/off down/off up/off D down/off 34

i 0 i 1 i 2 /o 0 o 1 o 2 S 1 S 0 FSM Example 1/1 0/0 1/1 S 1 S 0 00 01 Legend 0/0 0/0 Input: 0=up or 1=down Output: 1=on or 1=off States: 00=A, 01=B, 10=C, or 11=D 10 11 1/0 0/0 1/0 35

General Case: Mealy Machine Registers Mealy Machine Current State Input Comb. Logic Output Next State Outputs and next state depend on both current state and input 36

Moore Machine Special Case: Moore Machine Registers Current State Input Comb. Logic Comb. Logic Output Next State Outputs depend only on current state 37

Moore Machine Example input state out start out up A off down B on down Legend Input: up or down Output: on or off States: A, B, C, or D up C off up down up D on down 38

Example: Digital Door Lock Digital Door Lock Inputs: keycodes from keypad clock Outputs: unlock signal display how many keys pressed so far 39

Door Lock: Inputs Assumptions: signals are synchronized to clock Password is B A B K A B K A B Meaning 0 0 0 (no key) 1 1 0 A pressed 1 0 1 B pressed 40

D 3 D 2 D 1 D 0 4 LED dec 8 U Door Lock: Outputs Assumptions: High pulse on U unlocks door 41

Door Lock: Simplified State Diagram B G1 A G2 B G3 1 2 3, U else else any Idle 0 else B1 else B2 1 2 else any B3 3 42

Door Lock: Simplified State Diagram B G1 A G2 B G3 1 2 3, U else else any Idle 0 else B1 else B2 1 2 else 43

Door Lock: Simplified State Diagram G1 A G2 B G3 1 2 3, U Idle 0 B else else else else Cur. State any Output B1 else B2 1 2 44

Door Lock: Simplified State Diagram G1 A G2 B G3 1 2 3, U Idle 0 B else else B1 else B2 1 2 else else Cur. any Output State Idle 0 G1 1 G2 2 G3 3, U B1 1 B2 2 45

Door Lock: Simplified State Diagram B G1 A G2 B G3 1 2 3, U else Cur. State Input Next State else any Idle 0 else B1 else B2 1 2 else 46

Door Lock: Simplified State Diagram Idle 0 B else G1 A G2 B G3 1 2 3, U else B1 else B2 1 2 else Cur. State Input Next State else Idle Idle Idle B G1 Idle A B1 any G1 G1 G1 A G2 G1 B B2 G2 B2 G2 B G3 G2 A Idle G3 any Idle B1 B1 B1 K B2 B2 B2 B2 K Idle 47

State Table Encoding SCur. 2 SState 1 S 0 D 3 DOutput 2 D 1 D 0 U 0 Idle 0 0 0 0 0 0 0 0 0 G1 0 1 0 0 1 0 1 0 0 G2 1 0 0 0 2 1 0 0 0 G3 1 1 0 0 3, 1 U1 1 1 B1 0 0 0 0 1 0 1 0 1 B2 0 1 0 0 2 1 0 0 State S 2 S 1 S 0 0 Idle 0U0 0 (no key) 0 0 1 G1 1 0 A 0 pressed 0 1 1 G2 0 1 B 0 pressed 1 0 G3 0 1 1 D 3 D 2 KD 1 A 4 8 D 0 B Meaning dec R P B1 1 0 0 B2 1 0 1 Cur. S 2 SState 1 S 0 K Input A B S Next 2 S State 1 S 0 0 Idle 0 0 0 0 0 0 Idle 0 0 0 Idle 0 0 1 B 0 1 0 G1 0 1 0 Idle 0 0 1 A 1 0 1 B1 0 0 0 G1 0 1 0 0 0 0 G1 0 1 0 G1 0 1 1 A 1 0 0 G2 1 0 0 G1 0 1 1 B 0 1 1 B2 0 1 0 G2 1 0 0 0 0 0 B2 1 0 0 G2 1 0 1 B 0 1 0 G3 1 1 0 G2 1 0 1 A 1 0 0 Idle 0 0 0 G3 1 1 x any x x 0 Idle 0 0 1 B1 0 0 0 0 0 1 B1 0 0 1 B1 0 0 1 Kx x 1 B2 0 1 1 B2 0 1 0 0 0 1 B2 0 1 1 B2 0 1 1 Kx x 0 Idle 0 0 48

Door Lock: Implementation 3bit Reg S 2 0 D 3 0 U 4 dec clk S 2 0 A B C S 2 0 Strategy: (1) Draw a state diagram (e.g. Moore Machine) (2) Write output and next state tables (3) Encode states, inputs, and outputs as bits (4) Determine logic equations for next state and outputs 49

Summary We can now build interesting devices with sensors Using combinational logic We can also store data values Stateful circuit elements (D Flip Flops, Registers, ) Clock to synchronize state changes But be wary of asynchronous (un clocked) inputs State Machines or Ad Hoc Circuits 50