EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

Similar documents
EECS150 - Digital Design Lecture 8 - Hardware Description Languages

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

Outline. EECS150 - Digital Design Lecture 5 - Verilog 2. Structural Model: 2-to1 mux. Structural Model - XOR. Verilog Basics Lots of Examples

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

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

Hardware Description Languages: Verilog

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

EECS150 - Digital Design Lecture 6 - Logic Simulation

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

CSE140L: Components and Design Techniques for Digital Systems Lab

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

CSE140L: Components and Design

CS250 VLSI Systems Design Lecture 3: Hardware Design Languages. Fall Krste Asanovic, John Wawrzynek with John Lazzaro and Brian Zimmer (TA)

EEL 4783: HDL in Digital System Design

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

Hardware description languages

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

CS61C: Verilog Tutorial

Digital Design with FPGAs. By Neeraj Kulkarni

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

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

HDLs and SystemVerilog. Digital Computer Design

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

Lecture #2: Verilog HDL

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

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

A Brief Introduction to Verilog Hardware Definition Language (HDL)

EECS150 - Digital Design Lecture 6 - Logic Simulation. Encoder Example

Introduction to Verilog/System Verilog

Verilog introduction. Embedded and Ambient Systems Lab

Introduction to Verilog HDL

ECE 4514 Digital Design II. Spring Lecture 15: FSM-based Control

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

Lecture 8: Combinational Verilog. CSE 370, Autumn 2007 Benjamin Ylvisaker. Where We Are. Last lecture: Minimization with K!maps

Verilog for Synthesis Ing. Pullini Antonio

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 7. Summary of two-level combinational-logic. Ways of specifying circuits. Solving combinational design problems. Verilog versus VHDL

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

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

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Digital Design with SystemVerilog

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

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

Course Topics - Outline

Chap 6 Introduction to HDL (d)

Synthesizable Verilog

Verilog Module 1 Introduction and Combinational Logic

Writing Circuit Descriptions 8

Hardware Description Language VHDL (1) Introduction

Digital Design (VIMIAA01) Introduction to the Verilog HDL

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

Where We Are. Quick History Lesson. Lecture 8: Combinational Verilog. Specifying Circuits. Last lecture: Minimization with K!maps

Veriolog Overview. CS/EE 3710 Fall 2010

Synthesis of Combinational and Sequential Circuits with Verilog

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

Lecture #1: Introduction

problem maximum score 1 10pts 2 8pts 3 10pts 4 12pts 5 7pts 6 7pts 7 7pts 8 17pts 9 22pts total 100pts

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>

ECEN 449 Microprocessor System Design. Verilog. Texas A&M University

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

ECE 353 Lab 3 (Verilog Design Approach)

Verilog Design Principles

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

Topics. Midterm Finish Chapter 7

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

Topics. Midterm Finish Chapter 7

Contents. Appendix D Verilog Summary Page 1 of 16

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

Lecture 32: SystemVerilog

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

Introduction to Verilog HDL. Verilog 1

ECEN 449 Microprocessor System Design. Verilog. Texas A&M University

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

ELCT 501: Digital System Design

VHDL for Synthesis. Course Description. Course Duration. Goals

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

VHDL VS VERILOG.

Introduction. Why Use HDL? Simulation output. Explanation

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

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

ENGR 3410: MP #1 MIPS 32-bit Register File

Control in Digital Systems

Verilog for High Performance

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

Register Transfer Level in Verilog: Part I

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences. Spring 2010 May 10, 2010

CS6710 Tool Suite. Verilog is the Key Tool

Hardware Design Environments. Dr. Mahdi Abbasi Computer Engineering Department Bu-Ali Sina University

ENGR 3410: Lab #1 MIPS 32-bit Register File

Nikhil Gupta. FPGA Challenge Takneek 2012

Programming with HDLs

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

Don t expect to be able to write and debug your code during the lab session.

Verilog Behavioral Modeling

Transcription:

EECS150 - Digital Design Lecture 4 - Verilog Introduction Feb 3, 2009 John Wawrzynek Spring 2009 EECS150 - Lec05-Verilog Page 1 Outline Background and History of Hardware Description Brief Introduction to Verilog Basics Lots of examples structural, data-flow, behavioral Verilog in EECS150 Spring 2009 EECS150 - Lec05-Verilog Page 2

Schematic entry/editing used to be the standard method in industry and universities. Used in EECS150 until 2002 Schematics are intuitive. They match our use of gate-level or block diagrams. Somewhat physical. They imply a physical implementation. Require a special tool (editor). Unless hierarchy is carefully designed, schematics can be confusing and difficult to follow on large designs. Design Entry Hardware Description Languages (HDLs) are the new standard except for PC board design, where schematics are still used. Spring 2009 EECS150 - Lec05-Verilog Page 3 Basic Idea: Hardware Description Languages Language constructs describe circuits with two basic forms: Structural descriptions: connections of components. Nearly one-to-one correspondence to with schematic diagram. Behavioral descriptions: use highlevel constructs (similar to conventional programming) to describe the circuit function. Originally invented for simulation. Now logic synthesis tools exist to automatically convert from HDL source to circuits. High-level constructs greatly improves designer productivity. However, this may lead you to falsely believe that hardware design can be reduced to writing programs! Structural example: Decoder(output x0,x1,x2,x3; inputs a,b) { wire abar, bbar; } inv(bbar, b); inv(abar, a); and(x0, abar, bbar); and(x1, abar, b ); and(x2, a, bbar); and(x3, a, b ); Behavioral example: Decoder(output x0,x1,x2,x3; inputs a,b) { case [a b] 00: [x0 x1 x2 x3] = 0x1; 01: [x0 x1 x2 x3] = 0x2; 10: [x0 x1 x2 x3] = 0x4; 11: [x0 x1 x2 x3] = 0x8; endcase; } Warning: this is a fake HDL! Spring 2009 EECS150 - Lec05-Verilog Page 4

Sample Design Methodology Hierarchically defines structure and/or function of circuit. HDL Specification Simulation Verification: Does the design behave as required with regards to function, timing, and power consumption? Synthesis Maps specification to resources of implementation platform (FPGA or custom silicon). Note: This in not the entire story. Other tools are useful for analyzing HDL specifications. More on this later. Spring 2009 EECS150 - Lec05-Verilog Page 5 Verilog A brief history: Originated at Automated Integrated Design Systems (renamed Gateway) in 1985. Acquired by Cadence in 1989. Invented as simulation language. Synthesis was an afterthought. Many of the basic techniques for synthesis were developed at Berkeley in the 80 s and applied commercially in the 90 s. Around the same time as the origin of Verilog, the US Department of Defense developed VHDL (A double acronym! VSIC HDL). Because it was in the public domain it began to grow in popularity. Afraid of losing market share, Cadence opened Verilog to the public in 1990. An IEEE working group was established in 1993, and ratified IEEE Standard 1394 (Verilog) in 1995. We use IEEE Std 1364-2001. Verilog is the language of choice of Silicon Valley companies, initially because of high-quality tool support and its similarity to C-language syntax. VHDL is still popular within the government, in Europe and Japan, and some Universities. Most major CAD frameworks now support both. Latest Verilog version is system Verilog. Latest HDL: C++ based. OSCI (Open System C Initiative). Spring 2009 EECS150 - Lec05-Verilog Page 6

Verilog Introduction A module definition describes a component in a circuit Two ways to describe module contents: Structural Verilog List of sub-components and how they are connected Just like schematics, but using text tedious to write, hard to decode You get precise control over circuit details May be necessary to map to special resources of the FPGA Behavioral Verilog Describe what a component does, not how it does it Synthesized into a circuit that has this behavior Result is only as good as the tools Build up a hierarchy of modules. Top-level module is your entire design (or the environment to test your design). Spring 2009 EECS150 - Lec05-Verilog Page 7 Verilog Modules and Instantiation keywords Modules define circuit components. Instantiation defines hierarchy of the design. name port list module addr_cell (a, b, cin, s, cout); input a, b, cin; port declarations (input, output s, cout; output, or inout) module body module adder (A, B, S); Instance of addr_cell addr_cell ac1 (... connections... ); 8 Note: A module is not a function in the C sense. There is no call and return mechanism. Think of it more like a hierarchical data structure. Spring 2009 EECS150 - Lec05-Verilog Page

Structural Model - XOR example module xor_gate ( out, a, b ); input a, b; wire abar, bbar, t1, t2; Built-in gates not inva (abar, a); not invb (bbar, b); and and1 (t1, a, bbar); and and2 (t2, b, abar); or or1 (out, t1, t2); module name instances port list port declarations internal signal declarations out Interconnections (note output is first) Notes: Instance name The instantiated gates are not executed. They are active always. xor gate already exists as a built-in (so really no need to define it). Undeclared variables as assumed to be wires. Don t let this happen to you! Spring 2009 EECS150 - Lec05-Verilog Page 9 Structural Example: 2-to1 mux /* 2-input multiplexor in gates */ module mux2 (in0, in1, select, out); input in0,in1,select; wire s0,w0,w1; not (s0, select); and (w0, s0, in0), (w1, select, in1); or (out, w0, w1); // mux2 Built-ins don t need Instance names C++ style comments Multiple instances can share the same master name. Built-ins gates can have > 2 inputs. Ex: and (w0, a, b, c, d); Spring 2009 EECS150 - Lec05-Verilog Page 10

Instantiation, Signal Array, Named ports /* 2-input multiplexor in gates */ module mux2 (in0, in1, select, out); input in0,in1,select; wire s0,w0,w1; not (s0, select); and (w0, s0, in0), (w1, select, in1); or (out, w0, w1); // mux2 module mux4 (in0, in1, in2, in3, select, out); input in0,in1,in2,in3; input [1:0] select; Signal array. Declares select[1], select[0] Named ports. Highly recommended. wire w0,w1; mux2 m0 (.select(select[0]),.in0(in0),.in1(in1),.out(w0)), m1 (.select(select[0]),.in0(in2),.in1(in3),.out(w1)), m3 (.select(select[1]),.in0(w0),.in1(w1),.out(out)); // mux4 Spring 2009 EECS150 - Lec05-Verilog Page 11 Simple Behavioral Model module foo (out, in1, in2); input in1, in2; assign out = in1 & in2; continuous assignment Connects out to be the and of in1 and in2. Shorthand for explicit instantiation of and gate (in this case). The assignment continuously happens, therefore any change on the rhs is reflected in out immediately (except for the small delay associated with the implementation of the &). Not like an assignment in C that takes place when the program counter gets to that place in the program. Spring 2009 EECS150 - Lec05-Verilog Page 12

Continuous Assignment Examples assign R = X (Y & ~Z); wire [3:0] X,Y,R; wire [7:0] P; wire r, a, cout, cin; example assign r = &X; reduction use of bit-wise Boolean operators operator assign R = (a == 1 b0)? X : Y; conditional operator assign P = 8'hff; assign P = X * Y; example constants arithmetic operators (use with care!) assign P[7:0] = {3{X[3]}, X[3:0]}; (ex: sign-extension) assign {cout, R} = X + Y + cin; bit field concatenation assign Y = A << 2; bit shift operator assign Y = {A[1], A[0], 1 b0, 1 b0}; equivalent bit shift Spring 2009 EECS150 - Lec05-Verilog Page 13 Verilog Operators Spring 2009 EECS150 - Lec05-Verilog Page 14

Constants: Verilog Numbers 14 ordinary decimal number -14 2 s complement representation 12 b0000_0100_0110 binary number ( _ is ignored) 12 h046 hexadecimal number with 12 bits Signal Values: By default Values are by default unsigned e.g., C[4:0] = A[3:0] + B[3:0]; if A = 0110 (6) and B = 1010(-6) C = 10000 not 00000 i.e., B is zero-padded, not sign-extended wire signed [31:0] x; Declares a signed (2 s complement) signal array. Spring 2009 EECS150 - Lec05-Verilog Page 15 Non-continuous Assignments A bit strange from a hardware specification point of view. Shows off Verilog roots as a simulation language. always block example: module and_or_gate (out, in1, in2, in3); input in1, in2, in3; reg out; keyword reg type declaration. Not really a register in this case. Just a Verilog rule. always @(in1 or in2 or in3) begin out = (in1 & in2) in3; end sensitivity list, triggers the action in the body. brackets multiple statements (not necessary in this example. Isn t this just: assign out = (in1 & in2) in3;? Why bother? Spring 2009 EECS150 - Lec05-Verilog Page 16

Always Blocks Always blocks give us some constructs that are impossible or awkward in continuous assignments. case statement example: module mux4 (in0, in1, in2, in3, select, out); input in0,in1,in2,in3; input [1:0] select; reg out; always @ (in0 in1 in2 in3 select) case (select) keyword 2 b00: out=in0; 2 b01: out=in1; 2 b10: out=in2; 2 b11: out=in3; endcase // mux4 The statement(s) corresponding to whichever constant matches select get applied. Couldn t we just do this with nested if s? Well yes and no! Spring 2009 EECS150 - Lec05-Verilog Page 17 Nested if-else example: Always Blocks module mux4 (in0, in1, in2, in3, select, out); input in0,in1,in2,in3; input [1:0] select; reg out; always @ (in0 in1 in2 in3 select) if (select == 2 b00) out=in0; else if (select == 2 b01) out=in1; else if (select == 2 b10) out=in2; else out=in3; // mux4 Nested if structure leads to priority logic structure, with different delays for different inputs (in3 to out delay < than in0 to out delay). Case version treats all inputs the same. Spring 2009 EECS150 - Lec05-Verilog Page 18

State Elements Always blocks are the only way to specify the behavior of state elements. Synthesis tools will turn state element behaviors into state element instances. D-flip-flop with synchronous set and reset example: module dff(q, d, clk, set, rst); input d, clk, set, rst; output q; reg q; keyword always @(posedge clk) if (reset) q <= 1 b0; else if (set) q <= 1 b1; else q <= d; always @ (posedge clk) is key to flip-flop generation. This gives priority to reset over set and set over d. clk On FPGAs, maps to native flip-flop. d s q r How would you add an CE (clock enable) input? Spring 2009 EECS150 - Lec05-Verilog Page 19 State Transition Diagram Finite State Machines Holds a symbol to keep track of which bubble the FSM is in. Implementation Circuit Diagram Spring 2009 EECS150 - Lec05-Verilog Page 20 CL functions to determine output value and next state based on input and current state. out = f(in, current state) next state = f(in, current state)

Finite State Machines module FSM1(clk, rst, in, out); input clk, rst; input in; Must use reset to force to initial state. reset not always shown in STD // Defined state encoding: parameter IDLE = 2'b00; parameter S0 = 2'b01; Constants local to this module. parameter S1 = 2'b10; reg out; out not a register, but assigned in always block reg [1:0] state, next_state; THE register to hold the state of the FSM. // always block for state register always @(posedge clk) if (rst) state <= IDLE; else state <= next_state; Combinational logic signals for transition. A separate always block will be used for combination logic part of FSM. Next state and output generation. (Always blocks in a design work in parallel.) Spring 2009 EECS150 - Lec05-Verilog Page 21 FSMs (cont.) // always block for combinational logic portion always @(state or in) case (state) // For each state def output and next IDLE : begin out = 1 b0; if (in == 1 b1) next_state = S0; else next_state = IDLE; end S0 : begin out = 1 b0; if (in == 1 b1) next_state = S1; else next_state = S0; end S1 : begin out = 1 b1; if (in == 1 b1) next_state = S1; else next_state = IDLE; default: begin next_state = IDLE; data_out = 1 b0; end endcase Each state becomes a case clause. For each state define: Output value(s) State transition Spring 2009 EECS150 - Lec05-Verilog Page 22 Use default to cover unassigned state. Usually unconditionally transition to reset state.

Bonus Example //Parallel to Serial converter module ParToSer(LD, X, out, CLK); input [3:0] X; input LD, clk; reg out; reg [3:0] Q; assign out = Q[0]; always @ (posedge clk) if (LD) Q<=X; else Q <= Q>>1; // mux2 always @ (posedge CLK) forces Q register to be rewritten every cycle. >> operator does right shift (shifts in a zero on the left). Shifts can be done with concatenation. Continuous assign example: wire [3:0] A, B; assign B = {1 b0, A[3:1]} Spring 2009 EECS150 - Lec05-Verilog Page 23 Verilog in EECS150 We will primarily behavior modeling along with instantiation to build hierarchy and map to FPGA resources not supported by synthesis. Favor continuous assign and avoid always blocks unless: no other alternative: ex: state elements, case helps readability and clarity of code: ex: large nested if else Use named ports. Verilog is a big language. This is only an introduction. Our text book is a good source. Read and use chapter 4. Be careful of what you read on the web. Many bad examples out there. We will be introducing more useful constructs throughout the semester. Stay tuned! Spring 2009 EECS150 - Lec05-Verilog Page 24

Final thoughts on Verilog Examples Verilog looks like C, but it describes hardware Multiple physical elements with parallel activities and temporal relationships. A large part of digital design is knowing how to write Verilog that gets you the desired circuit. First understand the circuit you want then figure out how to code it in Verilog. If you do one of these activities without the other, you will struggle. These two activities will merge at some point for you. Be suspicious of the synthesis tools! Check the output of the tools to make sure you get what you want. Spring 2009 EECS150 - Lec05-Verilog Page 25