FSMs and Synchronization

Slides:



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

FSM and Efficient Synthesizable FSM Design using Verilog
Traffic light contoller using FSM
Synchronous Sequential Logic
Table 7.1 Verilog Operators.
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.
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.
Simple Sequential Circuits and Verilog. 序向邏輯重要關念 Classification:   Latch:   Register:   Flip-Flop:   Timing:
Computer Organization and Design Fundamental 書籍作者: David Tarnoff 投影片製作者:陳鍾誠 第 11 章 State Machines ( 狀態機 )
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.
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
CS 151 Digital Systems Design Lecture 25 State Reduction and Assignment.
1 Chapter 6 狀態機設計法 狀態機設計法的介紹 在圖形編輯器視窗下執行 在 Project Manager 視窗下執行.
第10章 移位暫存器 10-1 移位暫存器的基本功能 10-2 串列輸入/輸出移位暫存器 10-3 其他移位暫存器的線路型態
Give qualifications of instructors: DAP
Chapter 3 Entropy : An Additional Balance Equation
Arbitrary Waveform Discussion 12.2 Example 34. Recall Divide-by-8 Counter Use q2, q1, q0 as inputs to a combinational circuit to produce an arbitrary.
Spring 2002EECS150 - Lec15-seq2 Page 1 EECS150 - Digital Design Lecture 15 - Sequential Circuits II (Finite State Machines revisited) March 14, 2002 John.
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.
ELEN 468 Advanced Logic Design
ENGIN112 L25: State Reduction and Assignment October 31, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 25 State Reduction and Assignment.
VHDL語法(3).
Lecture 17 General finite state machine (FSM) design
Sequential Logic in Verilog
1 COMP541 State Machines Montek Singh Feb 8, 2012.
Registers & Counters M. Önder Efe
Registers(暫存器)與Counters(計數器):
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.
Chapter 6 Registers and Counters
Review of Digital Logic Design Concepts OR: What I Need to Know from Digital Logic Design (EEL3705)
1 CSE370, Lecture 18 Lecture 20 u Logistics n HW6 due Wednesday n Lab 7 this week (Tuesday exception) n Midterm 2 Friday (covers material up to simple.
DLD Lecture 26 Finite State Machine Design Procedure.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
VHDL Discussion Finite State Machines IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology 1.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL State Machines Anselmo Lastra.
Digital System Design using VHDL
1 COMP541 Finite State Machines - 1 Montek Singh Sep 22, 2014.
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.
© 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:
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.
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
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
Supplement on Verilog Sequential circuit examples: FSM
COMP541 Sequential Logic – 2: Finite State Machines
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
Supplement on Verilog Sequential circuit examples: FSM
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Lecture 20 Logistics Last lecture Today HW6 due Wednesday
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
Dr. Tassadaq Hussain Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain.
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
Lecture 7: Verilog Part II
Presentation transcript:

FSMs and Synchronization

Asynchronous Inputs in Sequential Systems

Asynchronous Inputs in Sequential Systems

Asynchronous Inputs in Sequential Systems

Asynchronous Inputs in Sequential Systems 如此可避免發生I、II類時序不同步之問題 但對於第三類觸發時間不確定確無法克服?

Handling Metastability Preventing metastability turns out to be an impossible problem High gain of digital devices makes it likely that metastable conditions will resolve themselves quickly Solution to metastability: allow time for signals to stabilize

Handling Metastability How many registers are necessary? Depends on many design parameters(clock speed, device speeds, …),one or maybe two synchronization registers is sufficient

Finite State Machines Finite State Machines (FSMs) are a useful abstraction for sequential circuits with centralized “states” of operation At each clock edge, combinational logic computes outputs and next state as a function of inputs and present state

Finite State Machines

Two Types of FSMs Moore FSMs 輸出只與目前狀態有關 Mealy FSMs 輸出與目前狀態及輸入有關 Moore and Mealy FSMs are distinguished by their output generation

Moore FSMs Moore and Mealy FSMs are distinguished by their output generation

Mealy FSMs

FSM Design Example : Level-to-Pulse 功能:A level-to-pulse converter produces a single-cycle pulse each time its input goes high. In other words, it’s a synchronous rising edge detector. 應用例: Buttons and switches pressed by humans for arbitrary periods of time Single-cycle enable signals for counters

FSM Design Example : Level-to-Pulse

State Transition Diagrams 如何設計Level to Pulse FSM? 狀態轉移圖是一種非常有用之工具。

State Transition Diagrams 狀態…. 轉移 觸發輸入/輸出 狀態A 狀態B 轉移 觸發輸入/輸出

State Transition Diagrams

Logic Derivation for a Moore FSM 應用轉移 寫出下一狀態、輸出與輸入、目前狀態之真假值表

Logic Derivation for a Moore FSM 對應之組合邏輯應用K-map化簡

Moore Level-to-Pulse Converter

Design of a Mealy Level-to-Pulse

Mealy Level-to-Pulse Converter

Moore/Mealy Trade-Offs Remember that the difference is in the output: Moore outputs are based on state only Mealy outputs are based on state and input Therefore, Mealy outputs generally occur one cycle earlier than a Moore: Compared to a Moore FSM, a Mealy FSM might... Be more difficult to conceptualize and design Have fewer states

FSM Timing Requirements

FSM Timing Requirements

Vending Machine

What States are in the System?

A Moore Vender

State Reduction

Verilog for the Moore Vender module mooreVender (N, D, Q, DC, DN, DD, clk, reset, state); input N, D, Q, clk, reset; output DC, DN, DD; output [3:0] state; reg [3:0] state, next;

parameter IDLE = 0; parameter GOT_5c = 1; parameter GOT_10c = 2; parameter GOT_15c = 3; parameter GOT_20c = 4; parameter GOT_25c = 5; parameter GOT_30c = 6; parameter GOT_35c = 7; parameter GOT_40c = 8; parameter GOT_45c = 9; parameter GOT_50c = 10; parameter RETURN_20c = 11; parameter RETURN_15c = 12; parameter RETURN_10c = 13; parameter RETURN_5c = 14

always @ (posedge clk or negedge reset) if (!reset) state <= IDLE; else state <= next;

always @ (state or N or D or Q) begin case (state) IDLE: if (Q) next = GOT_25c; else if (D) next = GOT_10c; else if (N) next = GOT_5c; else next = IDLE; GOT_5c: if (Q) next = GOT_30c; else if (D) next = GOT_15c; else if (N) next = GOT_10c; else next = GOT_5c; GOT_10c: if (Q) next = GOT_35c; else if (D) next = GOT_20c; else if (N) next = GOT_15c; else next = GOT_10c; GOT_15c: if (Q) next = GOT_40c; else if (D) next = GOT_25c; else if (N) next = GOT_20c; else next = GOT_15c; GOT_20c: if (Q) next = GOT_45c; else if (D) next = GOT_30c; else if (N) next = GOT_25c; else next = GOT_20c; GOT_25c: if (Q) next = GOT_50c; else if (D) next = GOT_35c; else if (N) next = GOT_30c; else next = GOT_25c; GOT_30c: next = IDLE; GOT_35c: next = RETURN_5c; GOT_40c: next = RETURN_10c; GOT_45c: next = RETURN_15c; GOT_50c: next = RETURN_20c; RETURN_20c: next = RETURN_10c; RETURN_15c: next = RETURN_5c; RETURN_10c: next = IDLE; RETURN_5c: next = IDLE; default: next = IDLE; endcase end

endmodule assign DC = (state == GOT_30c || state == GOT_35c || assign DN = (state == RETURN_5c); assign DD = (state == RETURN_20c || state == RETURN_15c || state == RETURN_10c); endmodule

Simulation of Moore Vender

Coding Alternative: Two Blocks GOT_30c: begin DC = 1; next = IDLE; end GOT_35c: begin DC = 1; next = RETURN_5c; GOT_40c: begin DC = 1; next = RETURN_10c; GOT_45c: begin DC = 1; next = RETURN_15c; GOT_50c: begin DC = 1; next = RETURN_20c; RETURN_20c: begin DD = 1; next = RETURN_10c; RETURN_15c: begin DD = 1; next = RETURN_5c; RETURN_10c: begin DD = 1; next = IDLE; RETURN_5c: begin DN = 1; next = IDLE; default: next = IDLE; endcase always @ (state or N or D or Q) begin DC = 0; DD = 0; DN = 0; // defaults case (state) IDLE: if (Q) next = GOT_25c; else if (D) next = GOT_10c; else if (N) next = GOT_5c; else next = IDLE; GOT_5c: if (Q) next = GOT_30c; else if (D) next = GOT_15c; else if (N) next = GOT_10c; else next = GOT_5c; GOT_10c: if (Q) next = GOT_35c; else if (D) next = GOT_20c; else if (N) next = GOT_15c; else next = GOT_10c; GOT_15c: if (Q) next = GOT_40c; else if (D) next = GOT_25c; else if (N) next = GOT_20c; else next = GOT_15c; GOT_20c: if (Q) next = GOT_45c; else if (D) next = GOT_30c; else if (N) next = GOT_25c; else next = GOT_20c; GOT_25c: if (Q) next = GOT_50c; else if (D) next = GOT_35c; else if (N) next = GOT_30c; else next = GOT_25c;

FSM Output Glitching FSM state bits may not transition at precisely the same time Combinational logic for outputs may contain hazards Result: your FSM outputs may glitch!

If the soda dispenser is glitch-sensitive, your customers can get a 20-cent soda!

Registered FSM Outputs are Glitch-Free reg DC,DN,DD; // Sequential always block for state assignment always @ (posedge clk or negedge reset) begin if (!reset) state <= IDLE; else if (clk) state <= next; DC <= (next == GOT_30c || next == GOT_35c ||next == GOT_40c || next == GOT_45c ||next == GOT_50c); DN <= (next == RETURN_5c); DD <= (next == RETURN_20c || next == RETURN_15c ||next == RETURN_10c); END

Mealy Vender (covered in Recitation)

Verilog for Mealy FS module mealyVender (N, D, Q, DC, DN, DD, clk, reset, state); input N, D, Q, clk, reset; output DC, DN, DD; reg DC, DN, DD; output [3:0] state; reg [3:0] state, next; parameter IDLE = 0; parameter GOT_5c = 1; parameter GOT_10c = 2; parameter GOT_15c = 3; parameter GOT_20c = 4; parameter GOT_25c = 5; parameter RETURN_20c = 6; parameter RETURN_15c = 7; parameter RETURN_10c = 8; parameter RETURN_5c = 9; // Sequential always block for state assignment always @ (posedge clk or negedge reset) if (!reset) state <= IDLE; else state <= next;

endmodule always @ (state or N or D or Q) begin case (state) DC = 0; DN = 0; DD = 0; // defaults case (state) IDLE: if (Q) next = GOT_25c; else if (D) next = GOT_10c; else if (N) next = GOT_5c; else next = IDLE; GOT_5c: if (Q) begin DC = 1; next = IDLE; end else if (D) next = GOT_15c; else if (N) next = GOT_10c; else next = GOT_5c; GOT_10c: if (Q) begin DC = 1; next = RETURN_5c; else if (D) next = GOT_20c; else if (N) next = GOT_15c; else next = GOT_10c; GOT_15c: if (Q) begin DC = 1; next = RETURN_10c; else if (D) next = GOT_25c; else if (N) next = GOT_20c; else next = GOT_15c; GOT_20c: if (Q) begin DC = 1; next = RETURN_15c; else if (D) begin else if (N) next = GOT_25c; else next = GOT_20c; GOT_25c: if (Q) begin DC = 1; next = RETURN_20c; end else if (D) begin DC = 1; next = RETURN_5c; else if (N) begin DC = 1; next = IDLE; else next = GOT_25c; RETURN_20c: begin DD = 1; next = RETURN_10c; RETURN_15c: begin DD = 1; next = RETURN_5c; RETURN_10c: begin DD = 1; next = IDLE; RETURN_5c: begin DN = 1; next = IDLE; default: next = IDLE; endcase endmodule

Simulation of Mealy Vender

Summary Synchronize all asynchronous inputs Use two back to back registers Two types of Finite State Machines introduced Moore – Outputs are a function of current state Mealy – outputs a function of current state and input A standard template can be used for coding FSMs Register outputs of combinational logic for critical control signals