© 2003-2008 BYU 16 FSM Page 1 ECEn 224 Finite State Machines.

Slides:



Advertisements
Similar presentations
ENGIN112 L23: Finite State Machine Design Procedure October 27, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 23 Finite State Machine.
Advertisements

Finite State Machines (FSMs)
COUNTERS Counters with Inputs Kinds of Counters Asynchronous vs
State-machine structure (Mealy)
Analysis of Clocked Sequential Circuits
TOPIC : Finite State Machine(FSM) and Flow Tables UNIT 1 : Modeling Module 1.4 : Modeling Sequential circuits.
Give qualifications of instructors: DAP
Circuits require memory to store intermediate data
Sequential Design Part II. Output A(t+1) =D A = AX + BX B(t+1) =D B = AX Y = AX + BX.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
CS 151 Digital Systems Design Lecture 25 State Reduction and Assignment.
Sequential Circuit Design
ECE 331 – Digital System Design
ECE C03 Lecture 101 Lecture 10 Finite State Machine Design Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Sequential Circuits and Finite State Machines Prof. Sin-Min Lee
Give qualifications of instructors: DAP
Contemporary Logic Design Finite State Machine Design © R.H. Katz Transparency No Chapter #8: Finite State Machine Design Finite State.
Sequential Circuit Design
Spring 2002EECS150 - Lec0-intro Page 1 EECS150 - Digital Design Lecture 9 - Finite State Machines 1 February 19, 2002 John Wawrzynek.
Spring 2002EECS150 - Lec15-seq2 Page 1 EECS150 - Digital Design Lecture 15 - Sequential Circuits II (Finite State Machines revisited) March 14, 2002 John.
Basic Register Typically, we store multi-bit items
1 Synchronous Sequential Circuit Design. 2 Sequential circuit design In sequential circuit design, we turn some description into a working circuit – We.
ENGIN112 L25: State Reduction and Assignment October 31, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 25 State Reduction and Assignment.
Sequential circuit design
Lecture 10 Topics: Sequential circuits Basic concepts Clocks
SEQUENTIAL CIRCUITS Introduction
Review for Exam 3 LC3 control State Graphs
1 COMP541 State Machines Montek Singh Feb 8, 2012.
Elevator Controller We’re hired to design a digital elevator controller for a four-floor building st try: Design a counter that counts up.
Unit 14 Derivation of State Graphs
Introduction to Sequential Logic Design Finite State-Machine Design.
Digital Logic Design Lecture # 21 University of Tehran.
1 © 2014 B. Wilkinson Modification date: Dec Sequential Logic Circuits Previously, we described the basic building blocks of sequential circuits,
Module : FSM Topic : types of FSM. Two types of FSM The instant of transition from the present to the next can be completely controlled by a clock; additionally,
Introduction to State Machine
Counters. In class excercise How to implement a “counter”, which will count as 0,3,1,4,5,7,0,3,1,…… Q2Q1Q0D2D1D
© BYU 13 COUNTERS Page 1 ECEn 224 COUNTERS Counters Transition Tables Moore Outputs Counter Timing.
DLD Lecture 26 Finite State Machine Design Procedure.
1 Finite State Machines (FSMs) Now that we understand sequential circuits, we can use them to build: Synchronous (Clocked) Finite State Machines Finite.
State Table Problem #1 An electronic lock is controlled by a keypad, which has three buttons labeled A, B, and R. The keypad is restricted such that, at.
1 ENGG 1203 Tutorial Combinational Logic (II) and Sequential Logic (I) 8 Feb Learning Objectives  Apply Karnaugh map for logic simplification  Design.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
1 COMP541 Finite State Machines - 1 Montek Singh Sep 22, 2014.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
5-1-2 Synchronous counters. Learning Objectives: At the end of this topic you will be able to: draw a block diagram showing how D-type flip-flops can.
1 COMP541 Sequential Logic – 2: Finite State Machines Montek Singh Feb 29, 2016.
Sequential Networks and Finite State Machines
© Copyright 2004, Gaetano Borriello and Randy H. Katz
COMP541 Sequential Logic – 2: Finite State Machines
Synchronous Sequential Circuit Design
Sequential circuit design
CSE 140L Discussion Finite State Machines.
Sequential circuit design
Sequential circuit design
Introduction to Sequential Circuits
CSE 370 – Winter Sequential Logic-2 - 1
ECE 352 Digital System Fundamentals
ECE 352 Digital System Fundamentals
Instructor: Alexander Stoytchev
Lecture 18 Logistics Last lecture Today HW5 due today (with extra 10%)
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
ECE 352 Digital System Fundamentals
EGR 2131 Unit 12 Synchronous Sequential Circuits
ECE 352 Digital System Fundamentals
ECE 352 Digital System Fundamentals
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
ECE 352 Digital System Fundamentals
Announcements Assignment 7 due now or tommorrow Assignment 8 posted
Finite State Machine Continued
CSE 370 – Winter Sequential Logic-2 - 1
Presentation transcript:

© BYU 16 FSM Page 1 ECEn 224 Finite State Machines

© BYU 16 FSM Page 2 ECEn 224 State Machine Concepts State, current state, next state, state registers IFL, OFL, Moore outputs, Mealy outputs Transition tables –With output don’t cares (X’s) –With input don’t cares (-’s) State graphs –And their correspondence to TT’s

© BYU 16 FSM Page 3 ECEn 224 Counters as State Machines A counter is a finite state machine –Where the state encodings are significant Q0 Q2 Q3 Q Segment Decoder

© BYU 16 FSM Page 4 ECEn 224 State Machines A state machine is a sequential circuit which progresses through a series of states in reponse to inputs –The output values are usually significant –The state encodings are usually not significant Unlike with counters

© BYU 16 FSM Page 5 ECEn 224 State Encodings In this machine, the state encodings don’t matter The output values do… … Event1 Event2 Event1 Event2Event3 Output1 Output2 Output3 Notice the alternate notation for X’ and outputs

© BYU 16 FSM Page 6 ECEn 224 A State Machine Controller for a Photocopier Finite State Machine Lamps Motors Display Buttons Timers Switches Inputs Outputs 1)FSM receives inputs from copier 2)FSM generates control outputs in response 3)States help it remember where it is in the copy process…

© BYU 16 FSM Page 7 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin’ Xin Xin’ Z S0 Because the encodings don’t matter, we will use symbolic state names What does this machine do?

© BYU 16 FSM Page 8 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 It is called a sequence detector. It has 1 input (Xin) and one output (Z) It detects the sequence on the input. When detected, output Z is asserted. Xin’ Xin Xin’

© BYU 16 FSM Page 9 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 As long as Xin=1, we stay in state S Xin’ Xin Xin’

© BYU 16 FSM Page 10 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 When Xin=0, we go to state S Xin’ Xin Xin’

© BYU 16 FSM Page 11 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 As long as Xin=0, we stay in state S Xin’ Xin Xin’

© BYU 16 FSM Page 12 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 When Xin=1, we go to state S Xin’ Xin Xin’

© BYU 16 FSM Page 13 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 If Xin=1 again, we go to state S SUCCESS! Raise the Z output Xin’ Xin Xin’

© BYU 16 FSM Page 14 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 Once we enter state S3, we never leave… Xin’ Xin Xin’

© BYU 16 FSM Page 15 ECEn 224 A Sequence Detector FSM S2 S1S3 Xin Xin’ Z S0 What if we don’t see the second Xin=1 ? Xin’ Xin Xin’

© BYU 16 FSM Page 16 ECEn 224 Implementing the Sequence Detector FSM 1.Create symbolic Transition Table 2.Assign state encoding 3.Create conventional Transition Table 4.Do standard implementation steps Symbolic TTConventional TTState Assignment S0 = 00 S1 = 01 S2 = 10 S3 = 11

© BYU 16 FSM Page 17 ECEn 224 Sequence Detector Implementation Q1 CLK Q0 CLK Q1 D Q Q0 N1 N0 Q1 Xin Q0 Xin’ Q1 Z N1 = Q1Q0 + XinQ1 + XinQ0 N0 = Xin’ + Q1 Z = Q1Q0

© BYU 16 FSM Page 18 ECEn 224 A Problem With the Sequence Detector This FSM only detects first occurrence of 011 on input… Here is a timing diagram –actual screenshot from a simulation

© BYU 16 FSM Page 19 ECEn 224 Improved Sequence Detector This starts over each time 011 is detected… S2 S1 Xin’ Xin Xin’ Z S0 S3 Xin’ Xin

© BYU 16 FSM Page 20 ECEn 224 Improved Detector Timing Diagram Z=1 any time state is S3 Looking at Xin, does it look like Z is a cycle late? How could we make Z output a cycle earlier?

© BYU 16 FSM Page 21 ECEn 224 Mealy Version of Sequence Detector S2 S1 Xin’ Xin Xin / Y Xin Xin’ S0 S3 Xin’ Xin Output is asserted during the second ‘1’ of the 011 sequence…

© BYU 16 FSM Page 22 ECEn 224 Mealy Version Timing Diagram Y Note how Mealy output follows input during state S2 Output is a cycle earlier than in Moore machine – it appears in S2 rather than in S3

© BYU 16 FSM Page 23 ECEn 224 Simplified Mealy Sequence Detector A characteristic of Mealy state machines is they often require fewer states than Moore state machines Here is simplified but basically equivalent FSM S2 S1 Xin Xin / Y Xin Xin’ S0 Xin’

© BYU 16 FSM Page 24 ECEn 224 Example FSM’s Two Car Wash Controllers

© BYU 16 FSM Page 25 ECEn 224 Basic Car Wash FSM Operation 1.Wait for a token to be inserted 2.Reset timer 3.Turn on water pump until timer expires 4.Start over This assumes existence of: –Token acceptance mechanism –Timer –Digitally-controlled water pump

© BYU 16 FSM Page 26 ECEn 224 Basic Car Wash FSM SG S_SPRAY S_TOKEN TOKEN TOKEN’ CLRT S_IDLE TDONE’ TDONE Wait for token… Clear timer… Spray car while waiting for timer to expire… SPRAY

© BYU 16 FSM Page 27 ECEn 224

© BYU 16 FSM Page 28 ECEn 224 Basic Car Wash Implementation D Q Q1 CLK Q0 CLK N1 N0 Q0 Q1 TDONE’ TOKEN Q1’ Q0’ SPRAY CLRT This is what you get from a K-map solution

© BYU 16 FSM Page 29 ECEn 224 Simplified State Graph S_SPRAY TOKEN TOKEN’ CLRT S_IDLE TDONE’ TDONE SPRAY Clear timer while waiting for a token and eliminate a state

© BYU 16 FSM Page 30 ECEn 224 Simplified Car Wash Implementation State Encoding: S_IDLE = 0, S_SPRAY = 1 NS = CS’TOKEN + CSTDONE’ CLRT = CS’ SPRAY = CS CS NS TDONE’ SPRAY D Q CS CS’ TOKEN CLRT CLK

© BYU 16 FSM Page 31 ECEn 224 A Fancy Car Wash Controller Two types of washes: –Regular wash (spray only) = 1 token –Deluxe wash (spray, soap, spray) = 2 tokens Customer: –Inserts 1 token and pushes START for Regular –Inserts 2 tokens for Deluxe

© BYU 16 FSM Page 32 ECEn 224 S3 TOKEN’ CLRT1 S0 S1 TOKEN TOKEN’ START’ TOKEN START’ S2 T1DONE’ SPRAY, CLRT2 T1DONE T2DONE’ S4 T2DONE SOAP, CLRT1 SPRAY T1DONE’ T1DONE START Straightforward process to write transition table and reduce to gates Creativity in FSM design is designing the initial state graph…

© BYU 16 FSM Page 33 ECEn 224 Enhancements to Fancy Controller

© BYU 16 FSM Page 34 ECEn 224 S3 TOKEN’ CLRT1, ACCEPTCOIN S0 S1 TOKEN TOKEN’ START’ TOKEN START’ S2 T1DONE’ SPRAY, CLRT2 T1DONE T2DONE’ S4 T2DONE SOAP, CLRT1 SPRAY T1DONE’ T1DONE START There is no way to cause coinbox to refuse tokens. Coins inserted after wash commences are presumably kept by the machine. Let’s add an ACCEPTCOIN output to control when coinbox will accept tokens… ACCEPTCOIN

© BYU 16 FSM Page 35 ECEn 224 S3 TOKEN’ CLRT1 S0 S1 TOKEN TOKEN’ START’ TOKEN START’ S2 T1DONE’ SPRAY, CLRT2 T1DONE T2DONE’ S4 T2DONE SOAP, CLRT1 SPRAY T1DONE’ T1DONE START If customer pushes START at precisely the same time as he inserts another TOKEN, the FSM will take the token, but deliver a Regular Wash. That is, START has precedence over TOKEN ACCEPTCOIN

© BYU 16 FSM Page 36 ECEn 224 S3 TOKEN’ CLRT1 S0 S1 TOKEN TOKEN’ START’ TOKEN S2 T1DONE’ SPRAY, CLRT2 T1DONE T2DONE’ S4 T2DONE SOAP, CLRT1 SPRAY T1DONE’ T1DONE STARTTOKEN’ This changes the precedence so the machine won’t steal the second token, but will give a deluxe wash in this case. ACCEPTCOIN

© BYU 16 FSM Page 37 ECEn 224 Completeness and Conflict Revisited State S1 is a typical problem spot Carefully analyze the state graph to ensure no conflicts exist and that all cases covered.

© BYU 16 FSM Page 38 ECEn 224 Resetting State Machines Ability to reset the FSM is essential for most systems Always include a reset capability –Add CLR signal to state graph –Use flip flops with reset/set inputs –Either method will work

© BYU 16 FSM Page 39 ECEn 224 Another Example An Electronic Key Lock

© BYU 16 FSM Page 40 ECEn 224 1)There are 10 keypads 0-9 2)The unlock sequence is )When a pad is pushed, the signal for that number is asserted 4)When any of the keypads are pushed a PUSHED signal is asserted 5)If you push a number out of sequence, you get an error indicator and you get to start over 6)After three wrong tries, you must wait ½ hour before trying again 7)If you entered the correct sequence, the lock unlocks. 8)Once the lock has opened, nothing happens until it is manually locked again. Inputs:Keypads signals 0-9 Outputs:INC PUSHED signalCLRCNTR ECNT3 (error count = 3)CLRTIMER WAITDONEERROR LOCKEDUNLOCK Example: Electronic Key Lock

© BYU 16 FSM Page 41 ECEn 224 ECNT3’ A F E CB D Start PUSHED7 PUSHED7’/ INC PUSHED9/ UNLOCK ERROR ECNT3/ CLRTIMER WAITDONE’ WAITDONE/ CLRCNTR PUSHED’ LOCKED’ LOCKED/ CLRCNTR PUSHED8 PUSHED8’/ INC PUSHED9’/ INC

© BYU 16 FSM Page 42 ECEn 224 Let’s create the transition table… ECNT3’ A F E CB D Start PUSHED7 PUSHED7’/ INC PUSHED9/ UNLOCK ERROR ECNT3/ CLRTIMER WAITDONE’ WAITDONE/ CLRCNTR PUSHED’ LOCKED’ LOCKED/ CLRCNTR PUSHED8 PUSHED8’/ INC PUSHED9’/ INC

© BYU 16 FSM Page 43 ECEn 224 Now let’s expand State A …

© BYU 16 FSM Page 44 ECEn 224 This is going to get ugly fast… 7 inputs + 3 state bits = 1024 rows in TT Can you do a 10-variable K-map? There is a technique called One-Hot state machines we can use instead (future lecture)… We could also use behavioral Verilog