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

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

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

N-input EX-NOR gate. N-output inverter. N-input NOR gate

Verilog Behavioral Modeling

CSE 591: Advanced Hardware Design and Verification (2012 Spring) LAB #0

Nikhil Gupta. FPGA Challenge Takneek 2012

Schematic design. Gate level design. 0 EDA (Electronic Design Assistance) 0 Classical design. 0 Computer based language

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

Lab 7 (All Sections) Prelab: Introduction to Verilog

Synthesizable Verilog

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog

Behavioral Modeling and Timing Constraints

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

DIGITAL SYSTEM DESIGN

VERILOG. Deepjyoti Borah, Diwahar Jawahar

CS232 VHDL Lecture. Types

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Hardware Description Languages (HDLs) Verilog

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

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

Register Transfer Level in Verilog: Part I

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

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

Behavioral Modeling and Timing Constraints

Introduction. Purpose. Intended Audience. Conventions. Close

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

structure syntax different levels of abstraction

Here is a list of lecture objectives. They are provided for you to reflect on what you are supposed to learn, rather than an introduction to this

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

- 1 of 18 - The Verilog Hardware Description Language - A Behavioural View Overview. The Behavioural Model

Modeling Sequential Circuits in Verilog

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and

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

Course Topics - Outline

Spiral 1 / Unit 4 Verilog HDL. Digital Circuit Design Steps. Digital Circuit Design OVERVIEW. Mark Redekopp. Description. Verification.

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

ECE 551: Digital System *

Introduction. Why Use HDL? Simulation output. Explanation

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

Synthesis of Combinational and Sequential Circuits with Verilog

VLSI Design 13. Introduction to Verilog

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

VERILOG: FLIP-FLOPS AND REGISTERS

Chapter 5 Registers & Counters

Lab #1. Topics. 3. Introduction to Verilog 2/8/ Programmable logic. 2. Design Flow. 3. Verilog --- A Hardware Description Language

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

ECEN 468 Advanced Digital System Design

EECS150 - Digital Design Lecture 10 Logic Synthesis

Advanced Verilog Coding

Verilog for High Performance

Federal Urdu University of Arts, Science and Technology, Islamabad VLSI SYSTEM DESIGN. Prepared By: Engr. Yousaf Hameed.

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

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

VHDL: RTL Synthesis Basics. 1 of 59

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

ARM 64-bit Register File

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

CSE140L: Components and Design Techniques for Digital Systems Lab

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATIONS ENGINEERING

EN2911X: Reconfigurable Computing Lecture 05: Verilog (2)

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

Writing Circuit Descriptions 8

Control in Digital Systems

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Combinational Logic II

Introduction to Digital Design with Verilog HDL

CSE140L: Components and Design

MLR Institute of Technology

A Brief Introduction to Verilog Hardware Definition Language (HDL)

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

Contents. Appendix D Verilog Summary Page 1 of 16

Verilog Lecture Gandhi Puvvada, USC always statements, Coding a Flip-Flop. blocking and non-blocking assignments. Copyright 2008 Gandhi Puvvada 1

Lecture 2 Hardware Description Language (HDL): VHSIC HDL (VHDL)

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

Finite State Machines

Sequential Statement

271/471 Verilog Tutorial

Finite-State Machine (FSM) Design

RTL Design (Using ASM/SM Chart)

A Tutorial Introduction 1

Digital Logic Design Lab

Digital Integrated Circuits

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

Verilog for Synthesis Ing. Pullini Antonio

Two HDLs used today VHDL. Why VHDL? Introduction to Structured VLSI Design

Verilog 1 - Fundamentals

Sequential Logic Blocks

EEL 4783: HDL in Digital System Design

Sunburst Design - Verilog-2001 Design & Best Coding Practices by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

Introduction to Verilog

Computer Aided Design Basic Syntax Gate Level Modeling Behavioral Modeling. Verilog

EECS 270 Verilog Reference: Sequential Logic

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

ECE UMass, Amherst. Verilog tutorial

Verilog Design Principles

Transcription:

Name: Instructor: Engr. Date Performed: Marks Obtained: /10 Group Members (ID):. Checked By: Date: Experiment # 11 Introduction to Verilog II Sequential Circuits OBJECTIVES: To understand the concepts related to behavioral modeling. To understand the concepts related to the types of logic circuits for Digital Systems i.e. Combinational & Sequential. Required Components and Equipment: A Computer Veriwell Software Introduction HDL (Hardware Description Language) is any language from a class of computer languages, specification languages, or modeling languages for formal description and design of electronic circuits, and most-commonly, digital logic. It can describe the circuit's operation, its design and organization, and tests to verify its operation by means of simulation. The two most popular HDLs are Verilog and VHDL. Verilog due to its similarity to C language is easier to understand so has become most widely used HDL in educational institutions. HDL Coding Verilog is both a behavioral and a structural language. Internals of each module can be defined at four levels of abstraction, deping on the needs of the design. The module behaves identically with the external environment irrespective of the level of abstraction at which the module is described. The internals of the module are hidden from the environment. Thus, the level of abstraction to describe a module can be changed without any change in the environment. The levels are defined below. Behavioral or algorithmic level Dataflow level Gate level Switch level

Behavioral Modeling Verilog provides designers the ability to describe design functionality in an algorithmic manner. In other words, the designer describes the behavior of the circuit. Thus, behavioral modeling represents the circuit at a very high level of abstraction. Design at this level resembles C programming more than it resembles digital circuit design. Behavioral Verilog constructs are similar to C language constructs in many ways. Verilog is rich in behavioral constructs that provide the designer with a great amount of flexibility. Structured Procedures There are two structured procedure statements in Verilog: always and. These statements are the two most basic statements in behavioral modeling. All other behavioral statements can appear only inside these structured procedure statements. Verilog is a concurrent programming language unlike the C programming language, which is sequential in nature. Activity flows in Verilog run in parallel rather than in sequence. Each always and statement represents a separate activity flow in Verilog. Each activity flow starts at simulation time 0. The statements always and cannot be nested. The fundamental difference between the two statements is explained in the following sections. a) Statement All statements inside an statement constitute an block. An block starts at time 0, executes exactly once during a simulation, and then does not execute again. If there are multiple blocks, each block starts to execute concurrently at time 0. Each block finishes execution indepently of other blocks. Multiple behavioral statements must be grouped; typically using the keywords and. If there is only one behavioral statement, grouping is not necessary. This is similar to the { } grouping in the C programming language. Example: m = 1'b0; //single statement; does not need to be grouped #5 a = 1'b1; //multiple statements; need to be grouped #25 b = 1'b0; #10 x = 1'b0; #25 y = 1'b1; #50 $finish; In the above example, the three statements start to execute in parallel at time 0. If a delay #<delay> is seen before a statement, the statement is executed <delay> time units after the current simulation time. Thus, the execution sequence of the statements inside the blocks will be as follows.

The blocks are typically used for ization, monitoring, waveforms and other processes that must be executed only once during the entire simulation run. b) always Statement All behavioral statements inside an always statement constitute an always block. The always statement starts at time 0 and executes the statements in the always block continuously in a looping fashion. This statement is used to model a block of activity that is repeated continuously in a digital circuit. An example is a clock generator module that toggles the clock signal every half cycle. In real circuits, the clock generator is active from time 0 to as long as the circuit is powered on. Example: //Initialize clock at time zero clock = 1'b0; //Toggle clock every half-cycle (time period = 20) always #10 clock = ~clock; #1000 $finish; In the example, the always statement starts at time 0 and executes the statement clock = ~clock every 10 time units. Notice that the ization of clock has to be done inside a separate statement. If we put the ization of clock inside the always block, clock will be ized every time the always is entered. Also, the simulation must be halted inside an statement. If there is no $stop or $finish statement to halt the simulation, the clock generator will run forever. C programmers might draw an analogy between the always block and an infinite loop. But hardware designers t to view it as a continuously repeated activity in a digital circuit starting from power on. The activity is stopped only by power off ($finish) or by an interrupt ($stop).

Sequential Logic Circuit Sequential circuits employ storage elements in addition to logic gates. Their outputs are a function of the inputs and the state of the storage elements. Because the state of the storage elements is a function of the previous inputs, the outputs of the sequential circuit dep not only on present values of inputs, but also on past inputs, and the circuit behavior must be specified by a time sequence of inputs and internal states. Examples are Register, Counter etc. There are two main types of sequential circuits and their classification deps on the timings of their signals. A synchronous sequential circuit is a system whose behavior can be defined from the knowledge of its signal at discrete instants of time. The behavior of asynchronous sequential circuit deps upon the input signals at any instant of time and the order in which the inputs change. The asynchronous sequential circuits are also regarded as a combinational circuit with feedback. Register Transfer Level In the digital design community, the term register transfer level (RTL) is frequently used for a Verilog Description that uses a combination of behavioral and dataflow constructs and is acceptable to logic synthesis tools. Due to the wide usage of the term RTL, the module code files (containing a hardware description code) written using any level of abstraction are also known as RTL code file. Procedural Assignment Procedural assignments update values of reg, integer, real, or time variables. The value placed on a variable will remain unchanged until another procedural assignment updates the variable with a different value. These are unlike continuous assignments discussed in Dataflow Modeling, where one assignment statement can cause the value of the right-hand-side expression to be continuously placed onto the left-hand-side net. The syntax for the simplest form of procedural assignment is shown below. assignment ::= variable_lvalue = [ delay_or_event_control ] expression The left-hand side of a procedural assignment <lvalue> can be one of the following: A reg, integer, real, or time register variable or a memory element A bit select of these variables (e.g., addr[0]) A part select of these variables (e.g., addr[31:16]) A concatenation of any of the above The right-hand side can be any expression that evaluates to a value. In behavioral modeling, all operators discussed in Dataflow Modeling can be used in behavioral expressions. There are two types of procedural assignment statements: blocking and Non-Blocking.

a) Blocking Assignments Blocking assignment statements are executed in the order they are specified in a sequential block. A blocking assignment will not block execution of statements that follow in a parallel block. The = operator is used to specify blocking assignments. Example: Blocking Statements reg x, y, z; reg [15:0] reg_a, reg_b; integer count; //All behavioral statements must be inside an or always block x = 0; y = 1; z = 1; //Scalar assignments count = 0; //Assignment to integer variables reg_a = 16'b0; reg_b = reg_a; //ize vectors #15 reg_a[2] = 1'b1; //Bit select assignment with delay #10 reg_b[15:13] = {x, y, z}; //Assign result of concatenation to // part select of a vector count = count + 1; //Assignment to an integer (increment) In above example, the statement y = 1 is executed only after x = 0 is executed. The behavior in a particular block is sequential in a - block if blocking statements are used, because the statements can execute only in sequence. The statement count = count + 1 is executed last. The simulation times at which the statements are executed are as follows: All statements x = 0 through reg_b = reg_a are executed at time 0 Statement reg_a[2] = 0 at time = 15 Statement reg_b[15:13] = {x, y, z} at time = 25 Statement count = count + 1 at time = 25 Since there is a delay of 15 and 10 in the preceding statements, count = count + 1 will be executed at time = 25 units Note that for procedural assignments to registers, if the right-hand side has more bits than the register variable, the right-hand side is truncated to match the width of the register variable. The least significant bits are selected and the most significant bits are discarded. If the right-hand side has fewer bits, zeros are filled in the most significant bits of the register variable. b) Non-Blocking Assignments Non-Blocking assignments allow scheduling of assignments without blocking execution of the statements that follow in a sequential block. A <= operator is used to specify Non-Blocking assignments. Note that this operator has the same symbol as a relational operator, less_than_equal_to. The operator <= is interpreted as a relational operator in an expression and as an assignment operator in the context of a Non-Blocking assignment. To illustrate the behavior of Non-Blocking statements and its difference from blocking statements, let us consider the following example.

Example: Non-Blocking Assignments reg x, y, z; reg [15:0] reg_a, reg_b; integer count; //All behavioral statements must be inside an or always block x = 0; y = 1; z = 1; //Scalar assignments count = 0; //Assignment to integer variables reg_a = 16'b0; reg_b = reg_a; //Initialize vectors reg_a[2] <= #15 1'b1; //Bit select assignment with delay reg_b[15:13] <= #10 {x, y, z}; //Assign result of concatenation //to part select of a vector count <= count + 1; //Assignment to an integer (increment) In this example, the statements x = 0 through reg_b = reg_a are executed sequentially at time 0. Then the three Non-Blocking assignments are processed at the same simulation time. reg_a[2] = 0 is scheduled to execute after 15 units (i.e., time = 15) reg_b[15:13] = {x, y, z} is scheduled to execute after 10 time units (i.e., time = 10) count = count + 1 is scheduled to be executed without any delay (i.e., time = 0) Thus, the simulator schedules a Non-Blocking assignment statement to execute and continues to the next statement in the block without waiting for the Non-Blocking statement to complete execution. Typically, Non-Blocking assignment statements are executed last in the time step in which they are scheduled, that is, after all the blocking assignments in that time step are executed. In the example above, we mixed blocking and Non-Blocking assignments to illustrate their behavior. However, it is recommed that blocking and Non-Blocking assignments not be mixed in the same always block. Application of Non-Blocking assignments Having described the behavior of Non-Blocking assignments, it is important to understand why they are used in digital design. They are used as a method to model several concurrent data transfers that take place after a common event. Consider the following example where three concurrent data transfers take place at the positive edge of clock. Consider the following example which is inted to swap the values of registers a and b at each positive edge of clock, using two concurrent always blocks.

//Illustration 1: Two concurrent always blocks with blocking //statements always @(posedge clock) a = b; always @(posedge clock) b = a; //Illustration 2: Two concurrent always blocks with Non-Blocking //statements always @(posedge clock) a <= b; always @(posedge clock) b <= a; In the above example, in Illustration 1, there is a race condition when blocking statements are used. Either a = b would be executed before b = a, or vice versa, deping on the simulator implementation. Thus, values of registers a and b will not be swapped. Instead, both registers will get the same value (previous value of a or b), based on the Verilog simulator implementation. However, Non-Blocking statements used in Illustration 2 eliminate the race condition. At the positive edge of clock, the values of all right-hand-side variables are "read," and the right-handside expressions are evaluated and stored in temporary variables. During the write operation, the values stored in the temporary variables are assigned to the left-handside variables. Separating the read and write operations ensures that the values of registers a and b are swapped correctly, regardless of the order in which the write operations are performed. Verilog Codes (to be utilized in this lab): D Flip-Flop: // D flip-flop module dff (clk, reset,d, q, qb); input clk,reset,d; output q,qb; reg q; assign qb = ~q; always @(posedge clk or posedge reset) if (reset) // Asynchronous reset when reset goes high q <= 1'b0; else q <= d; // Assign D to Q on positive clock edge

module Stimulus: // Testbench module test; reg clk; reg reset; reg d; wire q; wire qb; // Instantiate design under test dff DFF(.clk(clk),.reset(reset),.d(d),.q(q),.qb(qb)); $monitor(reset,clk,d,q,qb); clk = 0;reset = 0;d = 1'bx; #5 clk = 0;reset = 1;d = 1'bx; #5 d = 1; reset = 0; #5 clk = 1; module Student s Task: Write the Verilog code for J-K flip flop. Write Verilog code for T-flip flop.