Verilog 1 - Fundamentals

Similar documents
Verilog 1 - Fundamentals

Image Courtesy CS250 Section 2. Yunsup Lee 9/4/09

Course Details: Webpage

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

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

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

Chapter 2 Using Hardware Description Language Verilog. Overview

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

FPGA: FIELD PROGRAMMABLE GATE ARRAY Verilog: a hardware description language. Reference: [1]

Chapter 4 :: Topics. Introduction. SystemVerilog. Hardware description language (HDL): allows designer to specify logic function only.

Lecture 32: SystemVerilog

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

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

HDLs and SystemVerilog. Digital Computer Design

Synthesizable Verilog

Digital Design with SystemVerilog

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

Contents. Appendix D Verilog Summary Page 1 of 16

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

Hardware Description Languages. Hardware Description Languages. Hardware Description Languages. Digital Design Using Verilog

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

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Lecture 15: System Modeling and Verilog

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

Digital Design with FPGAs. By Neeraj Kulkarni

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Hardware Description Language VHDL (1) Introduction

Verilog for High Performance

Digital Design Using Verilog

CSE140L: Components and Design Techniques for Digital Systems Lab

EEL 4783: HDL in Digital System Design

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

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

CSE140L: Components and Design

Introduction to Verilog HDL. Verilog 1

Chap 6 Introduction to HDL (d)

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

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

What is Verilog HDL? Lecture 1: Verilog HDL Introduction. Basic Design Methodology. What is VHDL? Requirements

a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

Synthesis of Combinational and Sequential Circuits with Verilog

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

VLSI Design 13. Introduction to Verilog

14:332:231 DIGITAL LOGIC DESIGN. Hardware Description Languages

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

A Verilog Primer. An Overview of Verilog for Digital Design and Simulation

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

Verilog Design Principles

Speaker: Shao-Wei Feng Adviser: Prof. An-Yeu Wu Date: 2010/09/28

VERILOG 2: LANGUAGE BASICS

Verilog Behavioral Modeling

Writing Circuit Descriptions 8

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

(System)Verilog Tutorial Aleksandar Milenković

Verilog for Synthesis Ing. Pullini Antonio

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

Design Using Verilog

ENGN1640: Design of Computing Systems Topic 02: Lab Foundations

Online Verilog Resources

Verilog Module 1 Introduction and Combinational Logic

Introduction to Verilog/System Verilog

Modeling Sequential Circuits in Verilog

VERILOG: FLIP-FLOPS AND REGISTERS

DIGITAL SYSTEM DESIGN

Topics. Midterm Finish Chapter 7

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

Course Topics - Outline

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

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

Introduction to Verilog design. Design flow (from the book)

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

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay How it started!

VERILOG HDL. (and C) 1 ENGN3213: Digital Systems and Microprocessors L#5-6

Chapter 5 Registers & Counters

Verilog Design Principles

Lecture #2: Verilog HDL

! ISP (circa 1977) - research project at CMU " Simulation, but no synthesis

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

EECS 427 Lecture 14: Verilog HDL Reading: Many handouts/references. EECS 427 W07 Lecture 14 1

Hardware description language (HDL)

Verilog HDL. Gate-Level Modeling

Digital Design (VIMIAA01) Introduction to the Verilog HDL

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

VERILOG HDL. 1 ENGN3213: Digital Systems and Microprocessors L#5-6

Verilog. Verilog for Synthesis

CHAPTER 2 INTRODUCTION TO VERILOG 2.1 COMPUTER-AIDED DESIGN. Copyrighted material; Do not copy or circulate. Page 46

Hardware Description Languages: Verilog. Quick History of HDLs. Verilog/VHDL. Design Methodology. Verilog Introduction. Verilog.

VHDL for Synthesis. Course Description. Course Duration. Goals

Hardware Description Languages: Verilog

Nonblocking Assignments in Verilog Synthesis; Coding Styles That Kill!

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

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

Course administrative notes. Verilog 2 - Design Examples

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

Transcription:

Verilog 1 - Fundamentals FA FA FA FA module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], 1 b0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); 6.375 Complex Digital Systems Arvind February 6, 2009 L02-1 Verilog Fundamentals History of hardware design languages Data types Structural Verilog Simple behaviors FA FA FA FA module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], 1 b0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); L02-2 1

Originally designers used breadboards for prototyping Solderless Breadboard Number of Gates in Design 10 7 10 6 No symbolic execution or testing Printed circuit board tangentsoft.net/elec/breadboard.html home.cogeco.ca 10 5 10 4 10 3 10 2 10 L02-3 HDLs enabled logic level simulation and testing Manual Gate Level Description Number of Gates in Design 10 7 10 6 10 5 10 4 10 3 10 2 HDL = Hardware Description Language 10 L02-4 2

Designers began to use HDLs for higher level design Behavioral Algorithm Number of Gates in Design 10 7 Register Transfer Level 10 6 10 5 Gate Level Manual HDL models offered precise & executable specification but the translation between the levels remained manual L02-5 10 4 10 3 10 2 10 HDLs led to tools for automatic translation Behavioral Algorithm Manual Register Transfer Level Logic Synthesis Gate Level Auto Place + Route HDLs: Verilog, VHDL Tools: Spice, ModelSim, DesignCompiler, Number of Gates in Design L02-6 10 7 10 6 10 5 10 4 10 3 10 2 10 3

Raising the abstraction further Guarded Atomic Actions GAA Compiler Register Transfer Level Logic Synthesis Gate Level Auto Place + Route Bluespec and associated tools Number of Gates in Design 10 7 10 6 10 5 10 4 10 3 10 2 10 L02-7 The current situation Behavioral Level Bluespec C, C++, SystemC Behavioral RTL Verilog, VHDL, SystemVerilog MATLAB Register Transfer Level Structural RTL Verilog, VHDL, SystemVerilog Logic Synthesis Simulators and other tools are available at all levels but not compilers from the behavioral level to RTL Gate Level L02-8 4

Common misconceptions The only behavioural languages are C, C++ RTL languages are necessarily lower-level than behavioral languages Yes- in the sense that C or SystemC is farther away from hardware No- in the sense that HDLs can incorporate the most advanced language ideas. Bluespec is a modern high-level language and at the same time can describe hardware to the same level of precision as RTL L02-9 Verilog Fundamentals History of hardware design languages Data types Structural Verilog Simple behaviors FA FA FA FA module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], 1 b0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); L02-10 5

Bit-vector is the only data type in Verilog A bit can take on one of four values Value 0 1 X Z Meaning Logic zero Logic one Unknown logic value High impedance, floating An X bit might be a 0, 1, Z, or in transition. We can set bits to be X in situations where we don t care what the value is. This can help catch bugs and improve synthesis quality. L02-11 wire is used to denote a hardware net wire [15:0] instruction; wire [15:0] memory_req; wire [ 7:0] small_net; Absolutely no type safety when connecting nets! instruction memory_req instruction? small_net L02-12 6

Bit literals 4 b10_11 Base format ( d,b,o,h ) Underscores are ignored Decimal number representing size in bits Binary literals 8 b0000_0000 8 b0xx0_1xx1 Hexadecimal literals 32 h0a34_def1 16 haxxx Decimal literals 32 d42 We ll learn how to actually assign literals to nets a little later L02-13 Verilog Fundamentals History of hardware design languages Data types Structural Verilog Simple behaviors FA FA FA FA module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], 1 b0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); L02-14 7

A Verilog module has a name and a port list cout A B 4 4 adder 4 sum Ports must have a direction (or be bidirectional) and a bitwidth module adder( A, B, cout, sum ); input [3:0] A; input [3:0] B; output cout; output [3:0] sum; // HDL modeling of // adder functionality Note the semicolon at the of the port list! L02-15 Alternate syntax cout A B 4 4 adder 4 sum Traditional Verilog-1995 Syntax module adder( A, B, cout, sum ); input [3:0] A; input [3:0] B; output cout; output [3:0] sum; ANSI C Style Verilog-2001 Syntax module adder( input [3:0] A, input [3:0] B, output cout, output [3:0] sum ); L02-16 8

A module can instantiate other modules A B adder FA FA FA FA cout S module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0(... ); FA fa1(... ); FA fa2(... ); FA fa3(... ); a b cin cout FA module FA( input a, b, cin output cout, sum ); // HDL modeling of 1 bit // full adder functionality L02-17 c Connecting modules A B adder FA FA FA FA cout S module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], 1 b0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); Carry Chain L02-18 9

Alternative syntax Connecting ports by ordered list FA fa0( A[0], B[0], 1 b0, c0, S[0] ); Connecting ports by name (compact) FA fa0(.a(a[0]),.b(b[0]),.cin(1 b0),.cout(c0),.sum(s[0]) ); Argument order does not matter when ports are connected by name FA fa0 (.a (A[0]),.cin (1 b0),.b (B[0]),.cout (c0),.sum (S[0]) ); Connecting ports by name yields clearer and less buggy code. L02-19 Verilog Fundamentals History of hardware design languages Data types Structural Verilog Simple behaviors FA FA FA FA module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], 1 b0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); L02-20 10

A module s behavior can be described in many different ways but it should not matter from outside Example: mux4 L02-21 mux4: Gate-level structural Verilog module mux4(input a,b,c,d, input [1:0] sel, output out); wire [1:0] sel_b; not not0( sel_b[0], sel[0] ); not not1( sel_b[1], sel[1] ); wire n0, n1, n2, n3; b d a c sel[1]sel[0] and and0( n0, c, sel[1] ); and and1( n1, a, sel_b[1] ); and and2( n2, d, sel[1] ); and and3( n3, b, sel_b[1] ); wire x0, x1; nor nor0( x0, n0, n1 ); nor nor1( x1, n2, n3 ); wire y0, y1; or or0( y0, x0, sel[0] ); or or1( y1, x1, sel_b[0] ); nand nand0( out, y0, y1 ); out L02-22 11

mux4: Using continuous assignments module mux4( input a, b, c, d input [1:0] sel, output out ); wire out, t0, t1; assign out = ~( (t0 sel[0]) & (t1 ~sel[0]) ); assign t1 = ~( (sel[1] & d) (~sel[1] & b) ); assign t0 = ~( (sel[1] & c) (~sel[1] & a) ); The order of these continuous assignment statements does not matter. They essentially happen in parallel! Language defined operators L02-23 mux4: Behavioral style // Four input multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); assign out = ( sel == 0 )? a : ( sel == 1 )? b : ( sel == 2 )? c : ( sel == 3 )? d : 1 bx; If input is undefined we want to propagate that information. L02-24 12

mux4: Using always block module mux4( input a, b, c, d input [1:0] sel, output out ); reg out, t0, t1; Motivated by simulation always @( a or b or c or d or sel ) t0 = ~( (sel[1] & c) (~sel[1] & a) ); t1 = ~( (sel[1] & d) (~sel[1] & b) ); out = ~( (t0 sel[0]) & (t1 ~sel[0]) ); The order of these procedural assignment statements DOES matter. They essentially happen sequentially! L02-25 Always blocks permit more advanced sequential idioms module mux4( input a,b,c,d input [1:0] sel, output out ); reg out; always @( * ) if ( sel == 2 d0 ) out = a; else if ( sel == 2 d1 ) out = b else if ( sel == 2 d2 ) out = c else if ( sel == 2 d3 ) out = d else out = 1 bx; module mux4( input a,b,c,d input [1:0] sel, output out ); reg out; always @( * ) case ( sel ) 2 d0 : out = a; 2 d1 : out = b; 2 d2 : out = c; 2 d3 : out = d; default : out = 1 bx; case Typically we will use always blocks only to describe sequential circuits L02-26 13

What happens if the case statement is not complete? module mux3( input a, b, c input [1:0] sel, output out ); reg out; always @( * ) case ( sel ) 2 d0 : out = a; 2 d1 : out = b; 2 d2 : out = c; case If sel = 3, mux will output the previous value! What have we created? L02-27 What happens if the case statement is not complete? module mux3( input a, b, c input [1:0] sel, output out ); reg out; always @( * ) We CAN prevent creating state with a default case ( sel ) 2 d0 : out = a; statement 2 d1 : out = b; 2 d2 : out = c; default : out = 1 bx; case L02-28 14

Parameterized mux4 module mux4 #( parameter WIDTH = 1 ) ( input[width-1:0] a, b, c, d input [1:0] sel, output[width-1:0] out ); wire [WIDTH-1:0] out, t0, t1; default value assign t0 = (sel[1]? c : a); assign t1 = (sel[1]? d : b); assign out = (sel[0]? t0: t1); Parameterization is a good practice for reusable modules Writing a muxn is challenging Instantiation Syntax mux4#(32) alu_mux (.a (op1),.b (op2),.c (op3),.d (op4),.sel (alu_mux_sel),.out (alu_mux_out) ); L02-29 Verilog Registers reg Wires are line names they do not represent storage and can be assigned only once Regs are imperative variables (as in C): nonblocking assignment r <= v can be assigned multiple times and holds values between assignments L02-30 15

flip-flops module FF0 (input clk, input d, output reg q); always @( posedge clk ) q <= d; next_x clk D Q X module FF (input clk, input d, input en, output reg q); always @( posedge clk ) if ( en ) q <= d; next_x clk D Q X enable L02-31 flip-flops with reset always @( posedge clk) if (~resetn) Q <= 0; else if ( enable ) Q <= D; synchronous reset always @( posedge clk or negedge resetn) if (~resetn) Q <= 0; else if ( enable ) Q <= D; asynchronous reset next_x clk D Q X enable resetn What is the difference? L02-32 16

Latches versus flip-flops module latch ( input clk, input d, output reg q ); always @( clk or d ) if ( clk ) q <= d; module flipflop ( input clk, input d, output reg q ); always @( posedge clk ) q <= d; Edge-triggered always block L02-33 Register module register#(parameter WIDTH = 1) ( input clk, input [WIDTH-1:0] d, input en, output [WIDTH-1:0] q ); always @( posedge clk ) if (en) q <= d; L02-34 17

Register in terms of Flipflops module register2 ( input clk, input [1:0] d, input en, output [1:0] q ); always @(posedge clk) if (en) q <= d; module register2 ( input clk, input [1:0] d, input en, output [1:0] q ); FF ff0 (.clk(clk),.d(d[0]),.en(en),.q(q[0])); FF ff1 (.clk(clk),.d(d[1]),.en(en),.q(q[1])); Do they behave the same? L02-35 yes Static Elaboration: Generate module register#(parameter WIDTH = 1) ( input clk, input [WIDTH-1:0] d, input en, output [WIDTH-1:0] q ); genvar i; generate for (i =0; i < WIDTH; i = i + 1) : rege genvars disappear after static elaboration Generated names will have rege[i]. prefix FF ff(.clk(clk),.d(d[i]),.en(en),.q(q[i])); generate L02-36 18

Three abstraction levels for functional descriptions Behavioral Algorithm Register Transfer Level Gate Level Manual Logic Synthesis Auto Place + Route V V V Abstract algorithmic description Describes how data flows between state elements for each cycle Low-level netlist of primitive gates Next time Some examples L02-37 19