Digital Design with SystemVerilog

Similar documents
Digital Design with SystemVerilog

HDLs and SystemVerilog. Digital Computer Design

The VHDL Hardware Description Language

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>

Lecture 32: SystemVerilog

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

Synthesizable Verilog

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

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

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

ELCT 501: Digital System Design

Verilog introduction. Embedded and Ambient Systems Lab

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

Quick Introduction to SystemVerilog: Sequental Logic

Digital Design with FPGAs. By Neeraj Kulkarni

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

Lecture 12 VHDL Synthesis

VHDL: RTL Synthesis Basics. 1 of 59

(System)Verilog Tutorial Aleksandar Milenković

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Hardware Description Language VHDL (1) Introduction

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

CS6710 Tool Suite. Verilog is the Key Tool

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

CSE140L: Components and Design Techniques for Digital Systems Lab

Verilog for High Performance

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

EEL 4783: HDL in Digital System Design

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

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

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

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

Lecture 15: System Modeling and Verilog

Verilog 1 - Fundamentals

CSE140L: Components and Design

Introduction to Verilog/System Verilog

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

Writing VHDL for RTL Synthesis

Testbenches for Sequential Circuits... also, Components

HDL. Hardware Description Languages extensively used for:

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

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

Verilog Module 1 Introduction and Combinational Logic

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

Digital Design (VIMIAA01) Introduction to the Verilog HDL

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

CS6710 Tool Suite. Verilog is the Key Tool. Verilog as HDL (AHT) Verilog has a Split Personality. Quick Review. Synthesis

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

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Design Using Verilog

A short introduction to SystemVerilog. For those who know VHDL We aim for synthesis

Sequential Logic - Module 5

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Sequential Logic Design

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

3 Designing Digital Systems with Algorithmic State Machine Charts

EITF35: Introduction to Structured VLSI Design

Combinational Logic II

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

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

DIGITAL SYSTEM DESIGN

VHDL. VHDL History. Why VHDL? Introduction to Structured VLSI Design. Very High Speed Integrated Circuit (VHSIC) Hardware Description Language

Veriolog Overview. CS/EE 3710 Fall 2010

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

!"#$%&&"'(')"*+"%,%-".#"'/"'.001$$"

Verilog Overview. Verilog Overview. Simple Example. Simple Example. Simple Example. Simple Example

Control and Datapath 8

HDL Design Cube. Synthesis and VHDL

EECS150 - Digital Design Lecture 10 Logic Synthesis

VHDL simulation and 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

Control Unit: Binary Multiplier. Arturo Díaz-Pérez Departamento de Computación Laboratorio de Tecnologías de Información CINVESTAV-IPN

ECE 574: Modeling and Synthesis of Digital Systems using Verilog and VHDL. Fall 2017 Final Exam (6.00 to 8.30pm) Verilog SOLUTIONS

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

Writing Circuit Descriptions 8

Chap 6 Introduction to HDL (d)

Note: Closed book no notes or other material allowed, no calculators or other electronic devices.

Lecture #2: Verilog HDL

Online Verilog Resources

Verilog Coding Guideline

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

VHDL VS VERILOG.

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Computer Architecture (TT 2012)

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

Computer-Aided Digital System Design VHDL

EECS150 - Digital Design Lecture 10 Logic Synthesis

Digital Integrated Circuits

Topics. Midterm Finish Chapter 7

Lab 3: Standard Combinational Components

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

VERILOG QUICKSTART. Second Edition. A Practical Guide to Simulation and Synthesis in Verilog

yamin/

Verilog for Synthesis Ing. Pullini Antonio

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

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

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

Verilog Execution Semantics

Transcription:

Digital Design with SystemVerilog Prof. Stephen A. Edwards Columbia University Spring 25

Synchronous Digital Design Combinational Logic Sequential Logic Summary of Modeling Styles Testbenches

Why HDLs? 97s: SPICE transistor-level netlists An XOR built from four NAND gates Vdd.MODEL P PMOS.MODEL N NMOS.SUBCKT NAND A B Y Vdd Vss M Y A Vdd Vdd P M2 Y B Vdd Vdd P M3 Y A X Vss N M4 X B Vss Vss N.ENDS X A B I Vdd NAND X2 A I I2 Vdd NAND X3 B I I3 Vdd NAND X4 I2 I3 Y Vdd NAND A B A B X Vss X2 I X3 Y I2 I3 X4 Y

Why HDLs? 98s: Graphical schematic capture programs

Why HDLs? 99s: HDLs and Logic Synthesis library ieee; use ieee.std_logic_64.all; use ieee.numeric_std.all; entity ALU is port(a: in unsigned( downto ); B: in unsigned( downto ); Sel: in unsigned( downto ); Res: out unsigned( downto )); end ALU; architecture behv of ALU is begin process (A,B,Sel) begin case Sel is when "" => Res <= A + B; when "" => Res <= A + (not B) + ; when "" => Res <= A and B; when "" => Res <= A or B; when others => Res <= "XX"; end case; end process; end behv;

Separate but Equal: Verilog and VHDL Verilog: More succinct, really messy VHDL: Verbose, overly flexible, fairly messy Part of languages people actually use identical Every synthesis system supports both SystemVerilog a newer version. Supports many more features.

Synchronous Digital Design

The Synchronous Digital Logic Paradigm Gates and D flip-flops only No level-sensitive latches All flip-flops driven by the same clock No other clock signals INPUTS CLOCK STATE C L OUTPUTS Every cyclic path contains at least one flip-flop NEXT STATE No combinational loops

Timing in Synchronous Circuits Q D C L CLK t c CLK Q D t c : Clock period. E.g., ns for a MHz clock

Timing in Synchronous Circuits Q D C L CLK Sufficient Hold Time? t p(min,ff) t p(min,cl) CLK Q D Hold time constraint: how soon after the clock edge can D start changing? Min. FF delay + min. logic delay

Timing in Synchronous Circuits Q D C L CLK t p(max,ff) Sufficient Setup Time? t p(max,cl) CLK Q D Setup time constraint: when before the clock edge is D guaranteed stable? Max. FF delay + max. logic delay

Combinational Logic

Full Adder Single-line comment Systems are built from modules Continuous assignment expresses combinational logic // Full adder Module name Input port Data type: single bit Port name module full_adder(input logic a, b, c, output logic sum, carry); assign sum = a ^ b ^ c; assign carry = a & b a & c b & c; b a carry~ carry~2 carry~3 Logical Expression c carry~ carry sum sum

Operators and Vectors Four-bit vector, little-endian style module gates(input logic [3:] a, b, output logic [3:] y, y2, y3, y4, y5); /* Five groups of two-input logic gates acting on 4-bit busses */ assign y = a & b; // AND assign y2 = a b; // OR assign y3 = a ^ b; // XOR assign y4 = ~(a & b); // NAND assign y5 = ~(a b); // NOR Multi-line comment

Reduction AND Operator module and8(input logic [7:] a, output logic y); assign y = &a; // Reduction AND // Equivalent to // assign y = a[7] & a[6] & a[5] & a[4] & // a[3] & a[2] & a[] & a[]; // Also ~ a NAND // a OR // ~ a NOR // ^a XOR // ~^a XNOR

The Conditional Operator: A Two-Input Mux module mux2(input logic [3:] d, d, input logic s, output logic [3:] y); s d[3..] d[3..] 3 2 3 2 y~ y~ y[3..] // Array of two-input muxes assign y = s? d : d; y~2 y~3

Operators in Precedence Order!c -c &c ~&c NOT, Negate, Reduction AND, NAND c ~ c ^c ~^c OR, NOR, XOR, XNOR a*b a/b a%b Multiply, Divide, Modulus a+b a-b Add, Subtract a<<b a>>b Logical Shift a<<<b a>>>b Arithmetic Shift a<b a<=b a>b a>=b Relational a==b a!=b Equality a&b a^&b AND a^b a~^b XOR, XNOR a b OR a?b:c Conditional {a,b,c,d} Concatenation

An XOR Built Hierarchically module mynand2(input logic a, b, output logic y); assign y = ~(a & b); module myxor2(input logic a, b, output logic y); logic abn, aa, bb; mynand2 n(a, b, abn), n2(a, abn, aa), n3(abn, b, bb), n4(aa, bb, y); Declare internal wires n: A mynand2 connected to a, b, and abn mynand2:n2 mynand2:n4 a mynand2:n a b y y~not y a b y y~not y y b a b y y~not y a b y mynand2:n3 y~not y

A Decimal-to-Seven-Segment Decoder always_comb: combinational logic in an module dec7seg(input logic [3:] a, imperative style output logic [6:] y); always_comb case (a) Multiway 4 d: y = 7 b_; conditional 4 d: y = 7 b_; 4 d2: y = 7 b_; 4 d5: decimal 5 4 d3: y = 7 b_; as a four-bit 4 d4: y = 7 b_; binary number 4 d5: y = 7 b_; 4 d6: y = 7 b_; 4 d7: y = 7 b_; 4 d8: y = 7 b_; Mandatory 4 d9: y = 7 b_; default: y = 7 b_; endcase seven-bit binary vector (_ is ignored) blocking assignment : use in always_comb

Verilog Numbers 6 h h8_f Number of Bits Base: b, o, d, or h Value: _ s are ignored Zero-padded 4 b = 4 o2 = 4 d = 4 ha 6 h484 = 6 b

Imperative Combinational Logic module comb( input logic [3:] a, b, input logic s, output logic [3:] y); always_comb if (s) y = a + b; else y = a & b; y~5 2 y~2 2 2 y~ y~6 Add A[3..] OUT[3..] B[3..] + y~ y~7 s a[3..] 3 y~3 b[3..] 3 y~4 3 y[3..] Both a + b and a & b computed, mux selects the result.

Imperative Combinational Logic module comb2( input logic [3:] a, b, input logic s, t, output logic [3:] y); always_comb if (s) y = a + b; else if (t) y = a & b; else y = a b; a[3..] b[3..] t 2 2 3 3 2 2 3 3 y~2 y~6 y~9 y~5 y~ y~ y~ y~ y~4 y~3 y~8 y~7 2 3 y~3 y~4 y~5 y~2 y[3..] s A[3..] B[3..] Add + OUT[3..] All three expressions computed in parallel. Cascaded muxes implement priority (s over t). s t y a + b a & b a b

Imperative Combinational Logic module comb3( input logic [3:] a, b, input logic s, t, output logic [3:] y, z); t y~5 y~ :3 :3 Add A[4..] OUT[4..] B[4..] + y~ y~3 always_comb begin z = 4 b; if (s) begin y = a + b; z = a - b; end else if (t) begin y = a & b; z = a + b; end else y = a b; end s a[3..] b[3..] 2 2 2 2 3 3 3 3 y~2 y~6 y~ y~4 y~3 y~7 Add A[3..] OUT[3..] B[3..] + 'h 3 'h 2 y~9 y~ y~8 z~ z~ 4 3 2 3 y~4 y~5 y~2 z~4 z~5 y[3..] z[3..] 'h z~2 2 z~6 Separate mux cascades for y and z. One copy of a + b. 'h z~3 z~7

An Address Decoder module adecode(input logic [5:] address, output logic RAM, ROM, output logic VIDEO, IO); always_comb begin {RAM, ROM, VIDEO, IO} = 4 b ; if (address[5]) RAM = ; else if (address[4:3] == 2 b ) VIDEO = ; else if (address[4:2] == 3 b ) IO = ; else if (address[4:3] == 2 b ) ROM = ; end Vector concatenation Default: all zeros Select bit 5 Select bits 4, 3, & 2 Omitting defaults for RAM, etc. will give construct does not infer purely combinational logic.

Sequential Logic

A D-Flip-Flop always_ff introduces sequential logic Copy d to q module mydff(input logic clk, input logic d, output logic q); always_ff @(posedge clk) q <= d; Triggered by the rising edge of clk Non-blocking assignment: happens just after the rising edge q~reg d D Q q clk CLK

A Four-Bit Binary Counter module count4(input logic clk, output logic [3:] count); always_ff @(posedge clk) count <= count + 4 d ; Width optional but good style clk A[3..] 4'h8 B[3..] Add + OUT[3..] count[]~reg[3..] D Q CLK count[3..]

A Decimal Counter with Reset, Hold, and Load module dec_counter(input logic clk, input logic reset, hold, load, input logic [3:] d, output logic [3:] count); always_ff @(posedge clk) if (reset) count <= 4 d ; else if (load) count <= d; else if (~hold) if (count == 4 d 9) count <= 4 d ; else count <= count + 4 d ; 3 count~ 'h 2 count~ 3 count~4 3 count~8 'h count~2 hold A[3..] 4'h9 B[3..] = Equal OUT Add A[3..] OUT[3..] 4'h8 B[3..] + 'h 'h 'h count~2 count~3 2 count~5 count~6 count~7 2 count~9 count~ count~ 'h 'h 'h count~3 count~4 count~5 load d[3..] count[]~reg[3..] reset D Q count[3..] clk CLK

Moore and Mealy Finite-State Machines Inputs Next State Logic Next State CLK Current State Output Logic Outputs The Moore Form: Outputs are a function of only the current state.

Moore and Mealy Finite-State Machines Inputs Next State Logic Next State CLK Current State Output Logic Outputs The Mealy Form: Outputs may be a function of both the current state and the inputs. A mnemonic: Moore machines often need more states.

Moore-style: Sequential Next-State Logic module moore_tlc(input logic clk, reset, input logic advance, output logic red, yellow, green); enum logic [2:] {R, Y, G} state; // Symbolic state names always_ff @(posedge clk) // Moore-style next-state logic if (reset) state <= R; else case (state) R: if (advance) state <= G; G: if (advance) state <= Y; Y: if (advance) state <= R; default: state <= R; endcase assign red = state == R; // Combinational output logic assign yellow = state == Y; // separated from next-state logic assign green = state == G;

Mealy-style: Combinational output/next state logic module mealy_tlc(input logic clk, reset, input logic advance, output logic red, yellow, green); typedef enum logic [2:] {R, Y, G} state_t; state_t state, next_state; always_ff @(posedge clk) state <= next_state; always_comb begin // Mealy-style next state and output logic {red, yellow, green} = 3 b; // Default: all off and next_state = state; // hold state if (reset) next_state = R; else case (state) R: begin red = ; if (advance) next_state = G; end G: begin green = ; if (advance) next_state = Y; end Y: begin yellow = ; if (advance) next_state = R; end default: next_state = R; endcase end

Blocking vs. Nonblocking assignment module nonblock(input clk, input logic a, output logic d); logic b, c; always_ff @(posedge clk) begin Nonblocking b <= a; assignment: c <= b; All run on the d <= c; clock edge end module blocking(input clk, input logic a, output logic d); logic b, c; always_ff @(posedge clk) begin Blocking b = a; assignment: c = b; Effect felt by d = c; next statement end b c d~reg d~reg a clk D CLK Q D CLK Q D CLK Q d a clk D CLK Q d

Summary of Modeling Styles

A Contrived Example module styles_tlc(input logic clk, reset, input logic advance, output logic red, yellow, green); enum logic [2:] {R, Y, G} state; always_ff @(posedge clk) // Imperative sequential if (reset) state <= R; // Non-blocking assignment else case (state) // Case R: if (advance) state <= G; // If-else G: if (advance) state <= Y; Y: if (advance) state <= R; default: state <= R; endcase always_comb begin // Imperative combinational {red, yellow} = 2 b ; // Blocking assignment if (state == R) red = ; // If-else case (state) // Case Y: yellow = ; default: ; endcase; end assign green = state == G; // Cont. assign. (comb)

Testbenches

Testbenches A model of the environment; exercises the module. // Module to test: // Three-bit // binary counter module count3( input logic clk, reset, output logic [2:] count); always_ff @(posedge clk) if (reset) count <= 3 d ; else count <= count + 3 d ; module count3_tb; logic clk, reset; logic [2:] count; count3 dut(.*); initial begin clk = ; forever #2ns clk = ~clk; end initial begin // Reset reset = ; repeat (2) @(posedge clk); reset = ; repeat (2) @(posedge clk); reset = ; end No ports Signals for each DUT port Device Under Test Connect everything Initial block: Imperative code runs once Infinite loop Delay Counted loop Wait for a clock cycle

Running this in ModelSim