Lab 2 EECE473 Computer Organization & Architecture University of Maine

Similar documents
Introduction to VHDL Design on Quartus II and DE2 Board

CPE 200L LABORATORY 4: INTRODUCTION TO DE2 BOARD UNIVERSITY OF NEVADA, LAS VEGAS GOALS: BACKGROUND:

EMT1250 LABORATORY EXPERIMENT. EXPERIMENT # 7: VHDL and DE2 Board. Name: Date:

Lab 4: Register File and Memory 50 points Instructor: Yifeng Zhu Due: One week

ECE 3610 Microprocessing Systems Lab #1 Verilog Design of the TOC Using Quartus II

NOTE: This tutorial contains many large illustrations. Page breaks have been added to keep images on the same page as the step that they represent.

NIOS CPU Based Embedded Computer System on Programmable Chip

Tutorial on Quartus II Introduction Using Verilog Code

PRELAB! Read the entire lab, and complete the prelab questions (Q1- Q3) on the answer sheet before coming to the laboratory.

FPGA Introductory Tutorial: Part 1

EE 231 Fall Lab 1: Introduction to Verilog HDL and Altera IDE

Quartus II Introduction Using Verilog Design

Tutorial on Quartus II Introduction Using Schematic Designs

2 nd Year Laboratory. Experiment: FPGA Design with Verilog. Department of Electrical & Electronic Engineering. Imperial College London.

Laboratory Exercise 1

University of Massachusetts Amherst Computer Systems Lab 2 (ECE 354) Spring Lab 1: Using Nios 2 processor for code execution on FPGA

University of California, Davis Department of Electrical and Computer Engineering. Lab 1: Implementing Combinational Logic in the MAX10 FPGA

Introduction to the Altera SOPC Builder Using Verilog Design

Quartus II Introduction Using Schematic Design

CSE P567 - Winter 2010 Lab 1 Introduction to FGPA CAD Tools

CSEE W4840 Embedded System Design Lab 1

NIOS CPU Based Embedded Computer System on Programmable Chip

NIOS CPU Based Embedded Computer System on Programmable Chip

IMPLEMENTING COUNTERS

EE 231 Fall EE 231 Lab 2

Terasic DE0 Field Programmable Gate Array (FPGA) Development Board

Chapter 2 Getting Hands on Altera Quartus II Software

Tutorial for Altera DE1 and Quartus II

ECE241 - Digital Systems. University of Toronto. Lab #2 - Fall Introduction Computer-Aided Design Software, the DE2 Board and Simple Logic

The development board used in this class is ALTERA s DE The board provides the following hardware:

EMT1250 LABORATORY EXPERIMENT. EXPERIMENT # 10: Implementing Binary Adders. Name: Date:

Laboratory Exercise 7

Quick Tutorial for Quartus II & ModelSim Altera

Quartus II Introduction Using Verilog Designs. 1 Introduction. For Quartus II 12.0

Introduction to the Altera SOPC Builder Using Verilog Designs. 1 Introduction

Lab 6: Integrated the Decoder with Muti-bit Counter and Programming a FPGA

Lab 2: Introduction to Verilog HDL and Quartus

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180A DIGITAL SYSTEMS I Winter 2015

Experiment VERI: FPGA Design with Verilog (Part 1)

Laboratory Exercise 3 Comparative Analysis of Hardware and Emulation Forms of Signed 32-Bit Multiplication

CSEE W4840 Embedded System Design Lab 1

QUARTUS II Altera Corporation

Chapter 2: Hardware Design Flow Using Verilog in Quartus II

Quartus II Tutorial. September 10, 2014 Quartus II Version 14.0

Lab 3: Standard Combinational Components

EN2911X: Reconfigurable Computing Lecture 01: Introduction

Laboratory Exercise 3

The board is powered by the USB connection, so to turn it on or off you plug it in or unplug it, respectively.

Chip Design with FPGA Design Tools

FPGA Development Board Hardware and I/O Features

Laboratory Exercise 8

CSEE W4840 Embedded System Design Lab 1

1 Introduction 2. 2 Background 3. 3 Getting Started 4. 4 Starting a New Project 6. 5 Design Entry Using VHDL Code 13

PRELAB! Read the entire lab, and complete the prelab questions (Q1-Q3) on the answer sheet before coming to the laboratory.

Quartus II Version 14.0 Tutorial Created September 10, 2014; Last Updated January 9, 2017

Digital Systems Laboratory

CET4805 Component and Subsystem Design II. EXPERIMENT # 5: Adders. Name: Date:

DE2 Function Library Manual

Engineering 303 Digital Logic Design Spring 2017

DKAN0011A Setting Up a Nios II System with SDRAM on the DE2

Laboratory 4 Design a Muti-bit Counter and Programming a FPGA

Laboratory Experiment Mastering Digital Design

ECE 491 Laboratory 1 Introducing FPGA Design with Verilog September 6, 2004

TLL5000 Electronic System Design Base Module

ECE 437 Computer Architecture and Organization Lab 6: Programming RAM and ROM Due: Thursday, November 3

Laboratory 4 Design a Muti-bit Counter

University of Florida EEL 3701 Dr. Eric M. Schwartz Madison Emas, TA Department of Electrical & Computer Engineering Revision 1 5-Jun-17

DE2 Board & Quartus II Software

SignalTap II with Verilog Designs. 1 Introduction. For Quartus II 13.1

CME341 Laboratory Manual

TLL5000 Electronic System Design Base Module. Getting Started Guide, Ver 3.4

ECSE-323 Digital System Design. Lab #1 Using the Altera Quartus II Software Fall 2008

EXPERIMENT 1. INTRODUCTION TO ALTERA

My First FPGA for Altera DE2-115 Board

Configuration and programming minimodules MMfpga01 and MMfpga11

Building Combinatorial Circuit Using Behavioral Modeling Lab

QuartusII.doc 25/02/2005 Page 1

University of Massachusetts Amherst Computer Systems Lab 1 (ECE 354) LAB 1 Reference Manual

Laboratory Exercise 9

Graduate Institute of Electronics Engineering, NTU Advanced VLSI SOPC design flow

Physics 536 Spring Illustrating the FPGA design process using Quartus II design software and the Cyclone II FPGA Starter Board.

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

Experiment 8 Introduction to VHDL

SFWR ENG 2DA4 Lab 1. Announcements: Marking Scheme: Lab Safety Manual:

The University of Toledo EECS:6660:0xxField Programmable Gate Arrays s09l1.fm - 1 Dr. A.D. Johnson

EE 1315 DIGITAL LOGIC LAB EE Dept, UMD

ECE241 - Digital Systems

ECE 353 Lab 4. MIDI Receiver in Verilog. Professor Daniel Holcomb UMass Amherst Fall 2016

Introduction to Verilog HDL

E85: Digital Design and Computer Architecture J. Spjut and R. Wang Spring 2014

SOPC LAB1. I. Introduction. II. Lab contents. 4-bit count up counter. Advanced VLSI Due Wednesday, 01/08/2003

CSCB58 - Lab 0. Intro to The Lab & The DE2 Board. Prelab /4 Part I (in-lab) /1 Part II (in-lab) /1

UNIVERSITI MALAYSIA PERLIS

Making Qsys Components. 1 Introduction. For Quartus II 13.0

Laboratory Exercise 5

Tutorial: ISE 12.2 and the Spartan3e Board v August 2010

Contents. Appendix B HDL Entry Tutorial 2 Page 1 of 14

Tutorial 2 Implementing Circuits in Altera Devices

SCHEMATIC DESIGN IN QUARTUS

Transcription:

Lab 2: Verilog Programming Instructor: Yifeng Zhu 50 Points Objectives: 1. Quatus II Programming assignment: PIN assignments, LEDs, switches; 2. Download and test the design on Altera DE2 board 3. Create digital circuit by using Verilog code 4. Design 7-segment display In-lab demonstration: 1. Light up a LED by using a switch (Schematic Design) 10 points 2. Light up a LED if more than two switches are 1 (Verilog Design) 15 points 3. Correctly show the hex values on 7-segment Displays 25 points What to hand in: 1. TA Checkoff sheet with TA s grading and signature. 1. Introduction to DE2 Development Board The DE2 (shown on the above) is designed to support a wide range of experiments. It combines a variety of logic and I/O devices onto a single printed-circuit board and allows you to configure and control these devices to create different applications. The logic devices on the DE2 are an FPGA (a programmable logic device) and several memory components (SDRAM, SRAM, and flash RAM). The I/O devices on the DE2 are a small LCD display, numerous LEDs (lights), and switches. In addition, the DE2 has connections to a variety of external I/O The author (Yifeng Zhu) gratefully acknowledges borrowing parts of this homework assignment from ENGINEERING 100 (Section 700) Introduction to Computing Systems 2006 by Dr. Peter Chen. 1

devices, including PS/2 (keyboard and mouse), USB, VGA (video), audio (microphone and speaker), TV, Ethernet, RS-232 (serial port), Secure Digital and IrDA (infrared). 2. Light up a LED by using a Switch (Schematic Design) LEDs (light-emitting diodes) are digital lights. Each LED is controlled (i.e., set to on or off) by a single wire. The LED will be on if the wire has the value 1 and off if the wire has the value 0. A switch is used to input a value (0 or 1) to the DE2. There are two types of switches on the DE2. 1) Create a new project a. File New Project Wizard b. Named the project as LED_Schematic c. Select the device EP2C35F672C6 (DE2) in the Cyclone II family, which is the FPGA chip on the Altera DE2 board. You can also change the device: Assignments Device Select Cyclone II EP2C35F672C6 as the target chip 2) Create a Schematic Design, and make it as the top entity. The Schematic Design will have one input pin and one output pin. The input pin is named as SW[0] and the output pin is named as LEDR[0]. The two PINs are connected together via a NOT gate. 3) Perform PIN Assignments: Perform Pin Assignments. If you want to assign the pin numbers for inputs and outputs manually, you can find the Pin table from http://arch.eece.maine.edu/wiki/images/6/67/de2_pin_table.pdf. A simpler approach is to import the pin assignments from a cvs file and label your pins according to the name shown in the pin table. (For example label one 4-bit input as SW[7..4] to assign that value to the corresponding 4 switches.) You can get the DE2 PIN assignment comma separated value (csv) format file from (DE2_pin_assignments.csv). Copy this file to your working directory and import it into your project by choosing Assignments Import Assignments. After importing the PIN assignments, you can use pin names, instead of pin numbers to directly access input or output pins. For example, the DE2 board provides 18 toggle switches, called SW17 0, that can be used as inputs to a circuit, and 18 red lights, called LEDR17 0, that can be used to display output values. 4) Synthesis/Compile: The compile process may take over twenty minutes. A smart compiler can significantly reduce the compile time. Follow the menu: Processing Compiler Tool Analysis & Synthesis Settings. If your project is large (such as Project 2 and 3 of this course), enabling smart compilation will significantly save you compilation time. 2

Downloading the LED_Schematic.sof file to the DE2 board through USB-Blaster. a) Connect the DE2 board to the host computer by means of a USB cable plugged into the USB- Blaster port. b) Turn on the power to the DE2 board. Ensure that the RUN/PROG switch is in the RUN position. c) Select Tools Programmer. d) If not already chosen by default, select JTAG in the Mode box. Also, if the USB-Blaster is not chosen by default, click the "Hardware Setup..." button and select the USB-Blaster in the window that pops up. Note: if USB-Blaster does not appear, go to "Devices" on the Windows 2000 Professional window and check the box that says "Altera USB-Blaster" e) If you use your own computer to program the Altera DE2 boards, you might need to install the USB-Blaster Driver. You can download the driver from here: http://www.altera.com/download/drivers/dri-index.html f) The configuration file yourproject.sof should be listed in the window. If the file is not already listed, then click g) Add File and select it. h) Click the box under Program/Configure to select this action. i) Press Start to configure the FPGA. 5) Demo to TA if you complete. 3. Light up a LED by using Switches (Verilog Coding) In this project, you will develop a project based Verilog that uses a DIP switch to light up a LED. Specifically, if more than two switches are 1, then the LED is lighted up. The dip switches used in this circuit are SW[0] (labeled SW0 on the board) and SW[1] (labeled SW1 on the board). During the testing, move the levers of these switches between 0 (closer to the front edge of the DE2) and 1 (away from the front edge of the DE2) and observe the output of LEDR[0] (the LED directly above SW[0]). 1) Create a new project a. File New Project Wizard (Make sure that this project is stored in a different folder than your previous one) b. Named the project as LED_Verilog c. Select the device EP2C35F672C6 (DE2) in the Cyclone II family 2) Perform PIN import as Step 2 of the previous project. 3) Crate a Verilog File invoked through Quartus' File menu (File New Device Design Files tab Verilog HDL File) 4) Type in the following Verilog code and save the code as top.v a. Save the code as top.v (File Save As). Quartus adds the ".v" extension automatically, so you need only type top as the file name. b. Make sure the box is checked to add this file automatically to the current project. 5) Demo to TA after you complete. 3

// file top.v // The output of the LED will be 1 if and only if // two or more of the dip switches are 1. module top( input wire [17:0] SW, output reg [17:0] LEDR); always @* begin if (SW[0] == 1'b1 && SW[1] == 1'b1) begin LEDR[0] = 1'b1; end else if (SW[0] == 1'b1 && SW[2] == 1'b1) begin LEDR[0] = 1'b1; end else if (SW[1] == 1'b1 && SW[2] == 1'b1) begin LEDR[0] = 1'b1; end else begin LEDR[0] = 1'b0; // default value is 0 end end endmodule A few points about the Verilog code above: a. The code describes the circuit for the module top. This module name corresponds to the name of the toplevel design entity you specified when creating the Quartus project. b. 1'b0 and 1'b1 are how you express numbers in Verilog. The number before the ' indicates the number of bits in the number; in this case, we are expressing a 1-bit number. The letter after the ' indicates which base the number is in; in this case, we are expressing numbers in base 2, or binary, denoted by the letter b. The number after the letter indicates the value of the number; in this case, we are expressing the numbers 0 and 1. Other possible bases for expressing numbers are decimal (denoted by the letter d) and hexadecimal (denoted by the letter h). For example, an 8-bit number with the value 200 could be written as 8'd200 or 8'b11001000 or 8'hc8. c. The module takes an input variable (SW) and produces an output variable (LEDR). Each variable is declared as an array of 18 bits (bits 17 through 0). The file top.qsf that you downloaded when you created the project connects the SW array to the 18 dip switches on the DE2. Similarly, top.qsf connects the LEDR array to the 18 red LEDs on the DE2. d. Each variable in Verilog (such as SW and LEDR) is declared as type wire or type reg. Use the following rule to determine which type to use for a variable: if the variable is assigned a value in the module (through a statement such as LEDR[0] = 1'b1), it should be declared reg. Otherwise it should be declared wire. e. The code block starting with always @* specifies the relationship between LEDR and SW. It specifies how the value of LEDR[0] (the 0th element of the LEDR array) depends on the values of SW[0], SW[1], and SW[2]. always @* means "continuously drive the wire LEDR based on the value of computed in this block. In this case, the value will depend on SW and will implement a "majority vote": the output of the LED will be 1 if and only if two or more of the dip switches are 1. f. The syntax of Verilog is similar to that of C++. a. The operators =, ==, and && have the same meaning as in C++. Other operators that have the same meaning as in C++ are comparison operators (<, >, <=, >=,!=), logical operators (&&,,!), 4

addition/subtraction (+, -), and bitwise operators (<<, >>, &,, ~). (Avoid using from multiply/divide (*, /), as they are difficult to synthesize into an FPGA circuit.) b. If... else if... else work exactly as they do in C++. All if statements in Verilog should end with an unconditional else clause. c. begin... end are used to group lines of code into a single block, just as {... } work in C++. d. As with C++, Verilog ignores white space, uses // or /*... */ for comments, and is case sensitive. 4. Seven-segment LEDs based on Multi-module Verilog Hexadecimal (base 16) is a common way to represent numbers in digital circuits. Each hex digit shows the value of 4 bits of the number (value 0-15): Value 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F Create a new Quartus project called SevenSegmentLED. As always, the top-level design entity for the project will be a module named top. Next, complete the Verilog module hexdigit. hexdigit takes as input a 4-bit number (in) and produces a 7-bit array of values (out) based on the input value. The bits of out are meant to control the segments of a 7-segment LED, as per the following diagram: out[5] out[4] out[0] -------- out[6] -------- -------- out[3] out[1] out[2] For each bit of out, the value 0 causes that segment of the LED to be lit, and the value 1 causes that segment of the LED to be off. This is opposite from the LEDR devices you used in Lab 1. Complete the code so that the value of out returned by hexdigit generates a human-readable picture of the input value on the 7-segment LED. Remember that each output value must be defined for each combination of input values (usually by having an unconditional else clause in each if statement). Also remember that multi-bit values are specified with the mostsignificant bit on the left. E.g., out = 7'b0110000; is shorthand for: out[6] = 1'b0; out[5] = 1'b1; out[4] = 1'b1; out[3] = 1'b0; out[2] = 1'b0; out[1] = 1'b0; out[0] = 1'b0; 5

The table below shows how the segments in Figure 2 correspond to the pin names from the DE2_pin_assignments.csv file. Display Segment Wires for HEX0 Wires for HEX1 0 HEX0[0] HEX1[0] 1 HEX0[1] HEX1[1] 2 HEX0[2] HEX1[2] 3 HEX0[3] HEX1[3] 4 HEX0[4] HEX1[4] 5 HEX0[5] HEX1[5] 6 HEX0[6] HEX1[6] The same naming convention is used for all of the Hex displays on the DE2 board. The following is the top.v // file top.v module top( input wire [17:0] SW, output wire [6:0] HEX0, output wire [6:0] HEX1); hexdigit (SW[3:0], HEX0); hexdigit (SW[7:4], HEX1); endmodule The following is an incomplete hexdigit.v and please complete the code. // file hexdigit.v module hexdigit ( input wire [3:0] in, output reg [6:0] out); always @* begin if (in == 4'h0) begin out = end endmodule Compile, download, and test your circuit. You should use the switches to control the value of 7-segment LEDs display. Demo to TA if you complete. 6

ECE 473 Lab 2 TA Checkoff Sheet Name: Date: Final Grade: 1) Light up a LED by using a switch (Schematic Design) 10 points Grade TA Signature:, Time: Comments: 2) Light up a LED if more than two switches are 1 (Verilog Design) 15 points Grade TA Signature:, Time: Comments: 3) Correctly show the hex values on 7-segment Displays 25 points Grade TA Signature:, Time: Comments: 7