Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 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.

2 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

3 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

4 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

5 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

6 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

7 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.

8 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

9 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 0001 10 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

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

11 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:

12 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)

13 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

14 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., 25 + 10) as c d Soda dispenser processor 25 1 0 1 1 50 0 0 0 0 tot: 25 tot: 50 a as c d Soda dispenser processor 5.2

15 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

16 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

17 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

18 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

19 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

20 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...

21 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

22 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

23 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

24 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

25 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 000...00001 ? 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 add1 000...00001 Preg_clr Preg_ld DP m 32 We created this HLSM earlier Create DP Connect with controller Derive controller a a a

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

27 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 8 8 8 s 8 a Datapath tot_ld tot_clr tot_lt_s ld clr tot 8-bit < adder Step 2B a a Add

28 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

29 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


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

Similar presentations


Ads by Google