CME341 Assignment 4. module if\_else\_combinational\_logic( input [3:0] a, b, output reg [3:0] y ); * begin

Similar documents
Nikhil Gupta. FPGA Challenge Takneek 2012

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

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

EE431 April 6, 2009 Midterm Material on Assignments 6 to 10

Experiment VERI: FPGA Design with Verilog (Part 2) (webpage: /)

CSE 591: Advanced Hardware Design and Verification (2012 Spring) LAB #0

HDL Compiler Directives 7

ECEN 468 Advanced Logic Design

Verilog Behavioral Modeling

EEL 4783: HDL in Digital System Design

Lab 7 (All Sections) Prelab: Introduction to Verilog

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

Verilog HDL: Behavioral Counter

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

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

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

EE 231 Fall EE 231 Homework 8 Due October 20, 2010

ENSC E-123: HW D3: Counter Applications; Counter in Verilog

Midterm Exam Thursday, October 24, :00--2:15PM (75 minutes)

Lecture 32: SystemVerilog

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

CSE140L: Components and Design Techniques for Digital Systems Lab

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

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

Post-Synthesis Simulation. VITAL Models, SDF Files, Timing Simulation

CSE140L: Components and Design

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

P-1/P-105. Samir Palnitkar. Prentice-Hall, Inc. INSTRUCTOR : CHING-LUNG SU.

Synthesizable Verilog

Laboratory Exercise 7

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

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Logic Circuits II ECE 2411 Thursday 4:45pm-7:20pm. Lecture 3

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

Simple Behavioral Model: the always block

Lab 7 (Sections 300, 301 and 302) Prelab: Introduction to Verilog

Synplify Pro for Microsemi Edition Release Notes Version L M-G5, November 2016

Introduction to Digital Design with Verilog HDL

Speaker: Shao-Wei Feng Adviser: Prof. An-Yeu Wu Date: 2010/09/28

Hardware Description Languages: Verilog

Quick Introduction to SystemVerilog: Sequental Logic

Verilog For Synthesis

Verilog for Synthesis Ing. Pullini Antonio

Techniques for Digital Systems Lab. Verilog HDL. Tajana Simunic Rosing. Source: Eric Crabill, Xilinx

Course Topics - Outline

Verilog introduction. Embedded and Ambient Systems Lab

Digital Design and Computer Architecture

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

VERILOG 2: LANGUAGE BASICS

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

Lab 1.5 (Warmup): Synthesis Workflow and SystemVerilog Register File Not Due

ES611 FPGA Based System Design. Behavioral Model

Chap 6 Introduction to HDL (d)

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

yamin/

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

Synthesis of Combinational and Sequential Circuits with Verilog

Digital Design Using Verilog EE Final Examination

EE183 LAB TUTORIAL. Introduction. Projects. Design Entry

Verilog Nonblocking Assignments with Delays - Myths & Mysteries

Amrita Vishwa Vidyapeetham. EC429 VLSI System Design Answer Key

Tutorial: Working with the Xilinx tools 14.4

SystemVerilog HDL - a programming language

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

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

Tutorial 2 Implementing Circuits in Altera Devices

Digital Systems EEE4084F FPGA Introduction Verilog and Xilinx ISE [30 Marks]

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

Tutorial 3. Appendix D. D.1 Design Using Verilog Code. The Ripple-Carry Adder Code. Functional Simulation

ECE1387 Exercise 3: Using the LegUp High-level Synthesis Framework

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay Dept of CSE, IIT Madras 1

An easy to read reference is:

Digital Integrated Circuits

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

EN2911X: Reconfigurable Computing Lecture 05: Verilog (2)

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Introduction to Verilog. Mitch Trope EECS 240 Spring 2004

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

Online Verilog Resources

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

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>

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

ECE 353 Lab 3 (Verilog Design Approach)

VERILOG. Deepjyoti Borah, Diwahar Jawahar

Writing Circuit Descriptions 8

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

Introduction. In this exercise you will:

Hardware Description Language (HDL)

Control in Digital Systems

Introduction to Verilog

HDL. Hardware Description Languages extensively used for:

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

Transcription:

CME341 Assignment 4 1. The verilog description below is an example of how code can get butchered by an engineer with lazy debugging habits. The lazy debugger wanted to try something and yet be able to easily reverse the change without thinking. To do this the engineer added a begin-end wrapper and then a second if-else statement. When the change worked the lazy debugger didn t delete the first if-else statement. A U of S grad would have changed a==4 b1111 to a==4 b0111 and not added the second if-else statement or the begin-end wrapper. module if\_else\_combinational\_logic( input [3:0] a, b, output reg [3:0] y ); always @ * begin if (a==4 b1111) y=b; else y=~b; if (a==4 b0111) y=b; else y=~b; end endmodule (a) Enter the Verilog HDL above and compile it. Does the compiler issue a warning about ignoring the first if-else statement? (b) Simulate the circuit and verify that the first if-else statement is ignored. 2. Modify the if else combinational logic prototype given in question 1 by deleting the begin and end statements. (a) The modified prototype violates the rules for a procedure (i.e. always ). What is the problem? 1

(b) Compile the modified prototype and carefully read the error. Does the error message explain the problem? (c) Over the course of the year most students will encounter this error message several times, and not because they are lazy debuggers. Is the most likely reason: Reason 1: The student forgot to include the begin-end wrapper. Reason 2: The student wrote the body of procedure without putting the always line at the top of it. (d) Is it good practice to routinely place begin-end wrappers around an always procedure? Could this mask some typos that the complier would otherwise flag (for example a sequence of nested if-else statements where an else has inadvertently been omitted)? 3. Generate a table that shows the output versus the 16 possible values of select for the module case statement example given below. For example the entry in your table for select=4 b1111 should be data 0. module case_statement_example (select, data_0, data_1, data_2, data_3, data_out); /* ****** IMPORTANT NOTE ********** Some compilers, for example MAX PLUS II, do not handle "don t cares" properly - but some do, for example Leonardo Spectrum */ input [3:0] select; input [1:0] data_0, data_1, data_2, data_3; output [1:0] data_out; reg [1:0] data_out; always @ (select or data_0 or data_1 or data_2 or data_3) begin casex (select) // case x is used when don t cares are // used in the case item 2

4 b1xxx : data_out = data_0; // if (select[3]==1) 4 bx1xx : data_out = data_1; // else if (select[2]==1 4 bxx1x : data_out = data_2; // else if (select[1]==1) 4 bxxx1 : data_out = data_3; // else if (select[0]==1) default : data_out = 2 b00; // else endcase end endmodule 4. Compile the Verilog HDL in Question 3 and determine if the Quartus compiler handles the don t cares properly. 5. Compose a Verilog HDL for a combinational logic circuit that increments an 8 bit input variable called low number by either 1, 7, 255 or 249 when the value of a two bit variable, select, is 0, 1, 2 and 3 respectively. The output variable, which is called high number, is an 8 bit vector. Compile and test the resulting circuit. 6. Compose a Verilog HDL for a combinational logic circuit that interleaves two 16 bit input vectors, A and B, to make one 32 bit output vector, C. That is, make C[0]=A[0], C[1]=B[0], C[2]=A[1],..., C[31]=B[15]. Please use a for loop in your design. Compile and test the resulting circuit. 7. (a) There is a typo in the program below. The 3 b1001 should be 4 b1001. (This happens from time to time.). The vector a does not respond to vector b as intended. With the typo, the value of a does not depend on b. Why? module literal_ex (b, a); input [3:0] b; output [3:0] a; reg [3:0] a; always @ * if ( (&b)==1 b1 ) a=3 b1001; else a=4 b0001; 3

endmodule (b) Compile the program. In the testbench make the signal b count from 0 to 4 b1111 in increments of 1 at intervals of 1 µs. This can be done with the verilog commands given below: initial b=4 H0; always #1000 b = b + 4 H1; // the delay of 1000 assumes // a timescale of 1 ns Simulate the program and verify that x=4 b0001 for all values of b. (c) Determine how the compiler handles such typos? 8. Draw schematic diagrams for the sequential circuits described by the Verilog HDL segments given below. (Note that these descriptions are intended to demonstrate different constructs and are not necessarily good descriptions or useful circuits.) (a) input clk, toggle; output q; if (toggle == 1 b1) q = ~q; else q = q; (b) input d, clk_enable, clk; output q; if (clk_enable == 1 b1) q = d; else q = q; (c) input d, set, clear, clk; output q; if (set == 1 b1) q = 1 b1; else if (clear == 1 b1) q = 1 b0; 4

else q = d; (d) input d, set, clear, clk; output q; always @ (posedge clk or posedge clear or posedge set) if (set == 1 b1) q = 1 b1; else if (clear == 1 b1) q = 1 b0; else q = d; (e) input clk, input [3:0] d; output [3:0] q; reg [3:0] q; casex({d[3],d[1]}) 2 b00 : begin q[3]=1 b0; q[2:0] = q[2:0]; end 2 b1x : begin q[3] = ~q[3]; q[2:0] = 3 b000; end default: q = d; endcase (f) input clk, input d; output [3:0] q; reg [3:0] q; integer i; begin for(i = 2; i >= 0; i = i-1) q[i+1] = q[i]; q[0] = d; end 9. (a) Generate structural descriptions, in Verilog, of your hardware schematics (i.e. use primitives for each hardware element in the schematic diagrams). Use DFFE (which is not a true Verilog primitive but is built into most compilers) to instantiate your flip/flops. This is a prototype for a d-flip/flop with enable and asynchronous clear and set. An example instantiation of DFFE is given below. Inputs clrn and prn are active low, input ena is active high. You do not need to provide connections to inputs clrn, prn or ena if 5

they are not used. DFFE flop_1(.d(d), // the d input.clk(clk), // the clock, positive edge trigger.ena(enable), // if used, d goes to q on clock edge when ena is // high otherwise q does not change.clrn(clear_bar), // if used, clears q when low.prn(set_bar), // if used, sets q when low.q(q) // output ); // NOTE if clrn and prn are both active (i.e. both low) the // output, q, is undefined. (b) Compile your circuits and test them using the simulator. Before compiling a design that uses flip/flops, you should enter some information on the clock used. If this is not done Quartus issues a warning: Quartus 8.5 generates the warning Found pins functioning as undefined clocks and/or memory enables, while Quartus 12 generates: Critical warning (332148) : Timing requirements not met. In either case the compiler will build a circuit that can be simulated. (i.e. Quatus 12 generates a.vo file). The proper way to address this warning is: Quartus II v8.5: Select Assignments. This will pop up a page with a list on the left hand side. Expand Timing Analysis Settings to show its sub-menu. Click on classic timing analyser settings. The will open a page on the right hand side of the window called classic timing analyser settings. Click on individual Clocks and select New. In this window you have to select the node (i.e. the name of the clock used in your design) and give it a name that the timing analyser uses. Name the clock input, perhaps call it clock 1, and select the node that is used for the clock (Most examples in 6

class have the clock node named clk.). Choose 1 MHz for the Required fmax setting. The timing analysis report will then tell you if your circuit is able to operate at that clock frequency. Quartus II v12.0 Select Assignments TimeQuest Timing Analyser Wizard.... Once the wizard is activated click next to advance to the clock setting window. In this window there are 5 fields labelled: Clock Name; Input Pin; Period; Rising; and Falling. Only the first three fields need to be completed. Clock Name: Enter another name for the clock - say system clock. Input Pin: Enter the name of the clock used in the design (i.e. enter clk ii there is an in the Verilog HDL description). Period: Enter the period of the clock. (Enter 1 µs unless the questions asks to do otherwise.) Rising: Leave this field blank. It is used to specify a phase offset. To be specific, it specifies the time of the rising edge as a fraction of the period. The default setting is 0.0. Falling: Leave this field blank. It is used to specify the duty cycle. To be specific, it specifies the time of the falling edge as a fraction of the period. The default setting is 0.5. These setting will be put into a Synopsys Design Constraints (.SDC) file. The commands generated from the entries will be shown in the SDC command segment of the window, which is just beneath the base clock settings segment of the window. Observe and remember these commands (perhaps cut and paste this into a temporary file to avoid remembering the command). After entering the clock settings click next a few time until the summary window is reached. NB: Once the summary is reached check mark the box (if it is not already check marked) that indicates Add this output SDC file to the current project and then click finish. After finishing verify that the SDC script file was properly created. 7

The is done by selecting file open and then in the type of file box selecting Script files (*.tcl *.sdc *.qip *.sip). The file counter.sdc should appear in the directory window. Double click on counter.sdc to see its contents. This file can be created and edited directly without going through the TimeQuest Timing Analyser Wizard. 10. (a) Take the behavioral descriptions from which you derived the schematics and flesh them out to complete modules. Things like module declarations have to be added and there may be syntax errors that need to be fixed. (b) Compile your descriptions and test the resulting circuits using the simulator. (c) Compare the results of the simulations of the behavioral descriptions to the results of the simulations of the structural descriptions to verify that your schematic diagrams are correct. 8