ECE 451 Verilog Exercises. Sept 14, 2007. James Barnes (James.Barnes@colostate.edu)



Similar documents
Registers & Counters

More Verilog. 8-bit Register with Synchronous Reset. Shift Register Example. N-bit Register with Asynchronous Reset.

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

LAB #4 Sequential Logic, Latches, Flip-Flops, Shift Registers, and Counters

ECE232: Hardware Organization and Design. Part 3: Verilog Tutorial. Basic Verilog

A New Paradigm for Synchronous State Machine Design in Verilog

Modeling Sequential Elements with Verilog. Prof. Chien-Nan Liu TEL: ext: Sequential Circuit

Modeling Registers and Counters

Digital Design Verification

Life Cycle of a Memory Request. Ring Example: 2 requests for lock 17

Traffic Light Controller. Digital Systems Design. Dr. Ted Shaneyfelt

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

Chapter 5 :: Memory and Logic Arrays

Chapter 7: Advanced Modeling Techniques

Memory Elements. Combinational logic cannot remember

Digital Circuit Design Using Xilinx ISE Tools

Multiplexers Two Types + Verilog

A Verilog HDL Test Bench Primer Application Note

Understanding Verilog Blocking and Non-blocking Assignments

Asynchronous Counters. Asynchronous Counters

Digital Logic Design Sequential circuits

Manchester Encoder-Decoder for Xilinx CPLDs

Cascaded Counters. Page 1 BYU

Digital Design with VHDL

16-bit ALU, Register File and Memory Write Interface

An Integer Square Root Algorithm

Verilog: Blocks

Asynchronous & Synchronous Reset Design Techniques - Part Deux

Computer organization

E158 Intro to CMOS VLSI Design. Alarm Clock

Finite State Machine Design and VHDL Coding Techniques

Using SystemVerilog Assertions for Creating Property-Based Checkers

WEEK 8.1 Registers and Counters. ECE124 Digital Circuits and Systems Page 1

Counters & Shift Registers Chapter 8 of R.P Jain

3. VERILOG HARDWARE DESCRIPTION LANGUAGE

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

State Machines in VHDL

CHAPTER IX REGISTER BLOCKS COUNTERS, SHIFT, AND ROTATE REGISTERS

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

Digital Logic Design. Basics Combinational Circuits Sequential Circuits. Pu-Jen Cheng

MAX II ISP Update with I/O Control & Register Data Retention

Take-Home Exercise. z y x. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

ASYNCHRONOUS COUNTERS

Counters and Decoders

CHAPTER 11: Flip Flops

University of Toronto Faculty of Applied Science and Engineering

Introduction to Digital Design Using Digilent FPGA Boards Block Diagram / Verilog Examples

Modeling Latches and Flip-flops

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

Layout of Multiple Cells

Gates, Circuits, and Boolean Algebra

Vending Machine using Verilog

Design of Digital Circuits (SS16)

ECE410 Design Project Spring 2008 Design and Characterization of a CMOS 8-bit Microprocessor Data Path

Jianjian Song LogicWorks 4 Tutorials (5/15/03) Page 1 of 14

Combinational Logic Design Process

case Statement //8-wide, 4:1 multiplexer module case1 ( input [7:0] a_in, b_in, c_in, d_in, input [1:0] sel, output logic [7:0] d_out);

if-then else : 2-1 mux mux: process (A, B, Select) begin if (select= 1 ) then Z <= A; else Z <= B; end if; end process;

Introduction to CMOS VLSI Design (E158) Lecture 8: Clocking of VLSI Systems

Lab 1: Introduction to Xilinx ISE Tutorial

Lesson 12 Sequential Circuits: Flip-Flops

A low-cost, connection aware, load-balancing solution for distributing Gigabit Ethernet traffic between two intrusion detection systems

System Verilog Testbench Tutorial Using Synopsys EDA Tools

Chapter 13: Verification

a8251 Features General Description Programmable Communications Interface

Module 3: Floyd, Digital Fundamental

Sequential Logic. (Materials taken from: Principles of Computer Hardware by Alan Clements )

Having read this workbook you should be able to: recognise the arrangement of NAND gates used to form an S-R flip-flop.

8 by 8 dot matrix LED displays with Cascadable Serial driver B32CDM8 B48CDM8 B64CDM8 General Description

PLL Dynamic Reconfiguration Author: Karl Kurbjun and Carl Ribbing

Chapter 8. Sequential Circuits for Registers and Counters

EXPERIMENT 8. Flip-Flops and Sequential Circuits

Contents COUNTER. Unit III- Counters

CONSTRAINT RANDOM VERIFICATION OF NETWORK ROUTER FOR SYSTEM ON CHIP APPLICATION

The components. E3: Digital electronics. Goals:

Adder.PPT(10/1/2009) 5.1. Lecture 13. Adder Circuits

Wiki Lab Book. This week is practice for wiki usage during the project.

Decimal Number (base 10) Binary Number (base 2)

SystemVerilog Is Getting Even Better!

Memory unit. 2 k words. n bits per word

Arbitration and Switching Between Bus Masters

Lecture 10: Multiple Clock Domains

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.

Chapter 2 Verilog HDL for Design and Test

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

RTL Low Power Techniques for System-On-Chip Designs

(1) D Flip-Flop with Asynchronous Reset. (2) 4:1 Multiplexor. CS/EE120A VHDL Lab Programming Reference

Memory Testing. Memory testing.1

The 104 Duke_ACC Machine

Lecture-3 MEMORY: Development of Memory:

Sources: On the Web: Slides will be available on:

Introduction to Functional Verification. Niels Burkhardt

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

MICROPROCESSOR AND MICROCOMPUTER BASICS

Programmable Logic Design Grzegorz Budzyń Lecture. 12: VHDL vs Verilog

Flip-Flops and Sequential Circuit Design. ECE 152A Winter 2012

Flip-Flops and Sequential Circuit Design

EE 42/100 Lecture 24: Latches and Flip Flops. Rev B 4/21/2010 (2:04 PM) Prof. Ali M. Niknejad

Transcription:

ECE 451 Verilog Exercises Sept 14, 2007 James Barnes (James.Barnes@colostate.edu)

Organization These slides give a series of self-paced exercises. Read the specification of each exercise and write your code before proceeding to the solution slide. These exercises will be most useful if you have access to a verilog simulator (modelsim, Icarus verilog) as you read these slides. See Dr. Barnes if you need help installing a simulator.

Coding guidelines and standard practices Most design groups larger than a few designers have guidelines and standard practices for writing code. These make it easier to share code, as the code is organized in a way that makes it easier to find things. Disclaimer: each design organization has its own way of doing things. You may encounter different guidelines, but the principle is pretty universal.

Guidelines Logic blocks typically have the form of a combinational logic cloud feeding a register, with possible state feedback. An example would be a counter, where the register holds the count value and the combinational logic updates the count value. This block would have state feedback. Some blocks may have only one of either a combinational logic or a register block. Some blocks may have multiple instances of combinational logic and register blocks. Most organizations do not impose rules on how much can be in any one module this is up to the designer. One common rule is that the outputs must be registered. This gives the next block the maximum time to process and register the signals.

Guidelines A typical logic block is shown below.

Guidelines for register updates Standard practice (a requirement in some organizations) is that the register updates should be done in an always block with NO logic except a synchronous reset. Non-blocking assignments (<=) must be used. The register update section for the previous example would look like always @(posedge clk) begin d3_out <= rst? 1'b0 : d3_nxt; d2_out <= rst? 1'b0 : d2_nxt; d1_out <= rst? 1'b0 : d1_nxt; d0_out <= rst? 1'b0 : d0_nxt; end Reset is done with the conditional assignment. If the test variable (rst here) is true, the value before the : is taken; otherwise, the value after the : is taken.

Guidelines on combinational logic All the combinational logic should be done in one place in the module code and indicated to anyone reading the code through comments. This is true whether the combinational logic is done using wire assignments or an always block. If combinational logic is implemented within an always block, the blocking assignment (=) must be used. This will assure that the combinational logic is evaluated before the register update is done.

Verilog syntax Reminder on some verilog syntax rules: All inputs in a module are of the wire type. You cannot declare inputs to be reg type. You cannot re-assign or change an input. Inputs can only appear on the RHS of assignments or as a test variable in a conditional assignment or control flow statement. Outputs can be either wire or reg. There will be some internal signals which are neither input nor output. For example, the signals d3_nxt,... in the example. All multi-bit signals of wire type must be declared. Single bit input signals need not be declared as they default to wire type. All variables assigned inside a procedural block (initial or always) must be of reg type. All variables of reg type must be explicitly declared.

Exercise 1 2b shifter This is the same logic block as in Q2a of HW #2, but with bus notation for the inputs and outputs. This is a purely combinational logic block. The logic equations are: out[0] = s' in[0] out[1] = s' in[1] + s in[0]

Ex 1 Solution module shifter(in, out, s); input [1:0] in; input s; output [1:0] out; wire s; wire [1:0] in; wire out; assign out[1] = (~s) & in[1] s & in[0]; assign out[0] = (~s) & in[0]; endmodule

Ex 2 3:8 row decoder with enable This decoder has inputs addr[2:0] and an active low enable nen. It drives 8 active high output lines row_sel[7:0], one of which is driven when nen is asserted.

Ex 2 Solution module row_decoder(row_sel, addr, nen); input [2:0] addr; input nen; output [7:0] row_sel; wire [2:0] wire nen; reg [7:0] addr; row_sel; // Use a case statement always @(addr or nen) begin if (nen) row_sel = 8'h0; else case (addr) 3'h0: row_sel = 8'b0000_0001; // The _ is just for readability 3'h1: row_sel = 8'b0000_0010; 3'h2: row_sel = 8'b0000_0100; 3'h3: row_sel = 8'b0000_1000; 3'h4: row_sel = 8'b0001_0000; 3'h5: row_sel = 8'b0010_0000; 3'h6: row_sel = 8'b0100_0000; 3'h7: row_sel = 8'b1000_0000; endcase // case(addr) end // always @ (addr or nen) endmodule // row_decoder

Ex 3 8b register with load and synchronous reset This block implements an 8b wide register from DFFs. All flops are driven by a common clock and have a common reset rst. An input mux allows new data to be loaded into the register when ld is high; otherwise, the old data is recirculated.

Ex 3 Solution module ld_reg8(din, clk, rst, ld, q); input [7:0] din; input clk, rst, ld; output [7:0] q; wire [7:0] din, q_nxt; wire clk, rst, ld; reg [7:0] q; //Logic on register inputs assign q_nxt = ld? din : q; // Update register always @(posedge clk) q <= rst? 8'h0 : q_nxt; endmodule // row_decoder