9/13/07EECS150 F07 Culler Lec 6 1 EECS 150 - Components and Design Techniques for Digital Systems Lec 06 – Using FSMs 9-13-07 David Culler Electrical.

Slides:



Advertisements
Similar presentations
Lecture 15 Finite State Machine Implementation
Advertisements

Finite State Machines (FSMs)
Table 7.1 Verilog Operators.
Give qualifications of instructors: DAP
Finite State Machine (FSM)  When the sequence of actions in your design depend on the state of sequential elements, a finite state machine (FSM) can be.
CSE Spring Verilog for Sequential Systems - 1 Today: Verilog and Sequential Logic zFlip-flops yrepresentation of clocks - timing of state.
Spring 20067W. Rhett Davis with minor modifications by Dean Brock ECE 406 at UNASlide 1 ECE 406 Design of Complex Digital Systems Lecture 10: 9: State.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
CS 151 Digital Systems Design Lecture 25 State Reduction and Assignment.
FSMs 1 Sequential logic implementation  Sequential circuits  primitive sequential elements  combinational logic  Models for representing sequential.
Give qualifications of instructors: DAP
1 EECS Components and Design Techniques for Digital Systems Lec 21 – RTL Design Optimization 11/16/2004 David Culler Electrical Engineering and Computer.
Contemporary Logic Design Finite State Machine Design © R.H. Katz Transparency No Chapter #8: Finite State Machine Design Finite State.
Spring 2002EECS150 - Lec0-intro Page 1 EECS150 - Digital Design Lecture 9 - Finite State Machines 1 February 19, 2002 John Wawrzynek.
David Culler Electrical Engineering and Computer Sciences
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Verilog 2 (Sequential.
ENEE 408C Lab Capstone Project: Digital System Design Fall 2005 Sequential Circuit Design.
From Design to Verilog EECS150 Fall Lecture #4
VII - Finite State Machines © Copyright 2004, Gaetano Borriello and Randy H. Katz 1 Finite State Machines Sequential circuits  primitive sequential elements.
Advanced Verilog EECS 270 v10/23/06.
CS61CL Machine Structures Lec 8 – State and Register Transfers David Culler Electrical Engineering and Computer Sciences University of California, Berkeley.
ENGIN112 L25: State Reduction and Assignment October 31, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 25 State Reduction and Assignment.
CS61C L15 Synchronous Digital Systems (1) Beamer, Summer 2007 © UCB Scott Beamer, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
Lecture 21 Overview Counters Sequential logic design.
EECS Components and Design Techniques for Digital Systems FSMs 9/11/2007 Sarah Bird Electrical Engineering and Computer Sciences University of California,
Overview Logistics Last lecture Today HW5 due today
Sequential Logic in Verilog
1 COMP541 State Machines Montek Singh Feb 8, 2012.
Registers CPE 49 RMUTI KOTAT.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
1 CSE370, Lecture 19 Lecture 19 u Logistics n Lab 8 this week to be done in pairs íFind a partner before your lab period íOtherwise you will have to wait.
1 CSE370, Lecture 15 Lecture 15 u Logistics n HW5 due this Friday n HW6 out today, due Friday Feb 20 n I will be away Friday, so no office hour n Bruce.
DLD Lecture 26 Finite State Machine Design Procedure.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.
1 COMP541 State Machines – 2 Registers and Counters Montek Singh Feb 11, 2010.
1 COMP541 Finite State Machines - 1 Montek Singh Sep 22, 2014.
2/3/2006EECS150 Lab Lecture #31 Implementation of FSMs EECS150 Spring 2006 – Lab Lecture #3 Guang Yang Greg Gibeling.
2/2/07EECS150 Lab Lecture #31 Verilog Synthesis & FSMs EECS150 Spring 2007 – Lab Lecture #3 Brent Mochizuki Greg Gibeling.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Chapter 11: System Design.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Design of Datapath Controllers Speaker: Shao-Wei Feng Adviser:
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 9: State Machines & Reset Behavior Spring.
REGISTER TRANSFER LANGUAGE (RTL) INTRODUCTION TO REGISTER Registers1.
Chapter 3 Boolean Algebra and Digital Logic T103: Computer architecture, logic and information processing.
1 Modeling of Finite State Machines Debdeep Mukhopadhyay Associate Professor Dept of Computer Science and Engineering NYU Shanghai and IIT Kharagpur.
EMT 351/4 DIGITAL IC DESIGN Verilog Behavioral Modeling  Finite State Machine -Moore & Mealy Machine -State Encoding Techniques.
Pusat Pengajian Kejuruteraan Mikroelektronik EMT 351/4 DIGITAL IC DESIGN Verilog Behavioural Modeling (Part 4) Week #
1 COMP541 Sequential Logic – 2: Finite State Machines Montek Singh Feb 29, 2016.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Controller Implementation
Figure 8.1. The general form of a sequential circuit.
Chapter #6: Sequential Logic Design
© Copyright 2004, Gaetano Borriello and Randy H. Katz
Supplement on Verilog Sequential circuit examples: FSM
Typical Timing Specifications
David Culler Electrical Engineering and Computer Sciences
CSE 370 – Winter Sequential Logic-2 - 1
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
EECS Components and Design Techniques for Digital Systems Lec 08 – Using, Modeling and Implementing FSMs David Culler Electrical Engineering.
CSE 370 – Winter Sequential Logic-2 - 1
332:437 Lecture 8 Verilog and Finite State Machines
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
COE 202 Introduction to Verilog
Supplement on Verilog Sequential circuit examples: FSM
The Verilog Hardware Description Language
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
Verilog Synthesis & FSMs
332:437 Lecture 8 Verilog and Finite State Machines
Presentation transcript:

9/13/07EECS150 F07 Culler Lec 6 1 EECS Components and Design Techniques for Digital Systems Lec 06 – Using FSMs David Culler Electrical Engineering and Computer Sciences University of California, Berkeley

9/13/07EECS150 F07 Culler Lec 6 2 Outline Review FSMs Mapping to FPGAs Typical uses of FSMs Synchronous Seq. Circuits – safe composition Timing FSMs in verilog

9/13/07EECS150 F07 Culler Lec 6 3 Review: Typical Controller: state Combinational Logic state state(t+1) = F ( state(t) ) stateNext state i2i1i0o2o1o Example: Gray Code Sequence

9/13/07EECS150 F07 Culler Lec 6 4 Typical Controller: state + output Combinational Logic state state(t+1) = F ( state(t) ) stateNext state i2i1i0o2o1o Output (t) = G ( state(t) ) odd 000/0 001/1011/0 010/1 110/0 111/1101/0 100/1

9/13/07EECS150 F07 Culler Lec 6 5 Typical Controller: state + output + input Combinational Logic state state(t+1) = F ( state(t), input (t) ) stateNext state i2i1i0o2o1o Output (t) = G ( state(t) ) 0 1 x x x clr 000/0 001/1011/0 010/1 110/0 111/1101/0 100/1 Input odd clr=1 clr=0 clr=?

9/13/07EECS150 F07 Culler Lec 6 6 Review: Two Kinds of FSMs Moore Machine vs Mealy Machine Combinational Logic state state(t+1) = F ( state(t), input) Output (t) = G ( state(t), Input ) Input state state(t+1) = F ( state(t), input(t)) Output (t) = G ( state(t)) Input State / out Input State Input / Out

9/13/07EECS150 F07 Culler Lec 6 7 In = 0 In = 1 In = 0In = Review: Finite State Machine Representations States: determined by possible values in sequential storage elements Transitions: change of state Clock: controls when state can change by controlling storage elements Sequential Logic –Sequences through a series of states –Based on sequence of values on input signals –Clock period defines elements of sequence

9/13/07EECS150 F07 Culler Lec 6 8 Review: Formal Design Process Circuit Diagram: –XOR gate for ns calculation –DFF to hold present state –no logic needed for output Logic equations from table: OUT = PS NS = PS xor IN ns ps Review of Design Steps: 1. Circuit functional specification 2. State Transition Diagram 3. Symbolic State Transition Table 4. Encoded State Transition Table 5. Derive Logic Equations 6. Circuit Diagram FFs for state CL for NS and OUT Take this seriously!

9/13/07EECS150 F07 Culler Lec 6 9 Formal Design Process “State Transition Diagram” –circuit is in one of two states. –transition on each cycle with each new input, over exactly one arc (edge). –Output depends on which state the circuit is in.

9/13/07EECS150 F07 Culler Lec 6 10 Formal Design Process State Transition Table: Invent a code to represent states: Let 0 = EVEN state, 1 = ODD state present next state OUT IN state EVEN 0 0 EVEN EVEN 0 1 ODD ODD 1 0 ODD ODD 1 1 EVEN present state (ps) OUT IN next state (ns) Derive logic equations from table (how?): OUT = PS NS = PS xor IN

9/13/07EECS150 F07 Culler Lec 6 11 Review: What’s an FSM? Next state is function of state and input Moore Machine: output is a function of the state Mealy Machine: output is a function of state and input Often PLAs State / output inputA inputB State inputA/outputA inputB/outputB Which is which?

9/13/07EECS150 F07 Culler Lec 6 12 How to quickly implement the State Transition Diagram?

9/13/07EECS150 F07 Culler Lec 6 13 One Answer: Xilinx 4000 CLB

9/13/07EECS150 F07 Culler Lec 6 14 Two 4-input functions, registered output

9/13/07EECS150 F07 Culler Lec input function, combinational output

9/13/07EECS150 F07 Culler Lec 6 16 Recall: Parallel to Serial Converter //Parallel to Serial converter module ParToSer(LD, X, out, CLK); input [3:0] X; inputLD, CLK; outputout; regout; reg [3:0]Q; assign out =Q[0]; (posedge CLK) begin if (LD) Q <=X; else Q <={1’b0,Q[3:1]}; end endmodule // ParToSer One common use of FSMs is in adapters from one subsystem to another. different data widths different bit rates different protocols, …

9/13/07EECS150 F07 Culler Lec 6 17 Example: Byte-bit stream Byte FIFO pop Serial link Shift register controller LD bit 0/pop bit 1bit 2bit 3bit 4bit 5bit 6 bit 7 / LD init / LD

9/13/07EECS150 F07 Culler Lec 6 18 Byte-bit stream with Rate Matching How would you implement this FSM? Byte FIFO pop Serial link Shift register controller LD bit 0/pop bit 1bit 2bit 3bit 4bit 5bit 6 bit 7 / LD init / LD rdy bit 0’ ~rdy rdy ~rdy rdy ~rdy rdy ~rdy rdy ~rdy rdy ~rdy rdy ~rdy rdy ~rdy rdy

9/13/07EECS150 F07 Culler Lec 6 19 Another example: bus protocols A bus is: –shared communication link –single set of wires used to connect multiple subsystems A Bus is also a fundamental tool for composing large, complex systems (more later in the term) –systematic means of abstraction Control Datapath Memory Processor Input Output

9/13/07EECS150 F07 Culler Lec 6 20 Example: Pentium System Organization Processor/Memory Bus PCI Bus I/O Busses

9/13/07EECS150 F07 Culler Lec 6 21 Arbitration for the bus… Central arbitration shown here –Used in essentially all processor-memory busses and in high- speed I/O busses Bus Arbiter Device 1 Device N Device 2 Grant Req

9/13/07EECS150 F07 Culler Lec 6 22 Simple Synchronous Protocol Even memory busses are more complex than this –memory (slave) may take time to respond –it need to control data rate BReq BG Rd+Addr CMD Address Data1Data2 Data I want the bus nope You got it I still want the bus Mem grabs addr Proc grabs data I’m done after this

9/13/07EECS150 F07 Culler Lec 6 23 Processor Side of Protocol - sketch Memory waits? Additional outputs? Memory side? Idle ~BR Request bus BR Address BR,RD, addr_enable proc read BG Data 1 BR, MDR_enable Data 2 ~BR, MDR_enable ~BG

9/13/07EECS150 F07 Culler Lec 6 24 Simple Synchronous Protocol (cont) BReq BG Rd+Addr CMD Address Data1Data2 Data I want the bus nope You got it I still want the bus Mem grabs addr Proc grabs data I’m done after this idle req w-addr r-data1 r-data2 idle

9/13/07EECS150 F07 Culler Lec 6 25 Announcements Reading (slight change in ordering) HW 2 due tomorrow HW 3 will go out today Lab lecture on Verilog synthesis Next week feedback survey Input on discussion sections Technology in the News –iPhone “unlocked” –iPhone price drops by $200

9/13/07EECS150 F07 Culler Lec 6 26 Fundamental Design Principle Divide circuit into combinational logic and state Localize feedback loops and make it easy to break cycles Implementation of storage elements leads to various forms of sequential logic Combinational Logic Storage Elements Outputs State OutputsState Inputs Inputs

9/13/07EECS150 F07 Culler Lec 6 27 Forms of Sequential Logic Asynchronous sequential logic – “state” changes occur whenever state inputs change (elements may be simple wires or delay elements) Synchronous sequential logic – state changes occur in lock step across all storage elements (using a periodic waveform - the clock) Clock

9/13/07EECS150 F07 Culler Lec 6 28 General Model of Synchronous Circuit All wires, except clock, may be multiple bits wide. Registers (reg) –collections of flip-flops clock –distributed to all flip-flops –typical rate? Combinational Logic Blocks (CL) –no internal state (no feedback) –output only a function of inputs Particular inputs/outputs are optional Optional Feedback ALL CYCLES GO THROUGH A REG!

9/13/07EECS150 F07 Culler Lec 6 29 Composing FSMs into larger designs CL FSM CL

9/13/07EECS150 F07 Culler Lec 6 30 Composing Moore FSMs Synchronous design methodology preserved CL Moore CL statestate output next state statestate output next state

9/13/07EECS150 F07 Culler Lec 6 31 Composing Mealy FSMs … Synchronous design methodology violated!!! Why do designers used them? –Few states, often more natural in isolation –Safe if latch all the outputs »Looks like a mealy machine, but isn’t really »What happens to the timing? CL Mealy FSM CL statestate Output Next state statestate Output Next state

9/13/07EECS150 F07 Culler Lec 6 32 Recall: What makes Digital Systems tick? Combinational Logic time clk

9/13/07EECS150 F07 Culler Lec 6 33 Recall 61C: Single-Cycle MIPS PC instruction memory +4 registers ALU Data memory imm 3 1 x LW r3, 17(r1) 17 reg[1] reg[1]+17 MEM[r1+17] 1. Instruction Fetch 2. Register Read 3. Execute4. Memory 5. Reg. Write

9/13/07EECS150 F07 Culler Lec 6 34 Recall 61C: 5-cycle Datapath - pipeline PC instruction memory +4 registers ALU Data memory imm 3 1 x LW r3, 17(r1) 1. Instruction Fetch 17 reg[1] 2. Register Read reg[1] Execute MEM[r1+17] 4. Memory 5. Reg. Write IR

9/13/07EECS150 F07 Culler Lec 6 35 FSM timing Clock Inputs Outputs State Time (Clock Period) State register propagation delay Output logic propagation delay How long must this be? State (internal) What determines min FSM cycle time (max clock rate)? What determines this?

9/13/07EECS150 F07 Culler Lec 6 36 Finite State Machines in Verilog inputs Moore outputs Mealy outputs next state current state combinational logic combinational logic

9/13/07EECS150 F07 Culler Lec 6 37 module Reduce(Out, Clock, Reset, In); outputOut; inputClock, Reset, In; regOut; reg [1:0]CurrentState;// state register reg [1:0]NextState; // State assignment localparamSTATE_Zero =2’h0, STATE_One1 =2’h1, STATE_Two1s =2’h2, STATE_X =2’hX; Verilog FSM - Reduce 1s example Change the first 1 to 0 in each string of 1’s –Example Moore machine implementation zero [0] one1 [0] two1s [1]

9/13/07EECS150 F07 Culler Lec 6 38 or CurrentState) begin NextState =CurrentState; Out =1’b0; case (CurrentState) STATE_Zero: begin // last input was a zero if (In) NextState =STATE_One1; end STATE_One1: begin // we've seen one 1 if (In) NextState =STATE_Two1s; else NextState =STATE_Zero; end STATE_Two1s: begin // we've seen at least 2 ones Out =1; if (~In) NextState =STATE_Zero; end default: begin // in case we reach a bad state Out =1’bx; NextState =STATE_X; end endcase end Moore Verilog FSM: combinational part zero [0] one1 [0] two1s [1] include all signals that are input to state and output equations Compute: output = G(state) next state = F(state, in)

9/13/07EECS150 F07 Culler Lec 6 39 // Implement the state register (posedge Clock) begin if (Reset) CurrentState <= STATE_Zero; else CurrentState <= NextState; end endmodule Moore Verilog FSM: state part zero [0] one1 [0] two1s [1] Note: posedge Clock requires NONBLOCKING ASSIGNMENT. Blocking Assignment Combinational Logic Nonblocking Assignment Sequential Logic (Registers)

9/13/07EECS150 F07 Culler Lec module Reduce(Clock, Reset, In, Out); inputClock, Reset, In; outputOut; regOut; regCurrentState;// state register regNextState; localparam STATE_Zero =1’b0, STATE_One =1’b1; Clock) begin if (Reset) CurrentState <=STATE_Zero; else CurrentState <=NextState; end (In or CurrentState) begin NextState =CurrentState; Out =1’b0; case (CurrentState) zero: if (In) NextState =STATE_One; one: begin// we've seen one 1 if (In) NextState = STATE_One; else NextState = STATE_Zero; Out =In; end endcase end endmodule Mealy Verilog FSM for Reduce-1s example 1/0 0/0 1/1 zero [0] one1 [0] Note: smaller state machine Output = G(state, input)

9/13/07EECS150 F07 Culler Lec 6 41 Restricted FSM Implementation Style Mealy machine requires two always blocks –Register needs posedge Clock block –Input to output needs combinational block Moore machine can be done with one always block, but…. –E.g. simple counter –Very bad idea for general FSMs »This will cost you hours of confusion, don’t try it »We will not accept labs with this style for general FSMs –Use two always blocks! Moore outputs –Share with state register, use suitable state encoding

9/13/07EECS150 F07 Culler Lec 6 42 module reduce (clk, reset, in, out); input clk, reset, in; output out; reg out; reg [1:0] state;// state register parameter zero = 0, one1 = 1, two1s = 2; Single-always Moore Machine (Not Allowed!) zero [0] one1 [0] two1s [1]

9/13/07EECS150 F07 Culler Lec 6 43 clk) case (state) zero: begin out <= 0; if (in) state <= one1; else state <= zero; end one1: if (in) begin state <= two1s; out <= 1; end else begin state <= zero; out <= 0; end two1s: if (in) begin state <= two1s; out <= 1; end else begin state <= zero; out <= 0; end default: begin state <= zero; out <= 0; end endcase endmodule This is confusing: the output does not change until the next clock cycle Single-always Moore Machine (Not Allowed!) All outputs are registered

9/13/07EECS150 F07 Culler Lec 6 44 Finite State Machines Recommended FSM Verilog implementation style –Implement combinational logic using one always block –Implement an explicit state register using a second always block inputs Moore outputs Mealy outputs next state current state combinational logic combinational logic

9/13/07EECS150 F07 Culler Lec 6 45 Summary FSMs are critical tool in your design toolbox –Adapters, Protocols, Datapath Controllers, … They often interact with other FSMs Important to design each well and to make them work together well. Keep your verilog FSMs clean –Separate combinational part from state update Good state machine design is an iterative process