FSM and Efficient Synthesizable FSM Design using Verilog

Similar documents
Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

ECE 2300 Digital Logic & Computer Organization. More Finite State Machines

EE178 Lecture Verilog FSM Examples. Eric Crabill SJSU / Xilinx Fall 2007

Quick Introduction to SystemVerilog: Sequental Logic

RTL Design (Using ASM/SM Chart)

ECE 551: Digital System *

ECE 4514 Digital Design II. Spring Lecture 15: FSM-based Control

Verilog for Synthesis Ing. Pullini Antonio

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

EECS 270 Verilog Reference: Sequential Logic

Blocking(=) vs Nonblocking (<=) Assignment. Lecture 3: Modeling Sequential Logic in Verilog HDL. Procedural assignments

CSE140L: Components and Design Techniques for Digital Systems Lab

CSE140L: Components and Design

EE 231 Fall EE 231 Homework 8 Due October 20, 2010

State Machine Descriptions

Finite State Machines (FSM) Description in VHDL. Review and Synthesis

FSM Components. FSM Description. HDL Coding Methods. Chapter 7: HDL Coding Techniques

EEL 4783: HDL in Digital System Design

Control in Digital Systems

Sequential Logic Design

EECS150 - Digital Design Lecture 10 Logic Synthesis

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Finite State Machines

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

EN164: Design of Computing Systems Lecture 07: Lab Foundations / Verilog 3

EECS150 - Digital Design Lecture 10 Logic Synthesis

Lecture 3. Behavioral Modeling Sequential Circuits. Registers Counters Finite State Machines

Verilog Coding Guideline

Designing Safe Verilog State Machines with Synplify

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

ECEN 468 Advanced Logic Design

Simple Behavioral Model: the always block

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

Digital Integrated Circuits

Verilog 1 - Fundamentals

Verilog for High Performance

Finite-State Machine (FSM) Design

Synthesizable Verilog

Course Topics - Outline

Speaker: Kayting Adviser: Prof. An-Yeu Wu Date: 2009/11/23

World Class Verilog & SystemVerilog Training

Finite State Machines

Mealy and Moore examples

Finite State Machines

Yet Another Latch and Gotchas Paper

Lecture 32: SystemVerilog

Modeling Sequential Circuits in Verilog

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb With material by Professor Moritz and Kundu UMass Amherst Fall 2016

ECE 551 Digital System Design and Synthesis. Instructor: Kewal K. Saluja. Midterm Exam

FINITE STATE MACHINES (FSM) DESCRIPTION IN VHDL. Cristian Sisterna UNSJ

VHDL for Synthesis. Course Description. Course Duration. Goals

CSE140L: Components and Design Techniques for Digital Systems Lab. FSMs. Instructor: Mohsen Imani. Slides from Tajana Simunic Rosing

Lecture 15: System Modeling and Verilog

Laboratory Exercise 7

Last Lecture: Divide by 3 FSM

ECE 4514 Digital Design II. Spring Lecture 13: Logic Synthesis

Lecture #2: Verilog HDL

Verilog introduction. Embedded and Ambient Systems Lab

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

Logic Circuits II ECE 2411 Thursday 4:45pm-7:20pm. Lecture 3

Registers and finite state machines

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

Bulletproofing FSM Verification Automated Approach to Detect Corner Case Issues in an FSM Design

Digital Integrated Circuits

Verilog For Synthesis

CS6710 Tool Suite. Verilog is the Key Tool

VERILOG. Deepjyoti Borah, Diwahar Jawahar

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

Outline. EECS Components and Design Techniques for Digital Systems. Lec 11 Putting it all together Where are we now?

Nonblocking Assignments in Verilog Synthesis; Coding Styles That Kill!

Modeling of Finite State Machines. Debdeep Mukhopadhyay

CMPE 415 Full and Parallel Case

Parallel versus serial execution

HDL Compiler Directives 7

Hardware Description Languages: Verilog

Testbenches for Sequential Circuits... also, Components

L5: Simple Sequential Circuits and Verilog

L5: Simple Sequential Circuits and Verilog

Verilog Sequential Logic. Verilog for Synthesis Rev C (module 3 and 4)

The University of Alabama in Huntsville ECE Department CPE Midterm Exam February 26, 2003

ES611 FPGA Based System Design. Behavioral Model

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

L5: Simple Sequential Circuits and Verilog

EECS150 - Digital Design Lecture 6 - Logic Simulation

Last Lecture. Talked about combinational logic always statements. e.g., module ex2(input logic a, b, c, output logic f); logic t; // internal signal

Abstraction of State Elements. Sequential Logic Implementation. Forms of Sequential Logic. Finite State Machine Representations

P-1/P-105. Samir Palnitkar. Prentice-Hall, Inc. INSTRUCTOR : CHING-LUNG SU.

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Register Transfer Level in Verilog: Part I

FizZim an open-source FSM design environment

Sunburst Design - Comprehensive SystemVerilog Design & Synthesis by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

ECE 353 Lab 3 (Verilog Design Approach)

Writing Circuit Descriptions 8

EN2911X: Reconfigurable Computing Lecture 06: Verilog (3)

The Verilog Language COMS W Prof. Stephen A. Edwards Fall 2002 Columbia University Department of Computer Science

Transcription:

FSM and Efficient Synthesizable FSM Design using Verilog

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.) Mealy Machine Only Combinational Logic Sequential Logic Circuit Combinational Logic Next State Logic Next Present State FF s State Output Logic outputs CLK

Binary Encoded or One Hot Encoding Binary Encoded FSM (Highly Encoded) One Hot Encoding 110 S4 IDLE 000 S1 001 10000 S4 IDLE 00001 S1 00010 010 S3 S2 011 01000 S3 S2 00100

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) else required FF = log2(number of states) 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) 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 gnt = 1'b1; if (!dly) next = BFREE; else next = BWAIT; end BFREE: if (req) next = BBUSY; else next = IDLE; endcase end endmodule

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; gnt <= 1'b0; case (state) IDLE : if (req) begin state <= BBUSY; gnt <= 1'b1; end else

One Always Block FSM Style BBUSY: if (!done) begin state <= BBUSY; gnt <= 1'b1; end else if ( dly) begin state <= BWAIT; gnt <= 1'b1; end else state <= BFREE; BWAIT: if ( dly) begin state <= BWAIT; gnt <= 1'b1; end else state <= BFREE; BFREE: if (req) begin state <= BBUSY; gnt <= 1'b1; end else state <= IDLE; endcase end 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 nextstate 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