Introduction to Verilog. Introduction 1)Verilog is one of the hardware description languages (HDL) available in the industry for hardware designing. 2)It.

Slides:



Advertisements
Similar presentations
VERILOG: Synthesis - Combinational Logic Combination logic function can be expressed as: logic_output(t) = f(logic_inputs(t)) Rules Avoid technology dependent.
Advertisements

Verilog HDL -Introduction
Simulation executable (simv)
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Combinational Logic.
Chapter 11 Verilog HDL Application-Specific Integrated Circuits Michael John Sebastian Smith Addison Wesley, 1997.
Table 7.1 Verilog Operators.
Verilog Intro: Part 1.
Combinational Logic with Verilog Materials taken from: Digital Design and Computer Architecture by David and Sarah Harris & The Essentials of Computer.
CSE 341 Verilog HDL An Introduction. Hardware Specification Languages Verilog  Similar syntax to C  Commonly used in  Industry (USA & Japan) VHDL 
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
 HDLs – Verilog and Very High Speed Integrated Circuit (VHSIC) HDL  „ Widely used in logic design  „ Describe hardware  „ Document logic functions.
Introduction to Verilog
Lecture 2: Hardware Modeling with Verilog HDL
1 Lecture 1: Verilog HDL Introduction. 2 What is Verilog HDL? Verilog Hardware Description Language(HDL)? –A high-level computer language can model, represent.
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
ENEE 408C Lab Capstone Project: Digital System Design Verilog Tutorial Class Web Site:
Silicon Programming--Intro. to HDLs1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities.
Reconfigurable Computing (EN2911X, Fall07) Lecture 05: Verilog (1/3) Prof. Sherief Reda Division of Engineering, Brown University
Digital System Design Verilog ® HDL Tasks and Functions Maziar Goudarzi.
University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
B. RAMAMURTHY Hardware Description Language 8/2/
Digital System Design EEE344 Lecture 3 Introduction to Verilog HDL Prepared by: Engr. Qazi Zia, Assistant Professor EED, COMSATS Attock1.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
Lecture 7 Verilog Additional references Structural constructs
Overview Logistics Last lecture Today HW5 due today
Tasks and Functions Programmable Logic Design (40-493) Fall 2001 Computer Engineering Department Sharif University of Technology Maziar Gudarzi.
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
1 VERILOG Fundamentals Workshop סמסטר א ' תשע " ה מרצה : משה דורון הפקולטה להנדסה Workshop Objectives: Gain basic understanding of the essential concepts.
Introduction to FPGA AVI SINGH. Prerequisites Digital Circuit Design - Logic Gates, FlipFlops, Counters, Mux-Demux Familiarity with a procedural programming.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
ECE 2372 Modern Digital System Design
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
CS 3850 Lecture 3 The Verilog Language. 3.1 Lexical Conventions The lexical conventions are close to the programming language C++. Comments are designated.
1 An Update on Verilog Ξ – Computer Architecture Lab 28/06/2005 Kypros Constantinides.
Digital System 數位系統 Verilog HDL Ping-Liang Lai (賴秉樑)  
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Module 1.2 Introduction to Verilog
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Workshop Topics - Outline
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
3/4/20031 ECE 551: Digital System Design * & Synthesis Lecture Set 3 3.1: Verilog - User-Defined Primitives (UDPs) (In separate file) 3.2: Verilog – Operators,
1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities and architectural bodies behavioral,
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Introduction to ASIC flow and Verilog HDL
Introduction to Verilog
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Chapter 3: Dataflow Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 3-1 Chapter 3: Dataflow Modeling.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
1 University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
1 Lecture 1: Verilog HDL Introduction. 2 What is Verilog HDL? Verilog Hardware Description Language(HDL)? –A high-level computer language can model, represent.
Exp#5 & 6 Introduction to Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
Structural Description
Hardware Description Languages: Verilog
An Introduction to Verilog: Transitioning from VHDL
Hardware Description Language
Hardware Description Languages: Verilog
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Hardware Description Language
Hardware Description Language
COE 202 Introduction to Verilog
332:437 Lecture 8 Verilog and Finite State Machines
Hardware Description Language
Hardware Description Language
The Verilog Hardware Description Language
Hardware Description Language
332:437 Lecture 8 Verilog and Finite State Machines
COE 202 Introduction to Verilog
Presentation transcript:

Introduction to Verilog

Introduction 1)Verilog is one of the hardware description languages (HDL) available in the industry for hardware designing. 2)It allows designers to design at Behavior Level, Register Transfer Level (RTL), Gate level and at switch level. 3)Parallel not serial (Not like C language). 4)Verilog can describe everything from single gate to full computer system.

Why use HDL?  Digital systems are highly complex; millions of transistors.  For large digital systems, gate-level design is very difficult to achieve in a short time.  Verilog allows hardware designers to express their designs with behavioral constructs, deferring the details of implementation to a later stage in the final design.  Computer-aided design tools aid in the design process. © Intel P4 Processor Introduced in Million Transistors 1.5GHz Clock

Definition of Module  The is an identifier that uniquely names the module.  The is a list of input, inout and output ports which are used to connect to other modules.  Interface: port and parameter declaration  Body: Internal part of module  Add-ons (optional)

The Module Interface Port List Port Declaration

The Module Interface

Gate Level Modeling  Net-list description  built-in primitives gates module my_gate(OUT1, IN1, IN2); output OUT1; input IN1, IN2; wire X; and (X, IN1, IN2); not (OUT1, X); endmodule X OUT1 IN2 IN1 Internal Signal Any internal net must be defined as wire

Verilog Primitives  Basic logic gates only  and  or  not  buf  xor  nand  nor  xnor  bufif1, bufif0  notif1, notif0

Primitive Pins are Expandable nand (y, in1, in2) ; nand (y, in1, in2, in3) ; nand (y, in1, in2, in3, in4) ;

A Half Adder module hadd (S, C, X, Y); input X, Y; output S, C; xor (S, X, Y); and (C, X, Y); endmodule

A Full Adder module fadd (co, s, a, b, c); input a, b,c ; output co, s ; wire n1, n2, n3; xor (n1, a, b) ; xor (s, n1, c) ; nand (n2, a, b) ; nand (n3,n1, c) ; nand (co, n3,n2) ; endmodule

Instantiation of Modules module fadd (S, C, X, Y, Z); input X, Y, Z; output S, C; wire w1, w2, w3; hadd M1 (w1, w2, X, Y); hadd M2 (S, w3, w1, Z); or (C, w2, w3); endmodule  Here we instantiate hadd twice. i.e., placing two hadd circuits and connecting them.  This full adder is built from two half adders and an OR gate.

Verilog Operators { }concatenation + - * / arithmetic %modulus > >= < <= relational !logical NOT && logical AND ||logical OR ==logical equality !=logical inequality ? :conditional ~bit-wise NOT &bit-wise AND |bit-wise OR ^bit-wise XOR ^~ ~^bit-wise XNOR &reduction AND |reduction OR ~&reduction NAND ~|reduction NOR ^reduction XOR ~^ ^~reduction XNOR <<shift left >>shift right

Basic Verilog

Synthesis and HDLs

Verilog: The Module

Continuous (Dataflow) Assignment

Gate Level Description

Procedural Assignment with always

Verilog Registers

Mix-and-Match Assignments

The case Statement

The Power of Verilog: n-bit Signals

The Power of Verilog: Integer Arithmetic

Dangers of Verilog: Incomplete Specification

Incomplete Specification Infers Latches

Avoiding Incomplete Specification

The Sequential always Block

Importance of the Sensitivity List

Simulation

Blocking vs. Nonblocking Assignments

Assignment Styles for Sequential Logic

Use Nonblocking for Sequential Logic

Simulation

Use Blocking for Combinational Logic

Dangers of Verilog : Priority Logic

Priority Logic

Avoiding (Unintended) Priority Logic

Interconnecting Modules

Module Definitions

Top-Level ALU Declaration

Simulation

More on Module Interconnection

Useful Boolean Operators

Testbenches (ModelSim)

Summary

Read more

Advance Verilog

Parameter Parameters are useful because they can be redefined on a module instance basis. That is, each different instance can have different parameter values. This is particularly useful for vector widths. For example, the following module implements a shifter: module shift (shiftOut, dataIn, shiftCount); parameter width = 4; output [width-1:0] shiftOut; input [width-1:0] dataIn; input [31:0] shiftCount; assign shiftOut = dataIn << shiftCount; endmodule This module can now be used for shifters of various sizes, simply by changing the width parameter.

Define Parameter Value There are two ways to change parameter values from their defaults, defparam statements and module instance parameter assignment.  The defparam statement allows you to change a module instance parameter directly from another module. This is usually used as follows: shift sh1 (shiftedVal, inVal, 7); //instantiation defparam sh1.width = 16; // parameter redefinition  Parameter values can be specified in the module instantiation directly. This is done as follows: shift #(16) sh1 (shiftedVal, inVal, 7); //instance of 16-bit shift module

Task and Function Tasks and functions are declared within modules. The declaration may occur anywhere within the module, but it may not be nested within procedural blocks. The declaration does not have to precede the task or function invocation. Tasks may only be used in procedural blocks. A task invocation, or task enable as it is called in Verilog, is a statement by itself. It may not be used as an operand in an expression. Functions are used as operands in expressions. A function may be used in either a procedural block or a continuous assignment, or indeed, any place where an expression may appear.

Task Tasks may have zero or more arguments, and they may be input, output, or inout arguments. task do_read; input [15:0] addr; output [7:0] value; begin adbus_reg = addr; // put address out adbus_en = 1; // drive address clk) ; // wait for the next clock while clk); // wait for ack value = data_bus; // take returned value adbus_en = 0; // turn off address bus count = count + 1; // how many have we done end endtask

Function In contrast to tasks, no time or delay controls are allowed in a function. Function arguments are also restricted to inputs only. Output and inout arguments are not allowed. The output of a function is indicated by an assignment to the function name. For example, function [15:0] relocate; input [11:0] addr; input [3:0] relocation_factor; begin relocate = addr + (relocation_factor<<12); count = count + 1; // how many have we done end endfunction The above function might be used like this: assign absolute_address = relocate(relative_address, rf);

System Task System tasks are used just like tasks which have been defined with the task... endtask construct. They are distinguished by their first character, which is always a "$". There are many system tasks, but the most common are:  $display, $write, $strobe  $monitor  $readmemh and $readmemb  $stop  $finish

Example of System Task The $write system task is just like $display, except that it does not add a newline character to the output string. Example: $write ($time," array:"); for (i=0; i<4; i=i+1) write(" %h", array[i]); $write("\n"); This would produce the following output: 110 array: 5a5114b a d 4e8a7776

System Function Likewise, system functions are used just like functions which have been defined with the function... endfunction construct. Their first character is also always a "$". There are many system functions, with the most common being:  $time ($stime)  $random  $bitstoreal

Example of System Function The $time system function simply returns the current simulation time. Simulation time is a 64- bit unsigned quantity, and that is what $time is assumed to be when it is used in an expression. $stime (short time) is just like $time, except that it returns a 32-bit value of time. Example: $display ("The current time is %d", $time); $display ($time," now the value of x is %h", x);

Conversion Function $rtoi(real_value) Returns a signed integer, truncating the real value. $itor(int_val) Returns the integer converted to a real value. $realtobits(real_value) Returns a 64-bit vector with the bit representation of the real number. $bitstoreal(bit_value) Returns a real value obtained by interpreting the bit_value argument as an IEEE 754 floating point number. module driver (net_r); output net_r; real r; wire [64:1] net_r = $realtobits(r); endmodule module receiver (net_r); input net_r; wire [64:1] net_r; real r; r = $bitstoreal(net_r); endmodule

XMR Verilog has a mechanism for globally referencing nets, registers, events, tasks, and functions called the cross-module reference, or XMR. This is in marked contrast to VHDL, which rejected the concept. Cross-module references, or hierarchical references as they are sometimes called, can take several different forms:  References to a Different Scope within a Module  References between Modules  Downward Reference  Upward Reference

Hierarchical Module There is a static scope within each module definition with which one can locate any identifier. For example, in the following, module A; reg x; // 1... task B; reg x; // 2 begin... begin: C reg x; // 3... end endtask initial begin: D reg x; // 4... end endmodule

Reference to Scopes within Module there is a module, a task, and two named blocks. There are four distinct registers, each named x within its local scope.

Coding Styles

Memory The following are examples of memory declarations. reg [7:0] memdata[0:255];// bit registers reg [8*6:1] strings[1:10];// 10 6-byte strings reg membits [1023:0];// bit registers The maximum size of a memory is implementation-dependent, but is at least 2^24 (16,777,216) elements.

Access to Memory A memory element is accessed by means of a memory index operation. A memory index looks just like a bit- select: mem[index] Another limitation on memory access is that you can't take a bit-select or part-select of a memory element. Thus, if you want to get the 3rd bit out of the 10th element of a memory, you need to do it in two steps: reg [0:31] temp, mem[1:1024];... temp = mem[10]; bit = temp[3];

Finite State Machine There are two common variations of state machines, Mealy and Moore machines. Mealy machines produce outputs based on both current state and input. Moore machines produce outputs based only on the current state. As you would expect, the Verilog representation of the two types is very similar. Typically, the clock is used to change the state based on the inputs which have been seen up to that point. It is often convenient to think of all the activity of the state machine as taking place on the clock edge: sample inputs compute next state compute outputs change state produce outputs

Finite State Machine Finite state machines are one of the common types of logic designed using Verilog. There are several ways to represent them: Implicit Explicit State machines always have inputs, a state variable or set of variables (sometimes called a state vector), and a clock. The clock does not have to be periodic, but there must be some strobe signal which indicates when the state transition decision should be made.

Implicit Coding An implicit FSM is simply one whose state encoding is done by means of procedural code. In essence, the program counter is the current state variable.

Explicit Coding Representing FSMs explicitly is a better style than implicit coding, both because the code maps well to a state transition table and also because explicit representation is synthesizable.

Explicit Coding The following is an example of using an always block for next state logic. This style is probably more common, but it is really no different than the first version.

Pipeline Pipelines, queues, and FIFOs are common logic structures which are all related, in the sense that data moves from one storage location to another synchronously, based on a strobe signal, usually a clock.

Pipeline Coding module pipeline (out, in, clock); output out; input in, clock; reg out, pipe[1:2]; clock) begin out = pipe[2]; pipe[2] = pipe[1]; pipe[1] = in; end endmodule This code works fine. The only potential problem is that out changes value on the clock edge, so whatever takes it as an input may get the wrong value.

Pipeline Coding A better version would be to use a non-blocking assign: clock) begin out <= pipe[2]; pipe[2] <= pipe[1]; pipe[1] <= in; end Note that with the non-blocking assign, the order of the assignment statements is irrelevent.

Pipe Stage as Separate Module It is common to make a single pipe stage module and use it repetitively, as follows:

Combinational Logic in Pipeline It is more interesting if there is some combinational logic associated with each pipe stage. Suppose each stage has some logic represented by a function f1, f2, f3 which is applied to the input.

Race Condition The implication of all this is that you had better not write Verilog code which has a different result depending on the order of execution of simultaneous, unordered events. This is known generally as a race condition, and it occurs when one event samples a data value, another event changes the data value, and the two events are unordered with respect to each other. Example: clock) dff1 = f(x); clock) dff2 = dff1; This attempt at a pipeline doesn't work, because the value of dff2 may be either the old or the new value of dff1