FSM Revisit Synchronous sequential circuit can be drawn like below  These are called FSMs  Super-important in digital circuit design FSM is composed.

Slides:



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

Recap : Always block module and_gate (out, in1, in2); inputin1, in2; outputout; regout; or in2) begin out = in1 & in2; end endmodule zAlways.
//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
Verilog in transistor level using Microwind
Sequential Logic in Verilog
Synchronous Sequential Logic
Table 7.1 Verilog Operators.
Hardware Description Language (HDL)
//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.
TOPIC : Finite State Machine(FSM) and Flow Tables UNIT 1 : Modeling Module 1.4 : Modeling Sequential circuits.
How to get a Circuit in verilog converted to hspice, connected to the micron package models, and simulating in hspice and hsimplus.
CSE Spring Verilog for Sequential Systems - 1 Today: Verilog and Sequential Logic zFlip-flops yrepresentation of clocks - timing of state.
FSM examples.
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.
ELEN 468 Lecture 121 ELEN 468 Advanced Logic Design Lecture 12 Synthesis of Combinational Logic I.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
2-to-1 Multiplexer: if Statement Discussion D7.1 Example 4.
ENEE 408C Lab Capstone Project: Digital System Design Fall 2005 Sequential Circuit Design.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
FSMs in Verilog and other random things 9/27/02. FSM structure CLK STATE Next State Logic Inputs Output Logic Outputs.
D Flip-Flops in Verilog Discussion 10.3 Example 27.
FPGA-Based System Design: Chapter 5 Copyright  2004 Prentice Hall PTR Verilog for sequential machines.
Sequential Logic in Verilog
1 COMP541 State Machines Montek Singh Feb 8, 2012.
FPGA-Based System Design: Chapter 5 Copyright  2004 Prentice Hall PTR Topics n Verilog styles for sequential machines. n Flip-flops and latches.
Lecture 6. Verilog HDL – Sequential Logic
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
Lab7-1 Lab 6: FSM Description Separate combinational and memory circuits –State memory uses FFs –Others are combinational circuits.
ECE/CS 352 Digital System Fundamentals© 2001 C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Spring 2001 Chapters 3 and 4: Verilog – Part 2 Charles R.
TODAY’S OUTLINE Finite State Machine Exercise 1 Exercise 1 Exercise 2 Exercise 2 Exercise 3 Exercise 3 Exercise 4 Exercise 4.
Register Transfer Level & Design with ASM
Traffic Lights Discussion D8.3a. Recall Divide-by-8 Counter Use Q2, Q1, Q0 as inputs to a combinational circuit to produce an arbitrary waveform. s0 0.
Lecture 5. Sequential Logic 2 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education & Research.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Verilog Part 3 – Chapter.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.
1 COMP541 State Machines - II Montek Singh Feb 13, 2012.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Chapter 11: System Design.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
1 (c) W. J. Dally Digital Design: A Systems Approach Lecture 7: Data Path State Machines.
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 #
Lecture 5. Verilog HDL #3 Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Logic Design.
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.
Supplement on Verilog for Algorithm State Machine Chart
Lecture 4. Sequential Logic #2
Figure 8.1. The general form of a sequential circuit.
Supplement on Verilog Sequential circuit examples: FSM
COMP541 Sequential Logic – 2: Finite State Machines
Digital Logic Design Digital Design, M. Morris Mano and Michael D
HDL Compiler Unsupport (Do NOT use in your verilog code)
COMP541 State Machines Montek Singh Feb 4, 2010.
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
COE 202 Introduction to Verilog
Topics Verilog styles for sequential machines. Flip-flops and latches.
Supplement on Verilog Sequential circuit examples: FSM
Sequential logic implementation
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
CSE 140 Lecture 9 Sequential Networks
Mr. Pradeep J NATIONAL INSTITUTE OF TECHNOLOGY,
Design of Digital Circuits Lecture 7: Sequential Logic Design
Lecture 4: Finite State Machines
Presentation transcript:

FSM Revisit Synchronous sequential circuit can be drawn like below  These are called FSMs  Super-important in digital circuit design FSM is composed of  State register  Combinational logic that Computes the next state based on current state and input Computes the outputs based on current state (and input) 1

Traffic Light Controller Revisit 2 A simplified traffic light controller  Traffic sensors (sensing human traffic): T A, T B Each sensor becomes TRUE if students are present Each sensor becomes FALSE if students are NOT present (i.e., the street is empty)  Lights: L A, L B Each light receives digital inputs specifying whether it should be green, yellow, or red

Moore FSM in Verilog 3 // next state logic (*) begin case (currstate) S0: if (~TA) nextstate = S1; else nextstate = S0; S1: nextstate = S2; S2: if (~TB) nextstate = S3; else nextstate = S2; S3: nextstate = S0; default: nextstate = S0; endcase end // output logic (*) begin if (currstate == S0) begin LA = green; LB = red; end else if (currstate == S1) begin LA = yellow; LB = red; end else if (currstate == S2) begin LA = red; LB = green; end else begin LA = red; LB = yellow; end endmodule `timescale 1ns/1ps module moore_traffic_light (input clk, reset, TA, TB, output reg [1:0] LA, LB); reg [1:0] currstate, nextstate; parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; parameter green = 2'b00; parameter yellow = 2'b01; parameter red = 2'b10; // state register (posedge clk, posedge reset) begin if (reset) currstate <= S0; else currstate <= nextstate; end

Simulation with ModelSim Useful tips in using ModelSim  To display state information as described in Verilog code Format: radix define name { …. } Example: radix define mystate {2'b00 "S0", 2'b01 "S1", 2'b10 "S2", 2'b11 "S3", -default binary} radix define mylight {2'b00 "green", 2'b01 "yellow", 2'b10 "red", -default binary}  Save the display information for the use in the future File->Save Format, Then click on “OK” By default, it will save the waveform format to “wave.do” 4

Snail FSM Revisit There is a snail  The snail crawls down a paper tape with 1’s and 0’s on it  The snail smiles whenever the last four digits it has crawled over are Moore FSM: arcs indicate input S0 0 reset S S S S Mealy FSM: arcs indicate input/output S0 reset S1 1/0 0/0 S2 1/0 S3 0/0 1/1 0/0

Moore FSM in Verilog 6 `timescale 1ns/1ps module moore_snail(input clk, reset, bnum, output reg smile); reg [2:0] currstate, nextstate; parameter S0 = 3'b000; parameter S1 = 3'b001; parameter S2 = 3'b010; parameter S3 = 3'b011; parameter S4 = 3'b100; parameter delay = 1; // state register reset, posedge clk) begin if (reset) #delay currstate <= S0; else #delay currstate <= nextstate; end // next state logic begin case (currstate) S0: if (bnum) #delay nextstate = S1; else #delay nextstate = S0; S1: if (bnum) #delay nextstate = S2; else #delay nextstate = S0; S2: if (bnum) #delay nextstate = S2; else #delay nextstate = S3; S3: if (bnum) #delay nextstate = S4; else #delay nextstate = S0; S4: if (bnum) #delay nextstate = S2; else #delay nextstate = S0; default: #delay nextstate = S0; endcase end // output logic begin if (currstate == S4) smile = 1'b1; else smile = 1'b0; end endmodule Moore FSM: arcs indicate input S0 0 reset S S S S

Mealy FSM in Verilog 7 `timescale 1ns/1ps module mealy_snail(input clk, reset, bnum, output reg smile); reg [1:0] currstate, nextstate; parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; parameter delay = 1; // state register reset, posedge clk) begin if (reset) #delay currstate <= S0; else #delay currstate <= nextstate; end // next state logic begin case (currstate) S0: begin if (bnum) #delay nextstate = S1; else #delay nextstate = S0; end S1: begin if (bnum) #delay nextstate = S2; else #delay nextstate = S0; end S2: begin if (bnum) #delay nextstate = S2; else #delay nextstate = S3; end S3: begin if (bnum) #delay nextstate = S1; else #delay nextstate = S0; end default: #delay nextstate = S0; endcase end // output logic begin case (currstate) S3: begin if (bnum) #delay smile = 1'b1; else #delay smile = 1'b0; end default: #delay smile = 1'b0; endcase end endmodule Mealy FSM: arcs indicate input/output S0 reset S1 1/0 0/0 S2 1/0 S3 0/0 1/1 0/0

Simulation with ModelSim Use radices below for display purpose  radix define moore_state {3'b000 "S0", 3'b001 "S1", 3'b010 "S2", 3'b011 "S3", 3'b100 "S4", -default binary}  radix define mealy_state {2'b00 "S0", 2'b01 "S1", 2'b10 "S2", 2'b11 "S3", -default binary} 8

HDL Summary HDLs are extremely important languages for modern digital designers You are able to design digital systems with HDL much faster than drawing schematics Debug cycle is also often much faster because modifications require code changes instead of tedious schematic redrawing  However, the debug cycle can be much longer with HDLs if you don’t have a good idea of the hardware your code implies 9

HDL Summary The most important thing to remember when writing HDL code is that you are describing real hardware! (not writing a software program) The most common beginner’s mistake is to write HDL code without thinking about the hardware you intend to produce  If you don’t know what hardware your code is implying, you mostly likely don’t get what you want When designing with HDL, sketch a block diagram of your system  Identify which portions are combinational logic, sequential logic, FSMs and so on, so forth  Write HDL code for each portion and then merge together 10