The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Similar documents
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

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

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Introduction. Overview. Top-level module. EE108a Lab 3: Bike light

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

Quick Introduction to SystemVerilog: Sequental Logic

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

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Last Lecture. Talked about combinational logic always statements. e.g., module ex2(input logic a, b, c, output logic f); logic t; // internal signal

DIGITAL SYSTEM DESIGN

Digital Design and Computer Architecture

Lab 7 (All Sections) Prelab: Introduction to Verilog

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

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

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

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

Laboratory Exercise 7

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

Since this register file will mimic the MIPS architecture, address zero will always return the value zero regardless of attempts to write to it.

Lecture 32: SystemVerilog

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

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

Digital Design and Computer Architecture J. Spjut & M. Spencer

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

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

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

Last Lecture: Divide by 3 FSM

Writing Circuit Descriptions 8

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

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

EECS 270 Verilog Reference: Sequential Logic

University of Toronto Faculty of Applied Science and Engineering Edward S. Rogers Sr. Department of Electrical and Computer Engineering

FPGA Matrix Multiplier

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Nikhil Gupta. FPGA Challenge Takneek 2012

Lab 7 (All Sections) Prelab: Verilog Review and ALU Datapath and Control

VHDL: RTL Synthesis Basics. 1 of 59

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

Behavioral Modeling and Timing Constraints

SystemVerilog HDL - a programming language

I 3 I 2. ! Language of logic design " Logic optimization, state, timing, CAD tools

14:332:231 DIGITAL LOGIC DESIGN. Verilog Functions and Tasks

Memory Controller. System Integration Issues. Encoding numbers 1GB RAM FSM. Communicating FSMs Clocking, theory and practice. Combinational Logic

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

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

271/471 Verilog Tutorial

Digital Integrated Circuits

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

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

Modeling Sequential Circuits in Verilog

271/469 Verilog Tutorial

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

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

Verilog HDL Introduction

Control in Digital Systems

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

VERILOG: FLIP-FLOPS AND REGISTERS

EEL 4783: HDL in Digital System Design

ECE 551: Digital System *

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

ARM 64-bit Register File

Xilinx ChipScope ICON/VIO/ILA Tutorial

ENEE245 Digital Circuits and Systems Lab Manual

Ripple Counters. Lecture 30 1

Sequential Logic Design

Testbenches for Sequential Circuits... also, Components

Introduction. Purpose. Intended Audience. Conventions. Close

Behavioral Modeling and Timing Constraints

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

Laboratory Exercise 3

Digital Design with SystemVerilog

MIDTERM EXAM March 28, 2018

ECE2029: Introduction to Digital Circuit Design Lab 4 Building a Sequential Logic Circuit A Four Digit 7-Segment Display Driver

Verilog Execution Semantics

First Name: Last Name: PID: CSE 140L Exam. Prof. Tajana Simunic Rosing. Winter 2010

CS232 VHDL Lecture. Types

Standard Gotchas Subtleties in the Verilog and SystemVerilog Standards That Every Engineer Should Know

Course Details: Webpage

Simulate the Design using the XSim Simulator

ENGN 1630: CPLD Simulation Fall ENGN 1630 Fall Simulating XC9572XLs on the ENGN1630 CPLD-II Board Using Xilinx ISim

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

ENEE245 Digital Circuits and Systems Lab Manual

CS/EE Homework 7 Solutions

Midterm Exam ECE 448 Spring 2019 Wednesday, March 6 15 points

Synthesizable Verilog

Using ModelSim to Simulate Logic Circuits in VHDL Designs. 1 Introduction. For Quartus II 13.0

Lab 2 Designing with Verilog

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

Digital Design with FPGAs. By Neeraj Kulkarni

Nonblocking Assignments in Verilog Synthesis; Coding Styles That Kill!

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

Transcription:

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Comp 541 Digital Logic and Computer Design Prof. Montek Singh Fall 2017 Lab #3A: Sequential Design: Counters Issued Wed 9/6/17; Due Wed 9/13/17 (11:59pm) This lab assignment consists of several steps, each building upon the previous. Detailed instructions are provided, including screenshots of many of the steps. Verilog description is provided for almost all of the designs, but some portions of the code have been erased; in those cases, it is your task to complete and test your code carefully. Submission instructions are at the end. You will learn the following: Specifying sequential circuits in SystemVerilog Designing different types of counters Including synchronous reset capabilities Including start/stop functionality in your counters SystemVerilog simulation, and test fixtures with clocks A few new SystemVerilog constructs Part 0: Reading Since we have not yet covered sequential logic in the lectures, here is a list of the relevant sections of the textbook that you must read carefully before proceeding with this lab assignment: Sections 3.2.3 3.2.6: Flip-Flops and Registers Sections 4.4.1 4.4.3: Verilog for Flip-Flops and Registers Section 5.4.1: Counters 1

Part I: A Mod-4 Counter Let us begin by designing a modulo-4 counter, i.e., one that counts in the following sequence: 0, 1, 2, 3, 0, 1, 2, 3, 0,. The counter module will need the following: a 2-bit register to store the current value, a clock input to pace the counting, and a Reset input to synchronously reset the counter to 0. All changes to the counter s value whether counting up or resetting take place at the upward clock transition (i.e., positive edge of clock). Use the following SystemVerilog specification for the counter: This line tells the compiler not to assume that undeclared names are of the default type wire. By suppressing the default type, we are forcing undeclared names to trigger compiler errors. This helps catch undeclared names, typos, etc. Very useful! Use it in every design from now on! This specification uses constructs that is not present in standard Verilog, but are part of SystemVerilog: logic and always_ff. Therefore, when you create a new design source, be sure to choose SystemVerilog as its file type. (If you choose Verilog by mistake, you can change the file type by rightclicking on the file under Design Sources and choosing Source Node Properties. Then, in the pane below (which you might have to pop out), under the General tab, change the type to SystemVerilog.) Name the file CounterMod4.sv. Note the following: The first two lines define some defaults. The time units for all delays (e.g., see the tester) are nanoseconds, with a picosecond resolution. And the default data type for any wires etc. not declared will be none. Without this default_nettype declaration, Verilog treats all undeclared identifiers as wires, which can cause trouble with debugging. By explicitly declaring the types of all undeclared identifiers as none, most such instances will cause compiler errors, forcing us to properly declare them before using them. Use this directive in every design from now on! The inputs are declared as wire type (since they are just wires coming in from outside the module), but the output here is of the logic type, not wire type. The logic type is unique to SystemVerilog, and resolves to different types of structural implementation depending on the complete description. In particular, a logic type variable will resolve to a wire if its description indicates a combinational function. On the other hand, a logic type variable will result in flip-flops being instantiated if its description indicates that state or memory is needed. Thus, the logic type is used to indicate that a variable might (but not necessarily) need flip-flops in its implementation. The logic type used to be called the reg type in Verilog, but that often got confused with the term register. In SystemVerilog, we often simply use the logic type in most instances, letting the compiler infer combinational or sequential logic from the rest of the description. But, if you are certain that you are trying to describe a piece of combinational logic, it is better to declare its output as 2

of the wire type, which will force the compiler to indicate an error is the implementation is noncombinational. The always_ff statement is a new type of SystemVerilog behavioral construct. It is used to specify how the value of a flip-flop (i.e., register) is to be updated. In this example, it states that whenever there is a positive edge of clock [always_ff @(posedge clock)], the value is updated to either value+1 (if counting) or to 0 (if resetting). Thus, since value is updated inside an always_ff construct, it means value will be implemented as sequential logic using flipflops, and not as combinational logic, because the value is only updated at discrete clock ticks and held steady in-between. The assignment operator here specifies what is called a non-blocking assignment, represented by the symbol <=. This is not to be confused with less-than-or-equal! Instead, regard it as a left arrow. Since value is declared to be 2-bit, when incrementing the value 3, it wraps around to 0. To test, use the Verilog test fixture provided on the website (CounterMod4_test.sv). This test fixture does the following: waits 5 ns; starts the clock (positive edge at 6 ns, period of 2 ns); simulates the counter for 5 clock cycles; then asserts the reset signal to reset the counter back to 0; then runs the counter for another 3 clock cycles. Be sure to go through the test fixture line-by-line and understand what each line does! If you format all the waveforms to display in decimal, you should see exactly the following: Part II: A Mod-7 Counter Your task is to design a mod-7 counter (with a synchronous reset), and test it via simulation. Use the mod-4 counter from Part I as a starting point, copy it to file CounterMod7.sv, and make appropriate modifications. In particular, the mod-7 counter will be different in two respects: It needs a 3-bit register for value, instead of the 2-bit register used in Part I. It counts in the sequence 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0,. Note: This sequence length is not a power of 2, so you cannot rely on the counter wrapping around to 0 on its own after reaching 6! Use the SystemVerilog description given below to implement this counter, and appropriately fill in the details that have been blacked out. 3

Simulate the new counter using the SystemVerilog test fixture provided on the website (CounterMod7_test.sv). Be sure you understand every line of the test fixture file! Set the display format to Unsigned Decimal for all the outputs. Your simulation output should look exactly like this: Question 1: Why is the value waveform shown as X for the first two nanoseconds of this simulation? Why does it become 0 at 2 ns? In contrast, for Part I, the value waveform starts out as 0 ; why? Part III: A Mod-7 Counter with an enable signal Copy your mod-7 counter definition from Part II to a new file named CounterMod7Enable.sv. Your task is to modify the mod-7 counter to incorporate an enable signal, which inhibits the counter from counting up at the next (one or many) upward clock transitions. In particular, if enable equals 0, then at the next positive edge of the clock, the counter s value does not change. This will be true as long as enable is low, providing you a means to freeze the counter for as long as you want. Subsequently, when enable is changed back to 1, the counter starts counting again, from where it left off. NOTES: If enable is 0 and reset is 1, the counter should reset. That is, reset has higher priority than disabling. The assignment to value should still be done using a single statement (value <= ), although you are allowed to use nested conditionals. You can also split the statement onto multiple lines for clarity, but it should remain a single statement. 4

Use the Verilog test fixture provided on the website (CounterMod7Enable_test.sv). Once again, look over the test fixture carefully, and be sure you understand every line. Your simulation output should look exactly like this: Part IV: Designing an xy-counter. Design a two-dimensional counter (i.e., xy-counter). This counter steps through a 2D matrix, one row at a time. The matrix range is [0..width-1, 0..height-1]. The counter starts at (x, y) = (0, 0) and increments x to go from (0, 0) to (width-1, 0). Then it wraps around to the beginning of the next line, (0, 1). Similarly, the counter wraps around from the end of the bottom line, (width-1, height-1) back to the top, (0, 0). The counter also has an input called enable that tells the counter whether counting is enabled or disabled. Thus, if enable is 0, the counter does not increment on the next positive edge of clock. Name this module xycounter, and name the source file xycounter.sv. A Verilog template for xycounter is provided below: 5

A Verilog test fixture is provided on the website (xycounter_test.sv). Fill in the details above, simulate using the text fixture, and verify that the counter behaves exactly as shown below. You may try a couple of different sets of values of width and height. But, you need only submit the results for the test fixture as provided. What to submit: A screenshot of the simulator window clearly showing the final simulation result for PART II (use filename waveforms2.png, or other appropriate extension). Do not submit Verilog file. Your answer to Question 1 in PART II (write it in the body of the email). Your Verilog for the counter module in PART III (CounterMod7Enable.sv), and a screenshot of the simulator window clearly showing the final simulation result for PART III (use filename waveforms3.png). Your Verilog for the xy-counter module in PART IV (xycounter.sv), and a screenshot of the simulator window clearly showing the final simulation result for PART IV (use filename waveforms4.png). How to submit: Please submit your work by email as follows: Send email to: comp541-submit-f17@cs.unc.edu Use subject line: Lab 3A Include the five attachments and the text answer as described above CONTINUE ON TO LAB 3B (on course website) 6