Dr. Tassadaq Hussain www.tassadaq.ucerd.com Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain.

Slides:



Advertisements
Similar presentations
FSM and Efficient Synthesizable FSM Design using Verilog
Advertisements

//HDL Example 8-2 // //RTL description of design example (Fig.8-9) module Example_RTL (S,CLK,Clr,E,F,A);
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Synchronous Sequential Logic
Combinational Logic.
Table 7.1 Verilog Operators.
Give qualifications of instructors: DAP
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
ENEE 408C Lab Capstone Project: Digital System Design Fall 2005 Sequential Circuit Design.
ELEN 468 Advanced Logic Design
ECE 331 – Digital Systems Design Introduction to Sequential Logic Circuits (aka. Finite State Machines) and FSM Analysis (Lecture #19)
Sequential Logic in Verilog
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
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.
ECE 448 Lecture 6 Finite State Machines State Diagrams vs. Algorithmic State Machine (ASM) Charts.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU 99-1 Under-Graduate Project Design of Datapath Controllers Speaker: Shao-Wei Feng Adviser:
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..
Exp#7 Finite State Machine Design in Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
Overview Logistics Last lecture Today HW5 due today
Hardware Description Languages: Verilog
Verilog Tutorial Fall
Supplement on Verilog FF circuit examples
Supplement on Verilog for Algorithm State Machine Chart
Figure 8.1. The general form of a sequential circuit.
Last Lecture Talked about combinational logic always statements. e.g.,
© Copyright 2004, Gaetano Borriello and Randy H. Katz
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
Introduction to Advanced Digital Design (14 Marks)
Introduction Introduction to VHDL Entities Signals Data & Scalar Types
Supplement on Verilog Sequential circuit examples: FSM
Hardware Description Languages: Verilog
ECE 448 Lecture 6 Finite State Machines State Diagrams vs. Algorithmic State Machine (ASM) Charts.
Instructor: Alexander Stoytchev
Digital Logic Design Digital Design, M. Morris Mano and Michael D
Instructor: Alexander Stoytchev
COMP541 State Machines Montek Singh Feb 4, 2010.
CSE 370 – Winter Sequential Logic-2 - 1
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
Instructor: Alexander Stoytchev
332:437 Lecture 8 Verilog and Finite State Machines
Advanced FPGA Based System Design
COE 202 Introduction to Verilog
Supplement on Verilog Sequential circuit examples: FSM
Register-Transfer Level Components in Verilog
Figure 8.1. The general form of a sequential circuit.
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
ASM and Micro-programmed State Machines
Instructor: Alexander Stoytchev
The Verilog Hardware Description Language
ECE 448 Lecture 6 Finite State Machines State Diagrams, State Tables, Algorithmic State Machine (ASM) Charts, and VHDL Code.
Lecture 4: Continuation of SystemVerilog
332:437 Lecture 9 Verilog Example
332:437 Lecture 9 Verilog Example
ECE 448 Lecture 6 Finite State Machines State Diagrams, State Tables, Algorithmic State Machine (ASM) Charts, and VHDL code ECE 448 – FPGA and ASIC Design.
Instructor: Alexander Stoytchev
EGR 2131 Unit 12 Synchronous Sequential Circuits
332:437 Lecture 8 Verilog and Finite State Machines
Introduction to Digital IC Design
Introduction to Verilog – Part-2 Procedural Statements
ECE 448 Lecture 6 Finite State Machines State Diagrams vs. Algorithmic State Machine (ASM) Charts.
332:437 Lecture 9 Verilog Example
CSE 370 – Winter Sequential Logic-2 - 1
Presentation transcript:

Dr. Tassadaq Hussain www.tassadaq.ucerd.com Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain www.tassadaq.ucerd.com

Modeling Finite State Machines

General Model of a Digital System DATAPATH – Collection of functional units that process data Functional units are ultimately implemented as combinational and sequential logic CONTROLLER – Coordinates the operations in the datapath Controller (Usually a Finite State Machine) System Control Inputs System Control Outputs Datapath Control Signals Datapath Status Signals System Data Inputs Datapath System Data Outputs

Review: Moore vs Mealy Which is a Moore FSM and which is Mealy FSM? State INPUTS / Next State Combinational Logic Output Combinational / Logic D Q D Q / D Q / OUTPUTS / State INPUTS Next State Combinational Logic Output Combinational / Logic / D Q / D Q D Q / OUTPUTS /

Review: Moore Finite State Machine Output signals depend only on the current state Also, observe the THREE distinct parts State INPUTS / Next State Combinational Logic Output Combinational / Logic D Q / D Q D Q / OUTPUTS / Example State Diagram of a Moore FSM A = 0 A = 0 A = 0 A = 1 SA [F = 0] SB [F = 1] A = 1 SC [F = 1] SD [F = 0] A = 0 A = 1 A = 1 FSM A F

Review: Mealy Finite State Machine Output signals depend on both current state and current inputs Also, observe the THREE distinct parts State INPUTS Output Combinational / Logic / Next State Combinational Logic D Q / D Q D Q / OUTPUTS /

Moore-type FSM Example 3-states FSM Input = w Output = z

Recipe for Describing FSM in Verilog Define the state codes as parameters to list all states from your state diagram. Declare a reg [log2(num states) wide] to store the current state (flip-flops) and next state. Next-state logic: Write one always block to specify the values that next state should have for each value of present state: This is a combinational process (Type-1) Inputs are the current_state (outputs from the first process), and FSM Inputs Use CASE to specify next state Outputs are the FSM outputs Present-state Advancement: Write second always block which specifies that present state is assigned the value of next state on the positive clock edge: This is a sequential process (Type 2 or 3) Inputs to this always block are clock and async reset (if any) Output is the current state signal Output Logic: Write a third always block (optional) that drives the output based on present state (and input in case of Mealy). This is a combinational process (Type-1). Alternatively, can be modeled through continuous statements.

1 2 3 4 5 module moore (Clock, w, Resetn, z); input Clock, w, Resetn; output z; parameter A = 2'b00, B = 2'b01, C = 2'b10; reg [1:0] p_state, n_state;   always @(w, p_state) begin case (p_state) A: if (w = = 0) n_state = A; else n_state = B; B: if (w = = 0) n_state = A; else n_state = C; C: if (w = = 0) n_state = A; default: n_state = 2'bxx; endcase end always @(posedge Clock, negedge Resetn) if (Resetn = = 0) p_state <= A; else p_state <= n_state; assign z = (p_state = = C); endmodule  1 2 3 4 5

Combining Next Sate Logic and Output Logic module simple (Clock, Resetn, w, z); input Clock, Resetn, w; output reg z; reg [2:1] y, Y; parameter [2:1] A = 2'b00, B = 2'b01, C = 2'b10;   // Define the next state combinational circuit always @(w, y) begin case (y) A: if (w) Y = B; else Y = A; B: if (w) Y = C; C: if (w) Y = C; default: Y = 2'bxx; endcase z = (y = = C); //Define output end // Define the sequential block always @(negedge Resetn, posedge Clock) if (Resetn = = 0) y <= A; else y <= Y; endmodule

Alternate Coding Style 3 – One Always block module simple (Clock, Resetn, w, z); input Clock, Resetn, w; output z; reg [2:1] y; parameter [2:1] A = 2'b00, B = 2'b01, C = 2'b10;   // Define the sequential block always @(negedge Resetn, posedge Clock) if (Resetn = = 0) y <= A; else case (y) A: if (w) y <= B; else y <= A; B: if (w) y <= C; C: if (w) y <= C; default: y <= 2'bxx; endcase // Define output assign z = (y = = C); endmodule

Which Coding Style do I opt for my FSM? While all the three coding styles yield the same functionally equivalent FSM: It is suggested to stick with the first style, i.e. three always blocks (recall that third output logic block is optional); More closer to the circuit description Easier to read and debug

Impact of State Encoding on Sequential Circuit Complexity

Derivation for Next-state and Output Logic Expressions y y 2 1 Ignoring don't cares Using don't cares w 00 01 11 10 d Y = wy y Y = wy y 1 1 2 1 1 2 1 1 d y y 2 1 w 00 01 11 10 d Y = wy y + wy y Y = wy + wy 2 1 2 1 2 2 1 2 1 1 d 1 = w ( y + y ) 1 2 y 1 y 2 1 z = y y z = y 1 2 2 1 1 d

Final Implementation

State Encoding Fewer Gates  Lesser Implementation Cost Y y D Q z Q Y 2 2 D Q z Q Y y 1 1 w D Q Clock Q Resetn Fewer Gates  Lesser Implementation Cost

Other State-Encoding Options One-Hot: Another interesting possibility is to use as many state variables as there are states. In this method, for each state all but one of the state variables are equal to 0. The variable whose value is 1 is deemed to be “hot.” The approach is known as the one-hot encoding method. Two-Hot: Two variables are 1 in any given state. Johnson: Output of Johnson counter is used to encode the states, complement output of the last flip-flop Q̅n is back-fed to the first flip-flop in the chain.

Choosing THE Best State Encoding In general, circuits are much larger than our example, and different state assignments can have a substantial effect on the cost of the final implementation. It is often impossible to find the best state assignment for a large circuit. CAD tools usually perform the state assignment using heuristic techniques (https://en.wikipedia.org/wiki/Heuristic): These techniques are usually proprietary, and their details are seldom published.

Specifying the State Encoding in an EDA Tool Verilog compilers usually have a capability to search for different assignments that may give better results: such as attempting to use the one-hot encoding etc. The user can either allow the compiler to use its FSM-handling capability, or suppress it in which case the compiler simply deals with the Verilog statements in the usual way. In Quartus Prime: Assignments  Settings  Compiler Settings  Advanced Settings (Synthesis)  Filter with keyword ‘state’  State machine processing

Specifying State Encoding in Intel Quartus Prime

Recommended Reading Stephen Brown - Fundamentals of Digital Logic with Verilog Design, 3rd Edition: Chapter-5: 5.12 and 5.13 Chapter-6: 6.1 – 6.4. Also pay attention to FSM examples.

THANK YOU 26