HDLs and SystemVerilog. Digital Computer Design

Similar documents
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>

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

Lecture 32: SystemVerilog

(System)Verilog Tutorial Aleksandar Milenković

Digital Design with SystemVerilog

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

ENGIN 241 Digital Systems with Lab

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

Digital Design with FPGAs. By Neeraj Kulkarni

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

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

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

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

Topics. Midterm Finish Chapter 7

Digital Design with SystemVerilog

Synthesizable Verilog

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

Contents. Appendix D Verilog Summary Page 1 of 16

Sequential Logic Design

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

Verilog 1 - Fundamentals

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

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

Lecture 7. Standard ICs FPGA (Field Programmable Gate Array) VHDL (Very-high-speed integrated circuits. Hardware Description Language)

CSE140L: Components and Design Techniques for Digital Systems Lab

Verilog for High Performance

Verilog introduction. Embedded and Ambient Systems Lab

Lecture 12 VHDL Synthesis

CSE140L: Components and Design

A Brief Introduction to Verilog Hardware Definition Language (HDL)

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

EEL 4783: HDL in Digital System Design

Lecture #2: Verilog HDL

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

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

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

An Introduction to Verilog David Harris

Verilog 1 - Fundamentals

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

ELCT 501: Digital System Design

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

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

ECE 353 Lab 3 (Verilog Design Approach)

VHDL for Synthesis. Course Description. Course Duration. Goals

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

Verilog for Synthesis Ing. Pullini Antonio

Verilog Module 1 Introduction and Combinational Logic

Verilog Design Principles

Design Using Verilog

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Combinational Circuits

Verilog Hardware Description Language ROOM: B405

HDL. Hardware Description Languages extensively used for:

Hardware Description Language VHDL (1) Introduction

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

Quick Introduction to SystemVerilog: Sequental Logic

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

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb UMass Amherst Fall 2017

Chapter 2 Using Hardware Description Language Verilog. Overview

Veriolog Overview. CS/EE 3710 Fall 2010

Last Lecture: Adder Examples

Synthesis of Combinational and Sequential Circuits with Verilog

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

Topics. Midterm Finish Chapter 7

Digital Design (VIMIAA01) Introduction to the Verilog HDL

VERILOG 2: LANGUAGE BASICS

EECS150 - Digital Design Lecture 10 Logic Synthesis

ENGN1640: Design of Computing Systems Topic 02: Lab Foundations

Chap 6 Introduction to HDL (d)

Introduction to Verilog HDL. Verilog 1

Lecture 15: System Modeling and Verilog

EECS 470 Lab 1. Verilog: Hardware Description Language

CS6710 Tool Suite. Verilog is the Key Tool

EECS 470 Lab 1. Verilog: Hardware Description Language

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

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

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

Readings: Storage unit. Can hold an n-bit value Composed of a group of n flip-flops. Each flip-flop stores 1 bit of information.

CSE 502: Computer Architecture

This Lecture. Some components (useful for the homework) Verilog HDL (will continue next lecture)

Homework deadline extended to next friday

Writing Circuit Descriptions 8

Verilog Design Principles

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

Hardware Description Languages: Verilog

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

Chapter 6 Combinational-Circuit Building Blocks

FPGA for Complex System Implementation. National Chiao Tung University Chun-Jen Tsai 04/14/2011

EECS150 - Digital Design Lecture 7 - Computer Aided Design (CAD) - Part II (Logic Simulation) Finite State Machine Review

Testbenches for Sequential Circuits... also, Components

ECE 545 Lecture 5. Data Flow Modeling in VHDL. George Mason University

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

KING FAHD UNIVERSITY OF PETROLEUM & MINERALS COMPUTER ENGINEERING DEPARTMENT

E85: Digital Design and Computer Engineering Lab 2: FPGA Tools and Combinatorial Logic Design

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

271/469 Verilog Tutorial

Hardware description languages

Transcription:

HDLs and SystemVerilog Digital Computer Design

Logic Arrays Gates can be organized into regular arrays. If the connections are made programmable, these logic arrays can be configured to perform any function without the user having to connect wires in specific ways. Software tools allow users to map logic designs onto these arrays. Two types of logic arrays: programmable logic arrays (PLAs) field programmable gate arrays (FPGAs) 2

PLAs Programmable logic arrays (PLAs) is older technology perform only combinational logic functions. FPGAs can perform both combinational and sequential logic. Implement two-level combinational logic in sum-ofproducts (SOP) form. PLAs are built from an AND array followed by an OR array. Inputs M AND ARRAY Implicants N OR ARRAY P Outputs 3

PLAs A B C OR ARRAY X = ABC + ABC Y = AB ABC ABC AB AND ARRAY X Y A B C OR ARRAY ABC ABC AB AND ARRAY X Y

FPGA: Field Programmable Gate Array They can implement both combinational and sequential logic. They can also implement multilevel logic functions, whereas PLAs can only implement two-level logic. Modern FPGAs integrate other useful features such as built-in multipliers, high-speed I/Os, data converters including analog-to-digital converters, large RAM arrays, and processors. 5

FPGA: Field Programmable Gate Array Composed of: LEs (Logic elements): perform logic IOEs (Input/output elements): interface with outside world Programmable interconnection: connect LEs and IOEs Some FPGAs include other building blocks such as multipliers and RAMs

LE: Logic Element Composed of: LUTs (lookup tables): perform combinational logic Flip-flops: perform sequential logic Multiplexers: connect LUTs and flip-flops

Altera Cyclone IV LE 1 four-input LUT 1 registered output 1 combinational output

LE Configuration Example Show how to configure a Cyclone IV LE to perform the following functions: X = ABC + ABC Y = AB (A) (B) (C) (X) data 1 0 0 0 0 1 1 1 1 data 2 data 3 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 data 4 X X X X X X X X LUT output 0 1 0 0 0 0 1 0 C A B 0 data 1 data 2 data 3 data 4 LUT X LE 1 (A) (B) (Y) data 1 0 0 1 1 data 2 0 1 0 1 data 3 X X X X data 4 X X X X LUT output 0 0 1 0 A data 1 B 0 data 2 data 3 Y 0 data 4 LUT LE 2

LE configuration for one function of more than four inputs X = JKLM and the LUT on the second LE to compute Y = XPQR. 10

LE configuration for one function of more than four inputs The FSM has two bits of state (S 1:0 ) and one output (Y). The next state depends on the two bits of current state. 11

FPGA Design Flow Using a CAD tool (such as Altera s Quartus II) Enter the design using schematic entry or an HDL Simulate the design Synthesize design and map it onto FPGA Download the configuration onto the FPGA Test the design

Hardware description language (HDL) Specifies logic function only Computer-aided design (CAD) tool produces or synthesizes the optimized gates Think of the hardware the HDL should produce! Most commercial designs built using HDLs Two leading HDLs: SystemVerilog developed in 1984 by Gateway Design Automation IEEE standard (1364) in 1995 Extended in 2005 (IEEE STD 1800-2009) VHDL 2008 Developed in 1981 by the Department of Defense IEEE standard (1076) in 1987 Updated in 2008 (IEEE STD 1076-2008)

HDL to Gates Simulation Inputs applied to circuit Outputs checked for correctness Millions of dollars saved by debugging in simulation instead of hardware Synthesis Transforms HDL code into a netlist describing the hardware (i.e., a list of gates and the wires connecting them)

SystemVerilog Modules A block of hardware with inputs and outputs is called a module. Two types of Modules: Behavioral: describe what a module does Structural: describe how it is built from simpler modules a b c Verilog Module y 15

Behavioral SystemVerilog module/: required to begin/end module example: name of the module Operators: ~: NOT &: AND : OR module example(input logic a, b, c, output logic y); assign y = ~a & ~b & ~c a & ~b & ~c a & ~b & c; 16

HDL Simulation module example(input logic a, b, c, output logic y); assign y = ~a & ~b & ~c a & ~b & ~c a & ~b & c; Inputs applied to circuit, Outputs checked for correctness 17

HDL Synthesis module example(input logic a, b, c, output logic y); assign y = ~a & ~b & ~c a & ~b & ~c a & ~b & c; b c un5_y y y a un8_y Transforms HDL code into a netlist describing the hardware (i.e., a list of gates and the wires connecting them) 18

SystemVerilog Syntax Case sensitive Example: reset and Reset are not the same signal. No names that start with numbers Example: 2mux is an invalid name Whitespace ignored Comments: // single line comment /* multiline comment */ 19

Structural Modeling - Hierarchy module and3(input logic a, b, c, output logic y); assign y = a & b & c; module inv(input logic a, output logic y); assign y = ~a; module nand3(input logic a, b, c output logic y); logic n1; // internal signal and3 andgate(a, b, c, n1); // instance of and3 inv inverter(n1, y); // instance of inv 20

Bitwise Operators module gates(input logic [3:0] a, b, output logic [3:0] y1, y2, y3, y4, y5); /* Five different two-input logic gates acting on 4 bit busses */ assign y1 = a & b; assign y2 = a b; assign y3 = a ^ b; // AND // OR // XOR assign y4 = ~(a & b); // NAND assign y5 = ~(a b); // NOR // single line comment /* */ multiline comment 21

Reduction Operators module and8(input logic [7:0] a, output logic y); assign y = &a; // &a is much easier to write than // assign y = a[7] & a[6] & a[5] & a[4] & // a[3] & a[2] & a[1] & a[0]; 22

Conditional Assignment module mux2(input logic [3:0] d0, d1, input logic s, output logic [3:0] y); assign y = s? d1 : d0; 23

Internal Variables module fulladder(input logic a, b, cin, output logic s, cout); logic p, g; // internal nodes assign p = a ^ b; assign g = a & b; assign s = p ^ cin; assign cout = g (p & cin); 24

Precedence Highest Lowest ~ NOT *, /, % mult, div, mod +, - add,sub <<, >> shift <<<, >>> arithmetic shift <, <=, >, >= comparison ==,!= equal, not equal &, ~& AND, NAND ^, ~^ XOR, XNOR, ~ OR, NOR?: ternary operator 25

Numbers Format: N'Bvalue N = number of bits, B = base N'B is optional but recommended (default is decimal) Number # Bits Base Decimal Equivalent Stored 3'b101 3 binary 5 101 'b11 unsized binary 3 00 0011 8'b11 8 binary 3 00000011 8'b1010_1011 8 binary 171 10101011 3'd6 3 decimal 6 110 6'o42 6 octal 34 100010 8'hAB 8 hexadecimal 171 10101011 42 Unsized decimal 42 00 0101010 26

Bit Manipulations: Example 1 assign y = {a[2:1], {3{b[0]}}, a[0], 6'b100_010}; // if y is a 12-bit signal, the above statement produces: y = a[2] a[1] b[0] b[0] b[0] a[0] 1 0 0 0 1 0 // underscores (_) are used for formatting only to make // it easier to read. SystemVerilog ignores them. 27

Bit Manipulations: Example 2 module mux2_8(input logic [7:0] d0, d1, input logic s, output logic [7:0] y); mux2 lsbmux(d0[3:0], d1[3:0], s, y[3:0]); mux2 msbmux(d0[7:4], d1[7:4], s, y[7:4]); 28

Z: Floating Output module tristate(input logic [3:0] a, input logic en, output tri [3:0] y); assign y = en? a : 4'bz; 29

Sequential Logic SystemVerilog uses idioms to describe latches, flip-flops and FSMs Other coding styles may simulate correctly but produce incorrect hardware General Structure: always @(sensitivity list) statement; Whenever the event in sensitivity list occurs, statement is executed 30

D Flip-Flop module flop(input logic clk, input logic [3:0] d, output logic [3:0] q); always_ff @(posedge clk) q <= d; // pronounced q gets d always_ff behaves like always but is used exclusively to imply flip-flops and allows tools to produce a warning if anything else is implied. 31

Resettable D Flip-Flop module flopr(input logic clk, input logic reset, input logic [3:0] d, output logic [3:0] q); // synchronous reset always_ff @(posedge clk) if (reset) q <= 4'b0; else q <= d; 32

Resettable D Flip-Flop module flopr(input logic clk, input logic reset, input logic [3:0] d, output logic [3:0] q); // asynchronous reset always_ff @(posedge clk, posedge reset) if (reset) q <= 4'b0; else q <= d; 33

D Flip-Flop with Enable module flopren(input logic clk, input logic reset, input logic en, input logic [3:0] d, output logic [3:0] q); // enable and asynchronous reset always_ff @(posedge clk, posedge reset) if (reset) q <= 4'b0; else if (en) q <= d; 34

Other Behavioral Statements Statements that must be inside always statements: if / else case, casez 35

Combinational Logic using always // combinational logic using an always statement module gates(input logic [3:0] a, b, output logic [3:0] y1, y2, y3, y4, y5); always_comb // need begin/end because there is begin // more than one statement in always y1 = a & b; // AND y2 = a b; // OR y3 = a ^ b; // XOR y4 = ~(a & b); // NAND y5 = ~(a b); // NOR end always_comb reevaluates the statements inside the always statement any time any of the signals on the right hand side of <= or = in the always statement change. 36

Combinational Logic using case module sevenseg(input logic [3:0] data, output logic [6:0] segments); always_comb case (data) // abc_defg 0: segments = 7'b111_1110; 1: segments = 7'b011_0000; 2: segments = 7'b110_1101; 3: segments = 7'b111_1001; 4: segments = 7'b011_0011; 5: segments = 7'b101_1011; 6: segments = 7'b101_1111; 7: segments = 7'b111_0000; 8: segments = 7'b111_1111; 9: segments = 7'b111_0011; default: segments = 7'b000_0000; // required endcase case statement implies combinational logic only if all possible input combinations described Remember to use default statement 37

3:8 Decoder module decoder3_8(input logic [2:0] a, output logic [7:0] y); always_comb case(a) 3'b000: y = 8'b00000001; 3'b001: y = 8'b00000010; 3'b010: y = 8'b00000100; 3'b011: y = 8'b00001000; 3'b100: y = 8'b00010000; 3'b101: y = 8'b00100000; 3'b110: y = 8'b01000000; 3'b111: y = 8'b10000000; default: y = 8'bxxxxxxxx; endcase 38

Priority Circuit module priorityckt(input logic [3:0] a, output logic [3:0] y); always_comb if (a[3]) y = 4'b1000; else if (a[2]) y = 4'b0100; else if (a[1]) y = 4'b0010; else if (a[0]) y = 4'b0001; else y = 4'b0000; 39

Don t Cares module priority_casez(input logic [3:0] a, output logic [3:0] y); always_comb casez(a) 4'b1???: y = 4'b1000; 4'b01??: y = 4'b0100; 4'b001?: y = 4'b0010; 4'b0001: y = 4'b0001; default: y = 4'b0000; endcase The casez statement acts like a case statement except that it also recognizes? as don t care. 40

Blocking vs. Nonblocking Assignment <= is nonblocking assignment Occurs simultaneously with others = is blocking assignment Occurs in order it appears in file // Good synchronizer using // nonblocking assignments module syncgood(input logic clk, input logic d, output logic q); logic n1; always_ff @(posedge clk) begin n1 <= d; // nonblocking q <= n1; // nonblocking end // Bad synchronizer using // blocking assignments module syncbad(input logic clk, input logic d, output logic q); logic n1; always_ff @(posedge clk) begin n1 = d; // blocking q = n1; // blocking end 41

Finite State Machines (FSMs) module divideby3fsm(input logic clk, input logic reset, output logic y); typedef enum logic [1:0] {S0, S1, S2} statetype; statetype state, nextstate; // state register always_ff @(posedge clk, posedge reset) if (reset) state <= S0; else state <= nextstate; // next state logic always_comb case (state) S0: nextstate = S1; S1: nextstate = S2; S2: nextstate = S0; default: nextstate = S0; Endcase // output logic assign y = (state== S0); The typedef statement defines statetype to be a two-bit logic value with three possibilities: S0, S1, or S2. state and nextstate are statetype signals. 42

Testbenches A testbench is an HDL module that is used to test another module, called the device under test (DUT). The testbench contains statements to apply inputs to the DUT and, ideally, to check that the correct outputs are produced. The input and desired output patterns are called test vectors. 43

Testbenches module testbench1(); logic a, b, c; logic y; // instantiate device under test sillyfunction dut(a, b, c, y); // apply inputs one at a time initial begin a = 0; b = 0; c = 0; #10; c = 1; #10; b = 1; c = 0; #10; c = 1; #10; a = 1; b = 0; c = 0; #10; c = 1; #10; b = 1; c = 0; #10; c = 1; #10; end module sillyfunction(input logic a, b, c, output logic y); assign y = ~b & ~c a & ~b; 44

Self-checking Testbench module testbench2(); logic a, b, c, y; // instantiate device under test sillyfunction dut(a, b, c, y); // apply inputs one at a time // checking results initial begin a = 0; b = 0; c = 0; #10; assert (y === 1) else $error("000 failed."); c = 1; #10; assert (y === 0) else $error("001 failed."); b = 1; c = 0; #10; assert (y === 0) else $error("010 failed."); c = 1; #10; assert (y === 0) else $error("011 failed."); a = 1; b = 0; c = 0; #10; assert (y === 1) else $error("100 failed."); c = 1; #10; assert (y === 1) else $error("101 failed."); b = 1; c = 0; #10; assert (y === 0) else $error("110 failed."); c = 1; #10; assert (y === 0) else $error("111 failed."); end 45

Further Reading You can read Chapter 4 of your book. 46