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

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

RTL Design (Using ASM/SM Chart)

Quick Introduction to SystemVerilog: Sequental Logic

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

FSM and Efficient Synthesizable FSM Design using Verilog

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

Modeling Sequential Circuits in Verilog

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

ECE 4514 Digital Design II. Spring Lecture 2: Hierarchical Design

Synthesizable Verilog

Verilog for Synthesis Ing. Pullini Antonio

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

Sequential Logic Implementation. Mealy vs. Moore Machines. Specifying Outputs for a Mealy Machine. Specifying Outputs for a Moore Machine

ECE 551: Digital System *

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

Sequential Logic Design

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

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

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

Finite State Machines

Synthesis of Combinational and Sequential Circuits with Verilog

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

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

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

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

EECS 270 Verilog Reference: Sequential Logic

Mealy and Moore examples

Why Should I Learn This Language? VLSI HDL. Verilog-2

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

Finite-State Machine (FSM) Design

Problem Set 2 Solutions

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

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

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

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

Lecture 32: SystemVerilog

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

Parallel versus serial execution

Verilog HDL. Lecture #6. Madhu Mutyam Dept. of Computer Science and Engineering Indian Institute of Technology, Madras

Verilog Tutorial. Introduction. T. A.: Hsueh-Yi Lin. 2008/3/12 VLSI Digital Signal Processing 2

Techniques for Digital Systems Lab. Verilog HDL. Tajana Simunic Rosing. Source: Eric Crabill, Xilinx

Digital Integrated Circuits

CSE140L: Components and Design Techniques for Digital Systems Lab

Digital Design with SystemVerilog

Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

CSE140L: Components and Design

Verilog for High Performance

Lecture 15: System Modeling and Verilog

Writing Circuit Descriptions 8

Register Transfer Level

EEL 4783: HDL in Digital System Design

Chapter 5 Registers & Counters

Digital Integrated Circuits

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

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

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

EECS150 - Digital Design Lecture 10 Logic Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

Digital Circuits and Systems

VHDL VS VERILOG.

Nonblocking Assignments in Verilog Synthesis; Coding Styles That Kill!

CAD for VLSI Design - I. Lecture 21 V. Kamakoti and Shankar Balachandran

Lecture #2: Verilog HDL

Midterm Exam Thursday, October 24, :00--2:15PM (75 minutes)

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay Dept of CSE, IIT Madras 1

Registers and finite state machines

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Finite State Machines

Last Lecture: Divide by 3 FSM

Modeling of Finite State Machines. Debdeep Mukhopadhyay

ECE Digital Design Laboratory. Lecture 3 Finite State Machines!

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

Testbenches for Sequential Circuits... also, Components

Verilog Nonblocking Assignments with Delays - Myths & Mysteries

CS6710 Tool Suite. Verilog is the Key Tool

Chap 6 Introduction to HDL (d)

Register Transfer Level in Verilog: Part I

EN164: Design of Computing Systems Lecture 06: Lab Foundations / Verilog 2

Designing Safe Verilog State Machines with Synplify

DESCRIPTION OF DIGITAL CIRCUITS USING VHDL

Control in Digital Systems

EECS Components and Design Techniques for Digital Systems. Lec 07 PLAs and FSMs 9/ Big Idea: boolean functions <> gates.

Digital Design with FPGAs. By Neeraj Kulkarni

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

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

Lectures 11 & 12: Synchronous Sequential Circuits Minimization

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

271/471 Verilog Tutorial

Verilog. What is Verilog? VHDL vs. Verilog. Hardware description language: Two major languages. Many EDA tools support HDL-based design

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

Verilog Tutorial. Verilog Fundamentals. Originally designers used manual translation + bread boards for verification

Verilog Tutorial 9/28/2015. Verilog Fundamentals. Originally designers used manual translation + bread boards for verification

IT T35 Digital system desigm y - ii /s - iii

Verilog introduction. Embedded and Ambient Systems Lab

Digital Design Using Verilog EE Final Examination

Finite State Machines

Introduction to Verilog and ModelSim. (Part 6 State Machines)

L5: Simple Sequential Circuits and Verilog

Transcription:

Blocking(=) vs Nonblocking (<=) Assignment Lecture 3: Modeling Sequential Logic in Verilog HDL always @ (b) a = b; c = a; final value: a = b =c always @(posedge clk) a <= b; c <= a; final value: a = b c = old a 2 Use non-blocking for flip flop inference posedge/negedge require nonblocking always @ (posedge clock) b <= a; //swap a and b a <= b; If using blocking for flipflop inference, we may not get what you want. always @(posedge clock) b = a; a = b; // b=a, a=a 3 Procedural assignments Blocking assignment = Regular assignment inside procedural block Assignment takes place immediately LHS must be a register Nonblocking assignment <= Compute RHS Assignment takes place at of block LHS must be a register 4

Execution order at Q (in any order) Evaluate RHS of all non-blocking assignments Evaluate RHS and change LHS of all blocking assignments (execution of all blocking assignments is in order) Evaluate RHS and change LHS of all continuous assignments Evaluate inputs and change outputs of all primitives at Q2 Change LHS of all non-blocking assignments at the same time All non-blocking assignments are evaluated using the values the variables have when your design entered the always block. Non-blocking assignment is also known as an RTL assignment if used in an always block triggered by a clock edge all flipflops change together always @(posedge clk) B = A; C = B; D = C; //what does this circuit do? B=A, C=A, D=A always @(posedge clk) B <= A; C <= B; D <= C; //What does this circuit do? a shift register 5 6 Finite State Machine Review A finite state machine has a state register that holds current state some combinational logic that calculates the next state and outputs based on the current state and/or the current inputs Moore machine: output based on current state inputs combinational logic for next state logic for reg outputs outputs state feedback Mealy machine: based on current state and inputs A finite state machine is a feedback system which updates on each clock. inputs logic for outputs combinational logic for next state reg outputs state feedback 7 8 2

Comparison of Mealy and Moore machines Mealy machines t to have less states different outputs on arcs (n 2 ) rather than states (n) Moore machines are safer to use outputs change at clock edge (always one cycle later) in Mealy machines, input change can cause output change as soon as logic is done a big problem when two machines are interconnected asynchronous feedback may occur if one isn t careful Mealy machines react faster to inputs react in same cycle don't need to wait for clock in Moore machines, more logic may be necessary to decode state into outputs more gate delays after clock edge Finite State Machine Design Determine inputs/output Determine machine types (Mealy vs. Moore) Determine machine flow (state diagram) State assignment Implementation 9 A Moore Machine Output Z 2 Z Z Using D flip flops next state logic D = Q x + Q 3 x + Q x D = Q 2 x D 2 = Q x + Q x D 3 = Q 2 x + Q 3 x Output Logic Z 2 =Q 2 ; Z =Q 2 ; Z =Q 2 +Q input x Using D Flip Flops one-hot encoding State Q 3 Q 2 Q Q A B C D Write a complete structural Verilog model of this simple Moore machine. module DFF(q, d, clk, reset, preset); input d, clk, reset, preset; output q; reg q; always @(posedge clk or negedge reset or negedge preset) if (~reset) q <= ; else if (~preset) q <= ; else q <= d; module 2 3

module clock (clk); output clk; reg clk; initial # clk=; always # clk = ~clk; module module OneHotNS(D, Q, x); input x; input [3:] Q; output [3:] D; reg [3:] D; always @(Q or x) D[3] = (Q[2] & x) (Q[3] & ~x); D[2] =(Q[] & ~x) (Q[] & x); D[]= Q[2] & ~x; D[] = (Q[] & ~x) (Q[] & x) (Q[3] & x); module 3 4 module OneHotOutput(Z, Q); input [3:] Q; output [2:] Z; reg [2:] Z; always @ (Q) Z[2] = Q[2]; Z[] = ~Q[2]; Z[] = Q[2] Q[]; module module OneHotFSM(Z, x, clk, reset); input x, clk, reset; output [2:] Z; wire [3:] D, Q; DFF OneHotD3(Q[3], D[3], clk, reset, b), OneHotD2(Q[2], D[2], clk, reset, b), OneHotD(Q[], D[], clk, reset, b), OneHotD(Q[], D[], clk, b, reset); OneHotNS OneHotOutput module NextStateUnit(D, Q, x); OutputUnit(Z, Q); 5 6 4

module testbench (Z, x, clk, reset); input [2:] Z; input clk; output x, reset; reg x, reset; reg[:] data; integer i; initial $monitor ($time,, Z = %b, x = %b, clock= %b, Z, x, clk); reset = ; data = 2 b; // x = (from L to R) # reset = ; for (i = ; i <= ; i = i + ) x = data[i]; #2; # $finish; module 7 module system wire clk, reset, x; wire [2:] Z; testbench testunit (Z, x, clk, reset); clock clockunit (clk); OneHotFSM FSMunit(Z, x, clk, reset); module 8 Z =, x = x, clock= x Z =, x =, clock= Z =, x =, clock= 2 Z =, x =, clock= 3 Z =, x =, clock= 4 Z =, x =, clock= 4 Z =, x =, clock= 5 Z =, x =, clock= 6 Z =, x =, clock= 6 Z =, x =, clock= 7 Z =, x =, clock= 8 Z =, x =, clock= 8 Z =, x =, clock= 9 Z =, x =, clock= Z =, x =, clock= Z =, x =, clock= 2 Z =, x =, clock= 9 2 Z =, x =, clock= 3 Z =, x =, clock= 4 Z =, x =, clock= 4 Z =, x =, clock= 5 Z =, x =, clock= 6 Z =, x =, clock= 7 Z =, x =, clock= 8 Z =, x =, clock= 8 Z =, x =, clock= 9 Z =, x =, clock= 2 Z =, x =, clock= 2 Z =, x =, clock= 2 Z =, x =, clock= 22 Z =, x =, clock= 23 Z =, x =, clock= 24 Z =, x =, clock= 2 5

Another finite state machine given the state transition diagram module sfsm (clk, reset, in, out); input clk, reset, in; output out; parameter zero = 2 b; parameter one = 2 b; parameter twos = 2 b; reg out; reg [2:] state; // state variables reg [2:] next_state; always @(posedge clk) if (reset) state <= zero; else state <= next_state; zero [] one [] twos [] 2 always @(in or state) // generate Next State case (state) zero: //last input was a zero if (in) next_state = one; else next_state = zero; one: // we've seen one if (in) next_state = twos; else next_state = zero; twos: // we've seen at least 2 ones if (in) next_state = twos; else next_state = zero; case zero [] one [] twos [] always @(state) case (state) zero: out = ; one: out = ; twos: out = ; case module 22 A Mealy Machine An always block for a combinational function. A module can have more than one of these always blocks. Partition a design into several modules Tools optimize each module separately always @(state) case (state) zero: out = ; one: out = ; twos: out = ; case Combining several modules into one module, tools optimize this single module. Binary encoding state A = ; state B = ; state C=; state D = 23 24 6

module mealyfsm (out, x, clk, reset); input x, clk, reset; output [:] out; reg [:] out, curstate, nextstate; parameter [:] A=, B=, C=2, D=3; // state transition always @(posedge clk or negedge reset) $display( ); if (~reset) curstate <= ; $display ( state ); else curstate <= nextstate; $display ( state %d, nextstate); 25 // next state logic and output logic combinational always @(curstate or x) case (curstate) A: out = 3; nextstate = D; B: out = ( x ==)? 2 : ; nextstate = ( x == )? A : D; C: out = (x == )? : ; nextstate = (x == )? B : D; D: out = ( x == )? : ; nextstate = ( x== )? C : D; case module 26 module clock(clk); output clk; reg clk; initial clk = ; always # clk = ~clk; module module testbench (out, x, clk, reset); output x, reset; input [:] out; input clk; reg x, reset; reg[:] data; integer I; initial $monitor ($time,, clk = %b, x = %b, out = %d, clk, x, out); reset = ; // set state to A data = 2 b; # reset = ; for ( i = ; i >= ; i = i -) x = data[i]; #2; $finish; module 27 28 7

module system; wire [:] out; wire x, clk, reset; mealyfsm clock testbench module M(out, x, clk, reset); timer(clk); test(out, x, clk, reset); 29 state clk =, x = x, out = 3 clk =, x =, out = 3 clk =, x =, out = 2 clk =, x =, out = 2 clk =, x =, out = 3 clk =, x =, out = 4 clk =, x =, out = 5 clk =, x =, out = 6 clk =, x =, out = 6 clk =, x =, out = state 2 7 clk =, x =, out = 8 clk =, x =, out = 8 clk =, x =, out = copied from Silos output window 3 9 clk =, x =, out = clk =, x =, out = clk =, x =, out = state 2 clk =, x =, out = 2 clk =, x =, out = state 3 clk =, x =, out = 2 4 clk =, x =, out = 2 4 clk =, x =, out = 5 clk =, x =, out = 6 clk =, x =, out = 6 clk =, x =, out = state 2 7 clk =, x =, out = 8 clk =, x =, out = state 9 clk =, x =, out = 2 2 clk =, x =, out = 2 state 2 clk =, x =, out = 3 22 clk =, x =, out = 3 23 clk =, x =, out = 24 clk =, x =, out = 3 8