FSM and Efficient Synthesizable FSM Design using Verilog

Slides:



Advertisements
Similar presentations
Digital System Design-II (CSEB312)
Advertisements

Tutorial 2 Sequential Logic. Registers A register is basically a D Flip-Flop A D Flip Flop has 3 basic ports. D, Q, and Clock.
//HDL Example 8-2 // //RTL description of design example (Fig.8-9) module Example_RTL (S,CLK,Clr,E,F,A);
Counters Discussion D8.3.
Traffic light contoller using FSM
COMP541 State Machines – II: Verilog Descriptions
CDA 3100 Recitation Week 11.
Sequential Logic in Verilog
Synchronous Sequential Logic
Combinational Logic.
A Digital Circuit Toolbox
Table 7.1 Verilog Operators.
//HDL Example 5-1 // //Description of D latch (See Fig.5-6) module D_latch (Q,D,control); output Q; input.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
Analysis of Clocked Sequential Circuits
FSM Revisit Synchronous sequential circuit can be drawn like below  These are called FSMs  Super-important in digital circuit design FSM is composed.
TOPIC : Finite State Machine(FSM) and Flow Tables UNIT 1 : Modeling Module 1.4 : Modeling Sequential circuits.
Give qualifications of instructors: DAP
FSM examples.
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
Digital System Design by Verilog University of Maryland ENEE408C.
Asynchronous FSMs and Verilog. PLD registered output.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
ELEN 468 Lecture 161 ELEN 468 Advanced Logic Design Lecture 16 Synthesis of Language Construct II.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE VLSI System Design Lecture 4 - Advanced Verilog.
ELEN 468 Advanced Logic Design
ECE 301 – Digital Electronics Introduction to Sequential Logic Circuits (aka. Finite State Machines) and FSM Analysis (Lecture #17)
ECE 331 – Digital Systems Design Introduction to Sequential Logic Circuits (aka. Finite State Machines) and FSM Analysis (Lecture #19)
Sequential Logic in Verilog
ECE 2372 Modern Digital System Design
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
Verilog for Synthesis Ing. Pullini Antonio
Workshop Topics - Outline
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
The Verilog Hardware Description Language. GUIDELINES How to write HDL code: How to write HDL code:
Finite State Machine (FSM) Nattha Jindapetch December 2008.
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
Introduction to ASIC flow and Verilog HDL
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Chapter 11: System Design.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
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.
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 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Figure Implementation of an FSM in a CPLD..
Overview Logistics Last lecture Today HW5 due today
Supplement on Verilog FF circuit examples
Figure 8.1. The general form of a sequential circuit.
Last Lecture Talked about combinational logic always statements. e.g.,
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
Introduction Introduction to VHDL Entities Signals Data & Scalar Types
‘if-else’ & ‘case’ Statements
FIGURE 5.1 Block diagram of sequential circuit
TODAY’S OUTLINE Procedural Assignments Verilog Coding Guidelines
Digital Logic Design Digital Design, M. Morris Mano and Michael D
SYNTHESIS OF SEQUENTIAL LOGIC
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
COE 202 Introduction to Verilog
The Verilog Hardware Description Language
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Lecture 4: Continuation of SystemVerilog
Dr. Tassadaq Hussain Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain.
Presentation transcript:

FSM and Efficient Synthesizable FSM Design using Verilog S. Rawat

Introduction There are many ways to code FSMs including many very poor ways to code FSMs. This lecture offers guidelines for doing efficient coding, simulation and synthesis of FSM designs. In this lecture multiple references are made to combinational always blocks and sequential always blocks.

Introduction Combinational always blocks are always blocks that are used to code combinational logic functionality and are strictly coded using blocking assignments. A combinational always block has a combinational sensitivity list, a sensitivity list without "posedge" or "negedge" Verilog keywords. Sequential always blocks are always blocks that are used to code clocked or sequential logic and are always coded using nonblocking assignments. A sequential always block has an edge-based sensitivy list.

Mealy & Moore FSMs A common classification used to describe the type of an FSM is Mealy and Moore state machines. A Moore FSM is a state machine where the outputs are only a function of the present state. A Mealy FSM is a state machine where one or more of the outputs is a function of the present state and one or more of the inputs.

Mealy & Moore FSMs (contd.)

Binary Encoded or One Hot Encoding

Binary Encoded or One Hot Encoding A binary-encoded FSM design only requires as many flip-flops as are needed to uniquely encode the number of states in the state machine. Number of FF if(log2(number of states) == integer) required FF = log2(number of states) else required FF = integer(log2(#states))+1;

Binary Encoded or One Hot Encoding A onehot FSM design requires a flip-flop for each state in the design and only one flip-flop (the flip-flop representing the current or "hot" state) is set at a time in a onehot FSM design. For a state machine with 9-16 states, a binary FSM only requires 4 flip-flops while a onehot FSM requires a flip-flop for each state in the design (9-16 flip-flops).

FSM Coding Goals What constitutes an efficient FSM coding style? Identify HDL coding goals and why they are important. Quantify the capabilities of various FSM coding styles.

FSM Coding Goals The FSM coding style should be easily modified to change state encodings and FSM styles. The coding style should be compact. The coding style should be easy to code and understand. The coding style should facilitate debugging. The coding style should yield efficient synthesis results.

Two Always Block FSM Style (Good Style) One of the best Verilog coding styles is to code the FSM design using two always blocks, one for the sequential state register and one for the combinational next-state and combinational output logic.

Two Always Block FSM Style (Good Style) module fsm_4states (output reg gnt, input dly, done, req, clk, rst_n); parameter [1:0] IDLE = 2'b00, BBUSY = 2'b01, BWAIT = 2'b10, BFREE = 2'b11; reg [1:0] state, next; always @(posedge clk or negedge rst_n) if (!rst_n) state <= IDLE; else state <= next; Two Always Block FSM Style (Good Style)

Two Always Block FSM Style (Good Style) always @(state or dly or done or req) begin next = 2'bx; gnt = 1'b0; case (state) IDLE : if (req) next = BBUSY; else next = IDLE; BBUSY: begin gnt = 1'b1; if (!done) next = BBUSY; else if ( dly) next = BWAIT; else next = BFREE; end BWAIT: begin if (!dly) next = BFREE; else next = BWAIT; BFREE: if (req) next = BBUSY; endcase end endmodule Two Always Block FSM Style (Good Style)

Making default next equal all X's assignment Placing a default next state assignment on the line immediately following the always block sensitivity list is a very efficient coding style. This default assignment is updated by next-state assignments inside the case statement. There are three types of default next-state assignments that are commonly used: (1) next is set to all X's, (2) next is set to a predetermined recovery state such as IDLE, or (3) next is just set to the value of the state register. By making a default next state assignment of X's, pre-synthesis simulation models will cause the state machine outputs to go unknown if not all state transitions have been explicitly assigned in the case statement. This is a useful technique to debug state machine designs, plus the X's will be treated as "don't cares" by the synthesis tool. Some designs require an assignment to a known state as opposed to assigning X's. Examples include: satellite applications, medical applications, designs that use the FSM flip-flops as part of a diagnostic scan

One Always Block FSM Style (Avoid This Style!) One of the most common FSM coding styles in use today is the one sequential always block FSM coding style. For most FSM designs, the one always block FSM coding style is more verbose, more confusing and more error prone than a comparable two always block coding style.

One Always Block FSM Style: module fsm_4states (output reg gnt, input dly, done, req, clk, rst_n); parameter [1:0] IDLE = 2'd0, BBUSY = 2'd1, BWAIT = 2'd2, BFREE = 2'd3; reg [1:0] state;

One Always Block FSM Style: always @(posedge clk or negedge rst_n) if (!rst_n) begin state <= IDLE; gnt <= 1'b0; end else begin state <= 2'bx; case (state) IDLE : if (req) begin state <= BBUSY; gnt <= 1'b1; else

One Always Block FSM Style BBUSY: if (!done) begin state <= BBUSY; gnt <= 1'b1; end else if ( dly) begin state <= BWAIT; else state <= BFREE; BWAIT: if ( dly) begin BFREE: if (req) begin else state <= IDLE; endcase endmodule

Onehot FSM Coding Style (Good Style) Efficient (small and fast) onehot state machines can be coded using an inverse case statement; a case statement where each case item is an expression that evaluates to true or false. Reconsider the fsm_4state design shown. The key to understanding the changes is to realize that the parameters no longer represent state encodings, they now represent an index into the state vector, and comparisons and assignments are now being made to single bits in either the state or next-state vectors. Notice how the case statement is now doing a 1-bit comparison against the onehot state bit.

Onehot FSM Coding Style

Onehot FSM Coding Style

Onehot FSM Coding Style This is the only coding style where one should use full_case and parallel_case statements. The parallel case statement tells the synthesis tool to not build a priority encoder even though in theory, more than one of the state bits could be set (as engineers, we should know that this is a onehot FSM and that only one bit can be set so no priority encoder is required).

Registered FSM Outputs (Good Style) The Only Change one has to do is always @(posedge clk or negedge rst_n) if (!rst_n) gnt <= 1'b0; else begin gnt <= 1'b0; case (next) IDLE, BFREE: ; // default outputs BBUSY, BWAIT: gnt <= 1'b1; endcase end endmodule

Thanks Courtesy – International Cadence User Group 2002