Modeling Registers and Counters



Similar documents
Modeling Latches and Flip-flops

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

Registers & Counters

Counters & Shift Registers Chapter 8 of R.P Jain

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

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

Module 3: Floyd, Digital Fundamental

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

Asynchronous Counters. Asynchronous Counters

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

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

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

Digital Logic Design Sequential circuits

EXPERIMENT 8. Flip-Flops and Sequential Circuits

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

Lab 1: Introduction to Xilinx ISE Tutorial

Digital Circuit Design Using Xilinx ISE Tools

Design Example: Counters. Design Example: Counters. 3-Bit Binary Counter. 3-Bit Binary Counter. Other useful counters:

A New Paradigm for Synchronous State Machine Design in Verilog

RAPID PROTOTYPING OF DIGITAL SYSTEMS Second Edition

Counters and Decoders

A Verilog HDL Test Bench Primer Application Note

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

ECE 451 Verilog Exercises. Sept 14, James Barnes

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

Chapter 7. Registers & Register Transfers. J.J. Shann. J. J. Shann

Design and Implementation of Vending Machine using Verilog HDL

ASYNCHRONOUS COUNTERS

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

Multiplexers Two Types + Verilog

Manchester Encoder-Decoder for Xilinx CPLDs

DIGITAL ELECTRONICS. Counters. By: Electrical Engineering Department

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

Memory Elements. Combinational logic cannot remember

DDS. 16-bit Direct Digital Synthesizer / Periodic waveform generator Rev Key Design Features. Block Diagram. Generic Parameters.

Chapter 8. Sequential Circuits for Registers and Counters

Digital Electronics Detailed Outline

Lab 17: Building a 4-Digit 7-Segment LED Decoder

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

CHAPTER 11: Flip Flops

Finite State Machine Design A Vending Machine

DATA SHEET. HEF40193B MSI 4-bit up/down binary counter. For a complete data sheet, please also download: INTEGRATED CIRCUITS

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

Cascaded Counters. Page 1 BYU

CHAPTER IX REGISTER BLOCKS COUNTERS, SHIFT, AND ROTATE REGISTERS

Lab 1: Full Adder 0.0

DIGITAL TECHNICS II. Dr. Bálint Pődör. Óbuda University, Microelectronics and Technology Institute. 2nd (Spring) term 2012/2013

An Integer Square Root Algorithm

Asynchronous counters, except for the first block, work independently from a system clock.

VHDL Test Bench Tutorial

Lecture 8: Synchronous Digital Systems

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

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

Flip-Flops and Sequential Circuit Design

How To Fix A 3 Bit Error In Data From A Data Point To A Bit Code (Data Point) With A Power Source (Data Source) And A Power Cell (Power Source)

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE

Microprocessor & Assembly Language

EC313 - VHDL State Machine Example

Chapter 7: Advanced Modeling Techniques

Counters are sequential circuits which "count" through a specific state sequence.

Counters. Present State Next State A B A B

16-bit ALU, Register File and Memory Write Interface

A Digital Timer Implementation using 7 Segment Displays

Finite State Machine Design and VHDL Coding Techniques

Combinational Logic Design Process

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

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

Upon completion of unit 1.1, students will be able to

DEPARTMENT OF INFORMATION TECHNLOGY

Digital Design Verification

9/14/ :38

Technical Aspects of Creating and Assessing a Learning Environment in Digital Electronics for High School Students

Contents COUNTER. Unit III- Counters

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

Chapter 9 Latches, Flip-Flops, and Timers

Sequential Logic: Clocks, Registers, etc.

Copyright Peter R. Rony All rights reserved.

The 104 Duke_ACC Machine

Lecture-3 MEMORY: Development of Memory:

ESP-CV Custom Design Formal Equivalence Checking Based on Symbolic Simulation

Source-Synchronous Serialization and Deserialization (up to 1050 Mb/s) Author: NIck Sawyer

Implementation of Web-Server Using Altera DE2-70 FPGA Development Kit

Using Altera MAX Series as Microcontroller I/O Expanders

The components. E3: Digital electronics. Goals:

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

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

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

DM74LS169A Synchronous 4-Bit Up/Down Binary Counter

CpE358/CS381. Switching Theory and Logical Design. Class 10

DM74LS191 Synchronous 4-Bit Up/Down Counter with Mode Control

Latches, the D Flip-Flop & Counter Design. ECE 152A Winter 2012

Xilinx ISE. <Release Version: 10.1i> Tutorial. Department of Electrical and Computer Engineering State University of New York New Paltz

Using Xilinx ISE for VHDL Based Design

Seven-Segment LED Displays

E158 Intro to CMOS VLSI Design. Alarm Clock

Prototyping ARM Cortex -A Processors using FPGA platforms

Chapter 13: Verification

Flip-Flops, Registers, Counters, and a Simple Processor

NOTE: The Flatpak version has the same pinouts (Connection Diagram) as the Dual In-Line Package.

Transcription:

Lab Workbook Introduction When several flip-flops are grouped together, with a common clock, to hold related information the resulting circuit is called a register. Just like flip-flops, registers may also have other control signals. You will understand the behavior of a register with additional control signals. Counters are widely used sequential circuits. In this lab you will model several ways of modeling registers and counters. Please refer to the PlanAhead tutorial on how to use the PlanAhead tool for creating projects and verifying digital circuits. Objectives After completing this lab, you will be able to: Model various types of registers Model various types of counters Registers Part 1 In a computer system, related information is often stored at the same time. A register stores bits of information in such a way that systems can write to or read out all the bits simultaneously. Examples of registers include data, address, control, and status. Simple registers will have separate data input and output pins but clocked with the same clock source. A simple register model is shown below. module Register (input [3:0] D, input Clk, output reg [3:0] Q); Q <= D; Notice that this is similar to a simple D Flip-flop with multiple data port. The simple register will work where the information needs to be registered every clock cycle. However, there are situations where the register content should be updated only when certain condition occurs. For example, a status register in a computer system gets updated only when certain instructions are executed. In such case, a register clocking should be controlled using a control signal. Such registers will have a clock enable pin. A model of such register is given below. module Register_with_synch_load_behavior(input [3:0] D, input Clk, input load, output reg [3:0] Q); if (load) Q <= D; Another desired behavior of registers is to reset the content when certain condition occurs. A simple model of a register with synchronous reset and load (reset has a higher priority over load) is shown below module Register_with_synch_reset_load_behavior(input [3:0] D, input Clk, input reset, input load, output reg [3:0] Q); if (reset) begin Q <= 4'b0; end else if (load) begin Q <= D; end www.xilinx.com/university Nexys3 6-1

Lab Workbook 1-1. Model a 4-bit register with synchronous reset and load using the model provided above. Develop a testbench and simulate the design. Assign Clk to SW0, D input to SW4-SW1, reset to SW5, load to SW6, and output Q to LED3-LED0. Verify the design in hardware. 1-1-1. Open PlanAhead and create a blank project called lab6_1_1. 1-1-2. Create and add the Verilog module that will model the 4-bit register with synchronous reset and load. Use the code provided in the above example. 1-1-3. Develop a testbench and simulate the design. Analyze the output. 1-1-4. Synthesize the design. 1-1-5. Create and add the UCF file, assigning Clk to SW0, D input to SW4-SW1, reset to SW5, load to SW6, and Q to LED3-LED0. 1-1-6. Implement the design. Look at the Project Summary and note that 1 BUFG and 11 IOs are used. If you open map report file, you will notice that there are 4 IOB registers are used. 1-1-7. Generate the bitstream, download it into the Nexys3 board, and verify the functionality. In some situations, it is necessary to set the register to a pre-defined value. For such a case, another control signal, called set, is used. Typically, in such registers, reset will have a higher priority over set, and set will have a higher priority over load control signal. 1-2. Model a 4-bit register with synchronous reset, set, and load signals. Assign Clk to SW0, D input to SW4-SW1, reset to SW5, set to SW6, load to SW7, and output Q to LED3-LED0. Verify the design in hardware. 1-2-1. Open PlanAhead and create a blank project called lab6_1_2. 1-2-2. Create and add the Verilog module that will model the 4-bit register with synchronous reset, set, and load control signals. 1-2-3. Synthesize the design. 1-2-4. Create and add UCF file, assigning Clk to SW0, D input to SW4-SW1, reset to SW5, set to SW6, load to SW7, and Q to LED3-LED0. 1-2-5. Implement the design. Look at the Project Summary and note the resources used. Understand the result. Nexys3 6-2 www.xilinx.com/university

Lab Workbook 1-2-6. Generate the bitstream, download it into the Nexys3 board, and verify the functionality. The above registers are categorized as parallel registers. There are another kind of registers called shift registers. A shift register is a register in which binary data can be stored and then shifted left or right when the control signal is asserted. Shift registers can further be sub-categorized into parallel load serial out, serial load parallel out, or serial load serial out shift registers. They may or may not have reset signals. In Xilinx FPGA, LUT can be used as a serial shift register with one bit input and one bit output using one LUT as SRL32 providing efficient design (instead of cascading up to 32 flip-flops) provided the code is written properly. It may or may not have enable signal. When the enable signal is asserted, the internal content gets shifted by one bit position and a new bit value is shifted in. Here is a model for a simple onebit serial shift in and shift out register without enable signal. It is modeled to shift for 32 clock cycles before the shifted bit brought out. This model can be used to implement a delay line. module simple_one_bit_serial_shift_register_behavior(input Clk, input ShiftIn, output ShiftOut); reg [31:0] shift_reg; shift_reg <= {shift_reg[30:0], ShiftIn}; assign ShiftOut = shift_reg[31]; The above model can be modified if we want to implement a delay line less than 32 clocks. Here is the model for the delay line of 3 clocks. module delay_line3_behavior(input Clk, input ShiftIn, output ShiftOut); reg [2:0] shift_reg; shift_reg <= {shift_reg[1:0], ShiftIn}; assign ShiftOut = shift_reg[2]; 1-3. Model a 1-bit delay line shift register using the above code. Develop a testbench and simulate the design using the stimuli provided below. Assign Clk to SW0, ShiftIn to SW1, and output ShiftOut to LED0. Verify the design in hardware. 1-3-1. Open PlanAhead and create a blank project called lab6_1_3. 1-3-2. Create and add the Verilog module that will model the 1-bit delay line shift register using the provided code. 1-3-3. Develop a testbench and simulate the design. 1-3-4. Synthesize the design. 1-3-5. Create and add the UCF file, assigning Clk to SW0, ShiftIn to SW1, and ShiftOut to LED0. www.xilinx.com/university Nexys3 6-3

Lab Workbook 1-3-6. Implement the design. Look at the Project Summary and note the resources used. Understand the result. 1-3-7. Generate the bitstream, download it into the Nexys3 board, and verify the functionality. The following code models a four-bit parallel in shift left register with load and shift enable signal.. module Parallel_in_serial_out_load_enable_behavior(input Clk, input ShiftIn, input [3:0] ParallelIn, input load, input ShiftEn, output ShiftOut, output [3:0] RegContent); reg [3:0] shift_reg; if(load) shift_reg <= ParallelIn; else if (ShiftEn) shift_reg <= {shift_reg[2:0], ShiftIn}; assign ShiftOut = shift_reg[3]; assign RegContent = shift_reg; 1-4. Model a 4-bit parallel in left shift register using the above code. Develop a testbench and simulate the design using the stimuli provided below. Assign Clk to SW0, ParallelIn to SW4-SW1, load to SW5, ShiftEn to SW6, ShiftIn to SW7, RegContent to LED3-LED0, and ShiftOut to LED7. Verify the design in hardware. 1-4-1. Open PlanAhead and create a blank project called lab6_1_4. 1-4-2. Create and add the Verilog module that will model the 4-bit parallel in left shift register using the provided code. 1-4-3. Develop a testbench and simulate the design. 1-4-4. Synthesize the design. 1-4-5. Create and add the UCF file, assigning Clk to SW0, ParallelIn to SW4-SW1, load to SW5, ShiftEn to SW6, ShiftIn to SW7, RegContent to LED3-LED0, and ShiftOut to LED7. 1-4-6. Implement the design. Look at the Project Summary and note the resources used. Understand the result. 1-4-7. Generate the bitstream, download it into the Nexys3 board, and verify the functionality. Nexys3 6-4 www.xilinx.com/university

Lab Workbook 1-5. Write a model for a 4-bit serial in parallel out shift register. Develop a testbench and simulate the design. Assign Clk to SW0, ShiftEn to SW1, ShiftIn to SW2, ParallelOut to LED3-LED0, and ShiftOut to LED7. Verify the design in hardware. Counters Part 2 Counters can be asynchronous or synchronous. Asynchronous counters count the number of events solely using an event signal. Synchronous counters, on the other hand, use a common clock signal so that when several flip-flops must change state, the state changes occur simultaneously. A binary counter is a simple counter which counts values up when an enable signal is asserted and will reset when the reset control signal is asserted. Of course, a clear signal will have a higher priority over the enable signal. The following diagram shows such a counter. Note that clear is an asynchronous negative logic signal whereas Enable is synchronous positive logic signal. 2-1. Design a 8-bit counter using T flip-flops, extending the above structure to 8-bits. Your design needs to be hierarchical, using a T flip-flop in behavioral modeling, and rest either in dataflow or gate-level modeling. Develop a testbench and validate the design. Assign Clock input to SW0, Clear_n to SW1, Enable to SW2, and Q to LED7-LED0. Implement the design and verify the functionality in hardware. 2-1-1. Open PlanAhead and create a blank project called lab6_2_1. 2-1-2. Create and add the Verilog module to provide the desired functionality. 2-1-3. Synthesize the design and view the schematic under the Synthesized Design process group. Indicate what kind and how many resources are used. 2-1-4. Develop a testbench and validate the design. 2-1-5. Create and add the UCF file, assigning Clock input to SW0, Clear_n to SW1, Enable to SW2, and Q to LED7-LED0. 2-1-6. Implement the design. www.xilinx.com/university Nexys3 6-5

Lab Workbook 2-1-7. Generate the bitstream, download it into the Nexys3 board, and verify the functionality. Counters can also be implemented using D flip-flops since a T flip-flop can be constructed using a D flipflop as shown below. 2-2. Modify the 8-bit counter using D flip-flops. The design should be hierarchical, defining D flip-flop in behavioral modeling, creating T flip-flop from the D flip-flop, implementing additional functionality using dataflow modeling. Assign Clock input to SW0, Clear_n to SW1, Enable to SW2, and Q to LED7-LED0. Implement the design and verify the functionality in hardware. Other types of binary counters include (i) up, (ii) down, and (iii) up-down. Each one of them may have count enable and reset as control signals. There may be situation where you may want to start the count up/down from some non-zero value and stop when some other desired value is reached. Here is an example of a 4-bit counter which starts with a value 10 and counts down to 0. When the count value 0 is reached, it will re-initialize the count to 10. At any time, if the enable signal is negated, the counter pauses counting until the signal is asserted back. It assumes that load signal is asserted to load the predefined value before counting has begun. reg [3:0] count; wire cnt_done; assign cnt_done = ~ count; assign Q = count; always @(posedge Clock) if (Clear) count <= 0; else if (Enable) if (Load cnt_done) count <= 4'b1010; // decimal 10 else count <= count - 1; 2-3. Model a 4-bit up-counter with synchronous load, enable, and clear as given in the code above. Develop a testbench (similar to the waveform shown below) and verify the design works. Assign Clock input to SW0, Clear to SW1, Enable to SW2, Load to SW3, and Q to LED3-LED0. Implement the design and verify the functionality in hardware. Conclusion In this lab, you learned how various kinds of registers and counters work. You modeled and verified the functionality of these components. These components are widely used in a processor system design. Nexys3 6-6 www.xilinx.com/university