Introduction to Verilog, ModelSim, and Xilinx ISE

Slides:



Advertisements
Similar presentations
Xilinx 6.3 Tutorial Integrated Software Environment (ISE) Set up basic environment Select Gates or Modules to Be simulated (Insert Program Code) Run Waveform.
Advertisements

Hardware Description Languages (HDL): Verilog
Hardware Description Languages: Verilog
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Chapter 11 Verilog HDL Application-Specific Integrated Circuits Michael John Sebastian Smith Addison Wesley, 1997.
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.
Verilog - 1 Writing Hardware Programs in Abstract Verilog  Abstract Verilog is a language with special semantics  Allows fine-grained parallelism to.
ECE 272 Xilinx Tutorial. Workshop Goals Learn how to use Xilinx to: Draw a schematic Create a symbol Generate a testbench Simulate your circuit.
ECE 4680 Computer Architecture Verilog Presentation I. Verilog HDL.
Reconfigurable Computing (EN2911X, Fall07) Lecture 05: Verilog (1/3) Prof. Sherief Reda Division of Engineering, Brown University
University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Lecture 7 Verilog Additional references Structural constructs
Guest Lecture by Ben Magstadt CprE 281: Digital Logic.
Guest Lecture by Ben Magstadt CprE 281: Digital Logic.
ECE 2372 Modern Digital System Design
1 An Update on Verilog Ξ – Computer Architecture Lab 28/06/2005 Kypros Constantinides.
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.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHSIC Hardware Description Language  Required Reading: –These Slides –VHDL Tutorial  Very High Speed.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.
ELEE 4303 Digital II Introduction to Verilog. ELEE 4303 Digital II Learning Objectives Get familiar with background of HDLs Basic concepts of Verilog.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Introduction to ASIC flow and Verilog HDL
11 EENG 1920 Introduction to VHDL. 22 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.
Introduction to Verilog. Data Types A wire specifies a combinational signal. – Think of it as an actual wire. A reg (register) holds a value. – A reg.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
CprE 281: Verilog Tutorial Ben Magstadt – Master’s Student Electrical Engineering.
Introduction to Verilog. Structure of a Verilog Program A Verilog program is structured as a set of modules, which may represent anything from a collection.
1 Introduction to Engineering Spring 2007 Lecture 18: Digital Tools 2.
Exp#5 & 6 Introduction to Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
1 A hardware description language is a computer language that is used to describe hardware. Two HDLs are widely used Verilog HDL VHDL (Very High Speed.
Introduction to Verilog COE 202 Digital Logic Design Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals.
ECE 111 (Spring 2017) Professor Bill Lin
Hardware Description Languages: Verilog
An Introduction to Verilog: Transitioning from VHDL
Introduction to Vivado
TODAY’S OUTLINE Introduction to Verilog Verilog coding format
Lecture 3: Combinational Logic in SystemVerilog
University of Maryland Baltimore County Department of Computer Science and Electrical Engineering   CMPE 212 Laboratory (Discussion 2) Hasibul Hasan
Introduction to Verilog
Discussion 2: More to discuss
Lecture 7 Logistics Last lecture Today Homework 2 due today
Verilog-HDL-3 by Dr. Amin Danial Asham.
Hardware Description Languages: Verilog
Introduction to Verilog
Behavioral Modeling in Verilog
Overview Last lecture Today K-Maps Verilog Structural constructs
Introduction to Verilog
Overview Last lecture Today K-Maps Verilog Structural constructs
COE 202 Introduction to Verilog
Hardware Descriptive Languages these notes are taken from Mano’s book
Review Advancing technology changes the trade-offs and design techniques 2x transistors per chip every 18 months ASIC, Programmable Logic, Microprocessor.
Lecture 2: Continuation of SystemVerilog
Introduction to Digital System and Microprocessor Design
Founded in Silicon Valley in 1984
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2017
Introduction to Verilog
Introduction to Verilog, ModelSim, and Xilinx Vivado
Introduction to Verilog
The Verilog Hardware Description Language
Introduction to Verilog
COE 202 Introduction to Verilog
Reconfigurable Computing (EN2911X, Fall07)
Presentation transcript:

Introduction to Verilog, ModelSim, and Xilinx ISE UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2017 ECE 111 Fall 2017

Software access This week: Room 2214 at the Warren Lecture Hall After ~week we will be moving to 2217A (will be announced) For access send email to Keith Yu (the main TA) We requested the SW to be installed but it will take a week Meanwhile, the Linux server has the ModelSim. The instructions are on the website: http://eceweb.ucsd.edu/~fkoushanfar/teaching/ECE111/software.ht ml  ECE 111 Fall 2017

Overview Verilog: Hardware Description Language ModelSim: Simulator Designing the circuit ModelSim: Simulator Verification and debugging ISE: Synthesize the code for Xilinx FPGAs Generating configuration file Area, timing and power analysis Has a built-in simulator (ISIM), but we prefer ModelSim ECE 111 Fall 2017

Verilog Hardware Description Language ECE 111 Fall 2017

Overview Structural Models Behavioral Models Syntax Examples ECE 111 Fall 2017

Design Methodology HDL Specification Structure and Function (Behavior) of a Design Simulation (ModelSim) Synthesis (ISE) Verification: Design Behave as Required? Functional: I/O Behavior Register-Level (Architectural) Logic-Level (Gates) Transistor-Level (Electrical) Timing: Waveform Behavior Generation: Map Specification to Implementation ECE 111 Fall 2017

Verilog vs VHDL The “standard” languages Very similar Many tools provide front-ends to both Verilog is “simpler” Less syntax, fewer constructs VHDL supports large, complex systems Better support for modularization More grungy details “Hello world” is much bigger in VHDL We will use Verilog in this course ECE 111 Fall 2017

Verilog Module Corresponds to a circuit component “Parameter list” is the list of external connections, aka “ports” Ports are declared “input”, “output” or “inout” inout ports used on tri-state buses module full_addr (A, B, Cin, S, Cout); input A, B, Cin; output S, Cout; assign {Cout, S} = A + B + Cin; endmodule i/o ports Module name input/output declaration ECE 111 Fall 2017

Structural/Behavioral Model Structural Verilog List of components and how they are connected Just like schematics, but using text Hard to write, hard to decode Useful if you don’t have integrated design tools Behavioral Verilog Describe what a component does, not how it does it Synthesized into a circuit that has this behavior ECE 111 Fall 2017

Structural/Behavioral Model Structural : Composition of gates to form more complex module module xor_gate (out, a, b); input a, b; output out; wire abar, bbar, t1, t2; inverter invA (abar, a); inverter invB (bbar, b); and_gate and1 (t1, a, bbar); and_gate and2 (t2, b, abar); or_gate or1 (out, t1, t2); endmodule Instantiation name Primitive name ECE 111 Fall 2017

Structural/Behavioral Model Behavioral: Describe output as a function of inputs module xor_gate (out, a, b); input a, b; output out; assign out = a ^ b; endmodule assign keyword: continuous assignment ECE 111 Fall 2017

Structural/Behavioral Model module full_addr (A, B, Cin, S, Cout); input A, B, Cin; output S, Cout; assign {Cout, S} = A + B + Cin; endmodule module adder4 (A, B, Cin, S, Cout); input [3:0] A, B; input Cin; output [3:0] S; output Cout; wire C1, C2, C3; full_addr fa0 (A[0], B[0], Cin, S[0], C1); full_addr fa1 (A[1], B[1], C1, S[1], C2); full_addr fa2 (A[2], B[2], C2, S[2], C3); full_addr fa3 (A[3], B[3], C3, S[3], Cout); Behavioral model to describe the inner module Structural model instantiating the inner module to generate a larger module (more on module instantiation follows) Instantiation name Submodule name ECE 111 Fall 2017

Initial/Always Blocks initial block is executed only once when simulation starts Useful in writing test benches (example in discussion on testbench) always block is continuously executed It has a sensitivity list associated with it module xor_gate (out, a, b); input a, b; output reg out; always (a or b) begin out = a ^ b; end endmodule begin..end is equivalent to {..} in C sensitivity list: the code inside the block is executed when value of either a or b changes, supports wild card character (‘*’) ECE 111 Fall 2017

Assign Statement An assign statement is executed continuously An always block with sensitivity list set to ‘*’ is equivalent to assign Following two are equivalent module xor_gate (out, a, b); input a, b; output reg out; always (*) begin out = a ^ b; end endmodule module xor_gate (out, a, b); input a, b; output out; assign out = a ^ b; endmodule ECE 111 Fall 2017

Verilog “Variables” wire reg Variable used simply to connect components together All the variables (including i/o ports) are by default wire reg Variable that saves a value as part of a behavioral description Is NOT necessarily a register in the circuit wire is used outside initial/always block and reg is used inside always block Compare the two versions of the xor_gate module ECE 111 Fall 2017

Signal Values Regular logic values Z value: X value 0 and 1 logic High impedance (open circuit) Synthesized by a tri-state buffer E.g., assign output = (output_enable) ? input : 1'bz X value Don’t care (Assigned to either 0 or 1 logic, whichever is more helpful for the optimization process ) Applicable to certain input patters that may never occur

Verilog Data Types and Values Bits - value on a wire: 0, 1, X(don’t care), Z(undriven) Vectors of bits Declaration: wire [3:0] A; A vector of 4 bits: A[3], A[2], A[1], A[0] Treated as an unsigned integer value Concatenating bits/vectors into a vector B[7:0] = {A[3], A[3], A[3], A[3], A[3:0]}; B[7:0] = {4{A[3]}, A[3:0]}; ECE 111 Fall 2017

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 00…0011 8'b11 8 00000011 8'b1010_1011 171 10101011 3'd6 decimal 6 110 6'o42 octal 34 100010 8'hAB hexadecimal 42 00…0101010 Slide derived from slides by Harris & Harris from their book

Verilog Numbers 14: ordinary decimal number -14: 2’s complement representation 12’b0000_0100_0110: binary number with 12 bits (‘_’ is ignored) 12’h046: hexadecimal number with 12 bits Verilog values are unsigned by default e.g., C[4:0] = A[3:0] + B[3:0]; if A = 0110 (6) and B = 1010(-6), then C = 10000 not 00000 i.e., B is zero-padded, not sign-extended ECE 111 Fall 2017

Manual Sign Extension module signed_tb; reg [3:0] A, B; reg [4:0] C, D; initial begin A = 6; B = -5; C = A+B; D = {A[3], A} + {B[3], B}; end endmodule Result: C = 17 (10001b) = 6(00110b) + 11(01011b) D = 1(00001b) = 6(00110b) + (-5)(11011b) sign extension ECE 111 Fall 2017

Verilog Operators Type Symbol Operation Type Symbol Operation Arithmetic * Multiply / Division + Add - Subtract % Modulus Unary plus Unary minus Logical ! Logical negation && Logical and || Logical or Relational > Greater than < Less than >= Greater than or equal <= Less than or equal Equality == != inequality Reduction ~ Bitwise negation ~& nand | or ~| nor ^ xor ^~ xnor ~^ Shift >> Right shift << Left shift Concatenation { } Conditional ? conditional ECE 111 Fall 2017

Verilog Operators Examples: assign A = X | (Y & ~Z); use of Boolean operators (~ for bit-wise, ! for logical negation) assign A = X | (Y & ~Z); assign B[3:0] = 4'b01XX; assign C[15:0] = 16'h00ff; assign #3 {Cout, S[3:0]} = A[3:0] + B[3:0] + Cin; bits can take on four values (0, 1, X, Z) variables can be n-bits wide (MSB:LSB) use of arithmetic operator multiple assignment (concatenation) delay of performing computation, only used by simulator, not synthesis ECE 111 Fall 2017

Module Instantiation module MUX_4_1(O, I0, I1, I2, I3, S); input [7:0] I0, I1, I2, I3; input [1:0] S; output [7:0] O; wire [7:0] W0, W1; MUX MUX_1 (W0, I0, I1, S[0]); MUX MUX_2 (W1, I2, I3, S[0]); MUX MUX_3 (O, W0, W1, S[1]); endmodule output of a module is wire, NEVER reg Need to keep the order of i/o ports Instantiation name Submodule name ECE 111 Fall 2017

Module Instantiation module MUX_4_1(O, I0, I1, I2, I3, S); input [7:0] I0, I1, I2, I3; input [1:0] S; output [7:0] O; wire [7:0] W0, W1; MUX MUX_1 (.O(W0), .I0(I0), .I1(I1), .S(S[0])); MUX MUX_2 (.O(W1), .I0(I2), .I1(I3), .S(S[0])); MUX MUX_3 (.O(O), .I0(W0), .I1(W1), .S(S[1])); endmodule i/o ports referenced by name ECE 111 Fall 2017

More Examples module Compare1 (A, B, Equal, Alarger, Blarger); input A, B; output Equal, Alarger, Blarger; assign Equal = (A & B) | (~A & ~B); assign Alarger = (A & ~B); assign Blarger = (~A & B); endmodule ECE 111 Fall 2017

More Example // Make a 4-bit comparator from 4 x 1-bit comparators module Compare4(A4, B4, Equal, Alarger, Blarger); input [3:0] A4, B4; output Equal, Alarger, Blarger; wire e0, e1, e2, e3, Al0, Al1, Al2, Al3, B10, Bl1, Bl2, Bl3; Compare1 cp0(A4[0], B4[0], e0, Al0, Bl0); Compare1 cp1(A4[1], B4[1], e1, Al1, Bl1); Compare1 cp2(A4[2], B4[2], e2, Al2, Bl2); Compare1 cp3(A4[3], B4[3], e3, Al3, Bl3); assign Equal = (e0 & e1 & e2 & e3); assign Alarger = (Al3 | (Al2 & e3) | (Al1 & e3 & e2) | (Al0 & e3 & e2 & e1)); assign Blarger = (~Alarger & ~Equal); endmodule ECE 111 Fall 2017

ModelSim Simulator ECE 111 Fall 2017

Steps Create the project Add/create Verilog files Add testbench Compile and Simulate ECE 111 Fall 2017

Create the Project Open a new project: File > New > Project Specify a name and a location Leave the other two options as default Enter project name here Selected location ECE 111 Fall 2017

Add/Create Files Create new file: Either click on “Create New File” or right click > Add to project > New File Enter a name, Set file type to Verilog Save the file: File > Save (or ctr-S) ECE 111 Fall 2017

Add/Create Files Double click on the file or right click > edit to edit the file Add an existing file: Either click on “Create New File” or right click > Add to project > Existing file, then browse for the file Similarly, add the necessary testbench(s) ECE 111 Fall 2017

Add Testbench Testbench is a simulation specific Verilog file that is used to provide input values to the module under test. In the next two slides we provide a simple Verilog file and corresponding testbench. Detail on testbench later in the course ECE 111 Fall 2017

Add Testbench module first_module( input i1, i2, output o1, o2 ); assign o1 = i1&i2; assign o2 = i1|i2; endmodule ECE 111 Fall 2017

Add Testbench contd.. Testbench module does not have any input/output module first_module_tb; // Inputs reg i1; reg i2; // Outputs wire o1; wire o2; first_module uut ( .i1(i1), .i2(i2), .o1(o1), .o2(o2) ); Testbench module does not have any input/output The inputs will be changed inside an always/initial block Instantiate the module under test contd.. ECE 111 Fall 2017

Add Testbench initial begin i1 = 0; i2 = 0; #100; $display("%d %d %d %d\n", i1, i2, o1, o2); i2 = 1; Wait, only works in simulation Display the values, similar format as printf C , only works in simulation contd.. ECE 111 Fall 2017

Add Testbench i1 = 1; i2 = 0; #100; $display("%d %d %d %d\n", i1, i2, o1, o2); i2 = 1; end endmodule ECE 111 Fall 2017

Compile Select all the files and right click to specify compile order For simple project we can use Auto Generate to generate the order But for larger project we might need to specify the orders by ourselves Compile all after you have specified the order ECE 111 Fall 2017

Simulate Simulate > start simulation Under work > find your testbench file Click ok ECE 111 Fall 2017

Simulate Open wave tab if it did not pop up automatically In Objects tab, drag the desired input/output into the wave tab ECE 111 Fall 2017

Simulate Specify time to run and hit the run next to it ECE 111 Fall 2017

Xilinx ISE Synthesizer ECE 111 Fall 2017

Steps Create the project Add/create Verilog files Add I/O configuration file Synthesize ECE 111 Fall 2017

Open Xilinx ISE Open the corresponding ISE for your computer’s architecture This is Xilinx ISE ECE 111 Fall 2017

Create the Project Click on file > New project ECE 111 Fall 2017

Create the Project Provide a name and a location Click “Next” This will be automatically populated Enter project name here Selected location ECE 111 Fall 2017

Create the Project Set the target FPGA Device family: Spartan-3E Device model: XC3S500E Either select the evaluation board and rest of the fields will be populated automatically Or select the device model. You can find the device model as shown below. Device model ECE 111 Fall 2017

Create the Project Click “Finish” ECE 111 Fall 2017

Add/Create Files Right click on the device name Click “New Source” ECE 111 Fall 2017

Add/Create Files Select “Verilog Module” Provide a name Click “Next” Enter file name here ECE 111 Fall 2017

Add/Create Files You can create input and output ports her. However, I prefer to create them later in the Verilog file. So leave this as it is and click “Next” ECE 111 Fall 2017

Add/Create Files Click “Finish” ECE 111 Fall 2017

Add/Create Files It will open the created Verilog file. It will already have the name of the new module. ECE 111 Fall 2017

Simulate We can use the simulator provided with ISE to simulate the design. However, we prefer ModelSim as the simulator. You can move directly to “Synthesis” Select “Simulation” on the left side panel ECE 111 Fall 2017

Simulate Right click on the device name, Click “New Source” Select “Verilog Test Fixture” Provide a name Click “next” Enter a name ECE 111 Fall 2017

Simulate Select the module you want to test. In this case there is only one module in the design Click “Next”, then click “Finish” ECE 111 Fall 2017

Simulate The ISE will automatically generate a template for you You will now need to add the signal values An example is provided at the next page After changing the value of any input, wait 100ns (#100;) ECE 111 Fall 2017

Simulate module first_module_tb; // Inputs reg i1; reg i2; // Outputs wire o1; wire o2; // Instantiate the Unit Under Test (UUT) first_module uut ( .i1(i1), .i2(i2), .o1(o1), .o2(o2) ); initial begin // Initialize Inputs i1 = 0; i2 = 0; // Wait 100 ns for global reset to finish #100; // Add stimulus here i2 = 1; end endmodule ECE 111 Fall 2017

Simulate Make sure you select the testbench file at the top left navigation panel ECE 111 Fall 2017

Simulate On the middle left panel, double click on “Simulate Behaviorial Model” The ISIM simulator will start Click on the ISIM icon at the task bar to view it ECE 111 Fall 2017

Simulate You can view the waveforms of the simulation signals in ISIM ECE 111 Fall 2017

Synthesis Select “Implementation” Select the device name at the navigation panel on top left ECE 111 Fall 2017

Synthesis We need to add a “ucf” file that will tell where the input and output pins will be connected at the FPGA Right click, then click on “Add source” ECE 111 Fall 2017

Synthesis Find the default ucf file and click “open” (we will provide you the ucf file) ECE 111 Fall 2017

Synthesis ISE will check the format and show a green tick if everything is ok Click “Ok” to finish ECE 111 Fall 2017

Synthesis You will see the ucf file nested under the top module ECE 111 Fall 2017

Synthesis ECE 111 Fall 2017

Synthesis In the ucf file contains the name of the input/output pins and their physical locations (the “LOC” property) In the default ucf file all the entries are commented with “#”. We will uncomment the pins we need. We will connect the inputs to on/off switches and outputs to LED lights on the FPGA evaluation board ECE 111 Fall 2017

Synthesis Find the leds, uncomment the lines by removing the leading “#”, and rename them to o1 and o2 Similarly, rename to switches to i1 and i2 ECE 111 Fall 2017

Synthesis Make sure you select the top module (“first_module” in this case) at the navigation panel on the top left side bar ECE 111 Fall 2017

Synthesis Double click on implement design at the middle left side bar ECE 111 Fall 2017

Synthesis If there implementation is successful you will see green tick marks beside the different processes You can now download the configurtaion file to FPGA We will complete this at the next lesson ECE 111 Fall 2017