Digital Design 2e Copyright © 2010 Frank Vahid 1 How To Capture Desired Behavior as FSM List states –Give meaningful names, show initial state –Optionally.

Slides:



Advertisements
Similar presentations
CPE 201 Digital Design Lecture 25: Register Transfer Level Design (2)
Advertisements

Lecture 23: Registers and Counters (2)
Registers and Counters
TOPIC : Finite State Machine(FSM) and Flow Tables UNIT 1 : Modeling Module 1.4 : Modeling Sequential circuits.
Give qualifications of instructors: DAP
Digital Design - Sequential Logic Design Chapter 3 - Sequential Logic Design.
Circuits require memory to store intermediate data
Sequential Circuit Analysis & Design Dr. Aiman H. El-Maleh Computer Engineering Department King Fahd University of Petroleum & Minerals Dr. Aiman H. El-Maleh.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
Digital Design Copyright © 2006 Frank Vahid 1 Digital Design Chapter 3: Sequential Logic Design -- Controllers Slides to accompany the textbook Digital.
Sequential Logic Design Process A sequential circuit that controls Boolean outputs and a specific time- ordered behavior is called a controller. StepDescription.
Register-Transfer Level (RTL) Design
ECE C03 Lecture 101 Lecture 10 Finite State Machine Design Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Chapter 9: Hardware Description Languages
1 Register-Transfer Level (RTL) Design Recall –Chapter 2: Combinational Logic Design First step: Capture behavior (using equation or truth table) Remaining.
Sequential Circuits and Finite State Machines Prof. Sin-Min Lee
Digital Design 2e Copyright © 2010 Frank Vahid 1 Digital Design Chapter 5: Register-Transfer Level (RTL) Design Slides to accompany the textbook Digital.
Chapter 3: Sequential Logic Design -- Controllers
Digital Design Copyright © 2006 Frank Vahid 1 a b F InputsOutput a'b'a' b Converting among Representations Can convert from any representation.
Contemporary Logic Design Finite State Machine Design © R.H. Katz Transparency No Chapter #8: Finite State Machine Design 8.5 Finite State Machine.
Give qualifications of instructors: DAP
Basic Register Typically, we store multi-bit items
1 Introduction Chapters 2 & 3: Introduced increasingly complex digital building blocks –Gates, multiplexors, decoders, basic registers, and controllers.
Chapter 3: Sequential Logic Design -- Controllers
Chapter 3: Sequential Logic Design -- Controllers
Controller Design Five step controller design process.
Midterm Wednesday Chapter 1-3: Number /character representation and conversion Number arithmetic CMOS logic elements Combinational logic elements and design.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 9: RTL Design.
Lecture 21 Overview Counters Sequential logic design.
Basics of State Machine Design
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.
Rabie A. Ramadan Lecture 3
CS1Q Computer Systems Lecture 11 Simon Gay. Lecture 11CS1Q Computer Systems - Simon Gay2 The D FlipFlop A 1-bit register is called a D flipflop. When.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Introduction to Sequential Logic Design Finite State-Machine Design.
EEE2243 Digital System Design Chapter 4: Verilog HDL (Sequential) by Muhazam Mustapha, January 2011.
Introduction to State Machine
Chapter 3 Digital Logic Structures. 3-2 Combinational vs. Sequential Combinational Circuit always gives the same output for a given set of inputs  ex:
DLD Lecture 26 Finite State Machine Design Procedure.
Digital Design 2e Copyright © 2010 Frank Vahid 1 Digital Design Chapter 5: Register-Transfer Level (RTL) Design Slides to accompany the textbook Digital.
Digital Design 2e Copyright © 2010 Frank Vahid 1 Digital Design Chapter 5: Register-Transfer Level (RTL) Design Slides to accompany the textbook Digital.
Chapter 3 Digital Logic Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 3-2 Transistor: Building.
Lecture 20: Sequential Logic (5)
Digital System Design using VHDL
Digital System Design using VHDL
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.
CS151 Introduction to Digital Design Chapter 5: Sequential Circuits 5-1 : Sequential Circuit Definition 5-2: Latches 1Created by: Ms.Amany AlSaleh.
EEE2243 Digital System Design Chapter 7: RTL Design by Muhazam Mustapha, March 2011.
Digital Design 2e Copyright © 2010 Frank Vahid 1 Digital Design Chapter 3: Sequential Logic Design -- Controllers Slides to accompany the textbook Digital.
Digital Design 2e Copyright © 2010 Frank Vahid 1 RTL Design Process: Create a datapath Sub-steps –HLSM data inputs/outputs  Datapath inputs/outputs. –HLSM.
Digital Design 2e Copyright © 2010 Frank Vahid 1 Digital Design Chapter 3: Sequential Logic Design -- Controllers Slides to accompany the textbook Digital.
Digital Design Copyright © 2006 Frank Vahid 1 Digital Design Chapter 3: Sequential Logic Design -- Controllers Slides to accompany the textbook Digital.
1 COMP541 Sequential Logic – 2: Finite State Machines Montek Singh Feb 29, 2016.
Digital Design - Sequential Logic Design
Lecture 4. Sequential Logic #2
Learning Outcome By the end of this chapter, students are expected to be able to: Design State Machine Write Verilog State Machine by Boolean Algebra and.
Instructor: Alexander Stoytchev
Lecture 13: Sequential Circuits, FSM
Lecture 13: Sequential Circuits, FSM
Hakim Weatherspoon CS 3410 Computer Science Cornell University
Introduction to Sequential Circuits
CSE 370 – Winter Sequential Logic-2 - 1
Sequential Circuit Analysis & Design
FLIP-FLOPS.
Learning Outcome By the end of this chapter, students are expected to understand the principle of RTL design.
ECE 352 Digital System Fundamentals
Finite State Machine Continued
Instructor: Michael Greenbaum
Presentation transcript:

Digital Design 2e Copyright © 2010 Frank Vahid 1 How To Capture Desired Behavior as FSM List states –Give meaningful names, show initial state –Optionally add some transitions if they help Create transitions –For each state, define all possible transitions leaving that state. Refine the FSM –Execute the FSM mentally and make any needed improvements.

Digital Design 2e Copyright © 2010 Frank Vahid 2 FSM Capture Example: Code Detector Unlock door (u=1) only when buttons pressed in sequence: –start, then red, blue, green, red Input from each button: s, r, g, b –Also, a indicates that some colored button pressed Capture as FSM –List states Some transitions included Start Red Green Blue s r g b a Door lock u Code detector a ab ag ar Red1 u=0 Blue u=0 Green u=0 Red2 u=1 Inputs:s,r,g,b,a Outputs: u Wait s' u=0 s Waitfor startbutton ar Start u=0 Waitfor first colored b utton a 1

Digital Design 2e Copyright © 2010 Frank Vahid 3 FSM Capture Example: Code Detector Capture as FSM –List states –Create transitions Start Red Green Blue s r g b a Door lock u Code detector a Wait Start Red1Red2GreenBlue s' a' ar' ab ag ar u=0 ar u=0 s u=1 Inputs:s,r,g,b,a Outputs: u a

Digital Design 2e Copyright © 2010 Frank Vahid 4 FSM Capture Example: Code Detector Capture as FSM –List states –Create transitions Repeat for remaining states –Refine FSM Mentally execute Works for normal sequence Check unusual cases All colored buttons pressed –Door opens! –Change conditions: other buttons NOT pressed also Start Red Green Blue s r g b a Door lock u Code detector a Wait Start Red1Red2GreenBlue s' a' ar'ab'ag'ar' a' ab ag ar a' u=0 ar u=0 s u=1 Inputs:s,r,g,b,a Outputs: u

Digital Design 2e Copyright © 2010 Frank Vahid 5 FSM Capture Example: Code Detector Start Red Green Blue s r g b a Door lock u Code detector a

Digital Design 2e Copyright © 2010 Frank Vahid 6 Controller Design Converting FSM to sequential circuit –Circuit called controller –Standard controller architecture State register stores encoding of current state Combinational logic computes outputs and next state from inputs and current state Rising clock edge takes controller to next state 3.4 General form a

Digital Design 2e Copyright © 2010 Frank Vahid 7 Controller Design Process Step Description Step 1: Capture behavior Capture the FSM Create an FSM that describes the desired behavior of the controller. 2A: Set up architecture Use state register of appropriate width and combinational logic. The logic’s inputs are the state register bits and the FSM inputs; outputs are next state bits and the FSM outputs. 2B: Encode the states Assign unique binary number (encoding) to each state. Usually use fewest bits, assign encoding to each state by counting up in binary. Step 2: Convert to circuit 2C: Fill in the truth table Translate FSM to truth table for combinational logic such that the logic will generate the outputs and next state signals for the given FSM. Ordering the inputs with state bits first makes the correspondence between the table and the FSM clear. 2D: Implement combinational logic Implement the combinational logic using any method.

Digital Design 2e Copyright © 2010 Frank Vahid 8 Controller Example: Button Press Synchronizer Want simple sequential circuit that converts button press to single cycle duration, regardless of length of time that button was actually pressed Button press synchronizer controller bibo

Digital Design 2e Copyright © 2010 Frank Vahid 9 Controller Example: Button Press Synchronizer (cont) Step 2C: Fill in truth table a Step 1: Capture FSM AB C bo=1bo=0 bi bi’ ’ ’ FSM inputs: bi; FSM outputs: bo Step 2B: Encode states bo=1bo=0 bi ’ ’ ’ FSM inputs: bi; FSM outputs: bo Step 2D: Implement combinational logic clk State register bo bi s1s0 n1 n0 Combinational logic n1 = s1’s0bi + s1s0bi n0 = s1’s0’bi bo = s1’s0bi’ + s1’s0bi = s1s0 Step 2A: Set up architecture Combinational logic n0 s1s0 n1 bobi clk State register FSM inputs FSM outputs

Digital Design 2e Copyright © 2010 Frank Vahid 10 Common Mistakes when Capturing FSMs Non-exclusive transitions a Incomplete transitions

Digital Design 2e Copyright © 2010 Frank Vahid 11 Verifying Correct Transition Properties Can verify using Boolean algebra –Only one condition true: AND of each condition pair (for transitions leaving a state) should equal 0  proves pair can never simultaneously be true –One condition true: OR of all conditions of transitions leaving a state) should equal 1  proves at least one condition must be true –Example a + a’b = a*(1+b) + a’b = a + ab + a’b = a + (a+a’)b = a + b Fails! Might not be 1 (i.e., a=0, b=0) a a * a’b = (a * a’) * b = 0 * b = 0 OK! Answer:

Digital Design 2e Copyright © 2010 Frank Vahid 12 Verifying transition properties Recall code detector FSM –We “fixed” a problem with the transition conditions –Do the transitions obey the two required transition properties? Consider transitions of state Start, and the “only one true” property Wait Start Red1Red2GreenBlue s’ a’ a’ ab ag ar a’a’ u=0 ar u=0 s u=1 a ar * a’ a’ * a(r’+b+g) ar * a(r’+b+g) = (a*a’)r = (a’*a)*(r’+b+g) = (a*a)*r*(r’+b+g) = 0*r = 0*(r’+b+g) = a*r*(r’+b+g) = 0= 0= arr’+arb+arg = 0 + arb+arg = arb + arg = ar(b+g) Fails! Means that two of Start’s transitions could be true a A: ar should be arb’g’ (likewise for ab, ag, ar)

Digital Design 2e Copyright © 2010 Frank Vahid 13 Introduction –Capture Comb. behavior: Equations, truth tables –Convert to circuit: AND + OR + NOT  Comb. Logic –Capture sequential behavior: FSMs –Convert to circuit: Register + Comb. logic  Controller –Datapath components, simple datapaths –Capture behavior: High-level state machine –Convert to circuit: Controller + Datapath  Processor –Known as “RTL” (register-transfer level) design Note: Slides with animation are denoted with a small red "a" near the animated items Transistor level Logic level Register- transfer level (RTL) Levels of digital design abstraction Higher levels Processors: Programmable (microprocessor) Custom 5.1

Digital Design 2e Copyright © 2010 Frank Vahid 14 High-Level State Machines (HLSMs) Some behaviors too complex for equations, truth tables, or FSMs Ex: Soda dispenser –c: bit input, 1 when coin deposited –a: 8-bit input having value of deposited coin –s: 8-bit input having cost of a soda –d: bit output, processor sets to 1 when total value of deposited coins equals or exceeds cost of a soda FSM can’t represent… –8-bit input/output –Storage of current total –Addition (e.g., ) as c d Soda dispenser processor tot: 25 tot: 50 a as c d Soda dispenser processor 5.2

Digital Design 2e Copyright © 2010 Frank Vahid 15 HLSMs High-level state machine (HLSM) extends FSM with: –Multi-bit input/output –Local storage –Arithmetic operations Inputs:c(bit),a (8 bits), s (8 bits) Outputs:d (bit) // '1' dispenses soda Local storage : tot (8 bits) Wait Disp Init d:='0' tot:=0 c’*(tot<s)’ c'  ( tot<s ) d:='1' c tot:=tot+a SodaDispenser 88 as c d Soda dispenser processor Conventions –Numbers: Single-bit: '0' (single quotes) Integer: 0 (no quotes) Multi-bit: “0000” (double quotes) –== for equal, := for assignment –Multi-bit outputs must be registered via local storage –// precedes a comment a Add

Digital Design 2e Copyright © 2010 Frank Vahid 16 Ex: Cycles-High Counter P = total number (in binary) of cycles that m is 1 Capture behavior as HLSM –Preg required (multibit outputs must be registered) Use to hold count P m CountHigh clk 32 S_Clr S_Wt m' S_Inc m m m' Preg := 0 Preg := Preg + 1 // Clear Preg to 0s // Wait for m == '1' // Increment Preg CountHigh Inputs:m(bit) Outputs:P (32 bits) Local storage: Preg (c) S_Clr Preg := 0 // Clear Preg to 0s CountHigh Inputs:m(bit) Outputs:P (32 bits) Local storage: Preg (a) ? S_Clr S_Wt m' m Preg := 0 // Clear Preg to 0s // Wait for m == '1' CountHigh Inputs:m(bit) Outputs:P (32 bits) Local storage: Preg (b) ? a Note: Could have designed directly using an up-counter. But, that methodology is ad hoc, and won't work for more complex examples, like the next one. a Preg

Digital Design 2e Copyright © 2010 Frank Vahid 17 Example: Laser-Based Distance Measurer Laser-based distance measurement – pulse laser, measure time T to sense reflection –Laser light travels at speed of light, 3*10 8 m/sec –Distance is thus D = (T sec * 3*10 8 m/sec) / 2 Object of interest D 2D = T sec * 3*10 8 m/sec sensor laser T (in seconds) a

Digital Design 2e Copyright © 2010 Frank Vahid 18 Example: Laser-Based Distance Measurer Inputs/outputs –B: bit input, from button, to begin measurement –L: bit output, activates laser –S: bit input, senses laser reflection –D: 16-bit output, to display computed distance sensor laser T (in seconds) Laser-based distance measurer 16 from button to display S L D B to laser from sensor

Digital Design 2e Copyright © 2010 Frank Vahid 19 Example: Laser-Based Distance Measurer Declare inputs, outputs, and local storage –Dreg required for multi-bit output Create initial state, name it S0 –Initialize laser to off (L:='0') –Initialize displayed distance to 0 (Dreg:=0) Laser- based distance measurer 16 from button to display S L D B to laser from sensor a Inputs:B (bit), S (bit) Outputs:L (bit), D (16 bits) Local storage:Dreg(16) S0 ? L:= '0' // laser off Dreg := 0 // distance is 0 DistanceMeasurer (required) (first state usually initializes the system) Recall: '0' means single bit, 0 means integer

Digital Design 2e Copyright © 2010 Frank Vahid 20 Example: Laser-Based Distance Measurer Add another state, S1, that waits for a button press –B' – stay in S1, keep waiting –B – go to a new state S2 Q: What should S2 do?A: Turn on the laser a Laser- based distance measurer 16 from button to display S L D B to laser from sensor S0 L := '0' Dreg := 0 S1? B'// button not pressed B // button pressed S0 DistanceMeasurer...

Digital Design 2e Copyright © 2010 Frank Vahid 21 Example: Laser-Based Distance Measurer Add a state S2 that turns on the laser (L:='1') Then turn off laser (L:='0') in a state S3 Q: What do next?A: Start timer, wait to sense reflection a Laser- based distance measurer 16 from button to display S L D B to laser from sensor DistanceMeasurer... S0S1 L := '0' Dreg := 0 S2 L := '1' // laser on S3 L := '0' // laser off B' B

Digital Design 2e Copyright © 2010 Frank Vahid 22 Example: Laser-Based Distance Measurer Stay in S3 until sense reflection (S) To measure time, count cycles while in S3 –To count, declare local storage Dctr –Initialize Dctr to 0 in S1. In S2 would have been O.K. too. Don't forget to initialize local storage—common mistake –Increment Dctr each cycle in S3 Laser-based distance measurer 16 from button to display S L D B to laser from sensor a S0S1S2S3 L := '0' Dreg := 0 L := '1'L := '0' Dctr := Dctr + 1 // count cycles Dctr := 0 // reset cycle count B' S' // no reflection B S//reflection ? Inputs:B (bit), S (bit)Outputs:L (bit), D (16 bits) Local storage:Dreg, Dctr (16 bits) DistanceMeasurer

Digital Design 2e Copyright © 2010 Frank Vahid 23 Example: Laser-Based Distance Measurer Once reflection detected (S), go to new state S4 –Calculate distance –Assuming clock frequency is 3x10 8, Dctr holds number of meters, so Dreg:=Dctr/2 After S4, go back to S1 to wait for button again a S0S1S2S3 L := '0' Dreg := 0 L := '1'L := '0' Dctr := Dctr+1 Dreg := Dctr/2 // calculate D Dctr := 0 B' S' BS S4 Inputs:B (bit), S (bit)Outputs:L (bit), D (16 bits)DistanceMeasurer Local storage: Dreg, Dctr (16 bits) Laser- based distance measurer 16 from button to display S L D B to laser from sensor

Digital Design 2e Copyright © 2010 Frank Vahid 24 RTL Design Process Capture behavior Convert to circuit –Need target architecture –Datapath capable of HLSM's data operations –Controller to control datapath 5.3 External data outputs External control inputs Controller... External control outputs... Datapath... DP control inputs DP control outputs... External data inputs

Digital Design 2e Copyright © 2010 Frank Vahid 25 Ctrl/DP Example for Earlier Cycles-High Counter (a) First clear Preg to 0s Then increment Preg for each clock cycle that m is 1 P Preg m CountHigh (b) S_Clr S_Wt m' S_Inc m m m' Preg := 0 Preg := Preg + 1 //Clear Preg to 0s //Wait for m=='1' //Increment Preg CountHigh Inputs:m(bit) Outputs:P (32 bits) LocStr: Preg (32 bits) Preg Q I ld clr AB S add1 P ? Preg_clr Preg_ld m DP CountHigh (c) 32 S_Clr S_Wt m' S_Inc m m m' Preg_clr = 1 Preg_ld = 0 Preg_clr = 0 Preg_ld = 0 Preg_clr = 0 Preg_ld = 1 (d) //Preg := 0 //Wait for m=1 //Preg:=Preg+1 Controller CountHigh P Preg Q I ld clr AB S add Preg_clr Preg_ld DP m 32 We created this HLSM earlier Create DP Connect with controller Derive controller a a a

Digital Design 2e Copyright © 2010 Frank Vahid 26 RTL Design Process

Digital Design 2e Copyright © 2010 Frank Vahid 27 Example: Soda Dispenser from Earlier Quick overview example. More details of each step to come. Inputs:c(bit),a (8 bits), s (8 bits) Outputs:d (bit) // '1' dispenses soda Local storage : tot (8 bits) Wait Disp Init d:='0' tot:=0 c’*(tot<s)’ c'  ( tot<s ) d:='1' c tot:=tot+a SodaDispenser Step 1 Step 2A s 8 a Datapath tot_ld tot_clr tot_lt_s ld clr tot 8-bit < adder Step 2B a a Add

Digital Design 2e Copyright © 2010 Frank Vahid 28 Example: Soda Dispenser More details of each step to come. Inputs:c(bit),a (8 bits), s (8 bits) Outputs:d (bit) // '1' dispenses soda Local storage : tot (8 bits) Wait Disp Init d:='0' tot:=0 c’*(tot<s)’ c'  ( tot<s ) d:='1' c tot:=tot+a SodaDispenser Step 1 Step 2B Step 2C Inputs:c, tot_lt_s (bit) Outputs:d, tot_ld, tot_clr (bit) Wait Disp Init d=0 tot_clr=1 c'*tot_lt_s’ c  tot_lt_s d=1 c tot_ld=1 c d tot_ld tot_clr tot_lt_s Controller Add

Digital Design 2e Copyright © 2010 Frank Vahid 29 Example: Soda Dispenser Quick overview example. More details of each step to come. Step 2C Inputs:c, tot_lt_s (bit) Outputs:d, tot_ld, tot_clr (bit) Wait Disp Init d=0 tot_clr=1 c  tot_lt_s’ c  tot_lt_s d=1 c tot_ld=1 c d tot_ld tot_clr tot_lt_s Controller Add Use controller design process to complete the design a