Laboratory Exercise #8 Introduction to Sequential Logic

Similar documents
Laboratory Exercise #10 An Introduction to High-Speed Addition

Laboratory Exercise #11 A Simple Digital Combination Lock

ELCT201: DIGITAL LOGIC DESIGN

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 7 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

Latches. October 13, 2003 Latches 1

Module - 19 Gated Latches

Synchronous Sequential Logic

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

Sequential Logic Worksheet

Computers also need devices capable of Storing data and information Performing mathematical operations on such data

Sequential vs. Combinational

Problem Set 9 Solutions

Chapter 7 Sequential Logic

Sequential Logic Circuits

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

L4: Sequential Building Blocks (Flip-flops, Latches and Registers)

EE40 Lec 15. Logic Synthesis and Sequential Logic Circuits

State and Finite State Machines

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

CPS 104 Computer Organization and Programming Lecture 11: Gates, Buses, Latches. Robert Wagner

EECS Components and Design Techniques for Digital Systems. FSMs 9/11/2007

ALU A functional unit

Topic 8: Sequential Circuits

Appendix B. Review of Digital Logic. Baback Izadi Division of Engineering Programs

11.1 As mentioned in Experiment 10, sequential logic circuits are a type of logic circuit where the output of

Unit II Chapter 4:- Digital Logic Contents 4.1 Introduction... 4

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 9 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

Sequential Logic. Rab Nawaz Khan Jadoon DCS. Lecturer COMSATS Lahore Pakistan. Department of Computer Science

Introduction EE 224: INTRODUCTION TO DIGITAL CIRCUITS & COMPUTER DESIGN. Lecture 6: Sequential Logic 3 Registers & Counters 5/9/2010

L4: Sequential Building Blocks (Flip-flops, Latches and Registers)

Chapter 4. Sequential Logic Circuits

Digital Logic: Boolean Algebra and Gates. Textbook Chapter 3

Sequential Logic (3.1 and is a long difficult section you really should read!)

ELEN Electronique numérique

Boolean Algebra and Digital Logic 2009, University of Colombo School of Computing

5. Sequential Logic x Computation Structures Part 1 Digital Circuits. Copyright 2015 MIT EECS

Adders, subtractors comparators, multipliers and other ALU elements

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

EET 310 Flip-Flops 11/17/2011 1

Lecture 7: Logic design. Combinational logic circuits

Sequential Circuits Sequential circuits combinational circuits state gate delay

Lecture 7: Sequential Networks

Digital electronics form a class of circuitry where the ability of the electronics to process data is the primary focus.

Introduction to Digital Logic

Chapter 5 Synchronous Sequential Logic

ALU, Latches and Flip-Flops

Digital Circuits ECS 371

I. Motivation & Examples

CMPEN 411. Spring Lecture 18: Static Sequential Circuits

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING BENG (HONS) ELECTRICAL & ELECTRONICS ENGINEERING EXAMINATION SEMESTER /2017

CPE100: Digital Logic Design I

Simulation of Logic Primitives and Dynamic D-latch with Verilog-XL

Memory, Latches, & Registers

Synchronous Sequential Circuit Design. Digital Computer Design

Philadelphia University Student Name: Student Number:

Philadelphia University Student Name: Student Number:

Lecture 14: State Tables, Diagrams, Latches, and Flip Flop

EECS 270 Midterm 2 Exam Answer Key Winter 2017

CSE140: Components and Design Techniques for Digital Systems. Midterm Information. Instructor: Mohsen Imani. Sources: TSR, Katz, Boriello & Vahid


Chapter 3. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 3 <1>

LOGIC CIRCUITS. Basic Experiment and Design of Electronics

Models for representing sequential circuits

EECS150 - Digital Design Lecture 23 - FSMs & Counters

Memory Elements I. CS31 Pascal Van Hentenryck. CS031 Lecture 6 Page 1

Lab #10: Design of Finite State Machines

Parity Checker Example. EECS150 - Digital Design Lecture 9 - Finite State Machines 1. Formal Design Process. Formal Design Process

Combinational vs. Sequential. Summary of Combinational Logic. Combinational device/circuit: any circuit built using the basic gates Expressed as

State & Finite State Machines

Boolean Logic Continued Prof. James L. Frankel Harvard University

Combinational Logic. Mantıksal Tasarım BBM231. section instructor: Ufuk Çelikcan

Fundamentals of Digital Design

Synchronous Sequential Circuit

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Digital Techniques

ELEC Digital Logic Circuits Fall 2014 Sequential Circuits (Chapter 6) Finite State Machines (Ch. 7-10)

Topic 8: Sequential Circuits. Bistable Devices. S-R Latches. Consider the following element. Readings : Patterson & Hennesy, Appendix B.4 - B.

Integrated Circuits & Systems

Binary addition (1-bit) P Q Y = P + Q Comments Carry = Carry = Carry = Carry = 1 P Q

State & Finite State Machines

XI STANDARD [ COMPUTER SCIENCE ] 5 MARKS STUDY MATERIAL.

COE 202: Digital Logic Design Sequential Circuits Part 4. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Example: vending machine

Designing Sequential Logic Circuits

Adders, subtractors comparators, multipliers and other ALU elements

Sequential Logic Design: Controllers

Sequential Logic. Handouts: Lecture Slides Spring /27/01. L06 Sequential Logic 1

Review: Designing with FSM. EECS Components and Design Techniques for Digital Systems. Lec09 Counters Outline.

UNIVERSITY OF CALIFORNIA

Digital Control of Electric Drives

University of Minnesota Department of Electrical and Computer Engineering

Digital Electronics Final Examination. Part A

LOGIC CIRCUITS. Basic Experiment and Design of Electronics. Ho Kyung Kim, Ph.D.

Roger L. Tokheim. Chapter 8 Counters Glencoe/McGraw-Hill

EE 209 Logic Cumulative Exam Name:

CPE/EE 422/522. Chapter 1 - Review of Logic Design Fundamentals. Dr. Rhonda Kay Gaede UAH. 1.1 Combinational Logic

EECS 312: Digital Integrated Circuits Final Exam Solutions 23 April 2009

CPE100: Digital Logic Design I

6. Finite State Machines

MOSIS REPORT. Spring MOSIS Report 1. MOSIS Report 2. MOSIS Report 3

ESE 570: Digital Integrated Circuits and VLSI Fundamentals

Transcription:

Laboratory Exercise #8 Introduction to Sequential Logic ECEN 248: Introduction to Digital Design Department of Electrical and Computer Engineering Texas A&M University

2 Laboratory Exercise #8 1 Introduction The purpose of lab this week is to introduce sequential logic circuits. To start off, we will cover storage elements such as latches and flip-flops. You will have the opportunity to describe these components at the gate-level using Verilog and then simulated them within ISE. Next, synchronous sequential circuits will be discussed. To make the concepts more clear, you will combine flip-flops with combinational logic discussed in previous labs to simulate the operation of synchronous logic. Furthermore, you will introduce simulation delays into your combinational logic and observe the effects it has on clock timing. 2 Background The following subsection will expound on the theory necessary for completion of this lab assignment. The pre-lab will test your knowledge of these concepts. 2.1 Latches and Flip-flops What differentiates sequential circuits from the combinational circuits you have designed thus far is the memory component. Simply put, the output of a sequential circuit is dependent on not only the current inputs but also the state of the circuit (i.e. values stored in memory components). The state of a sequential circuit can viewed as a historical record of past inputs. Figure 1 illustrates this concept. Figure 1: Simplified Diagram of a Sequential Circuit Memory components come in many flavors but we will only study two types in this lab, namely latches and flip-flops. Latches can be combined to create flip-flops so we will begin by discussing latches. The simplest latch is the Set-Reset (SR) latch. The function table and gate-level schematic of an SR latch with an enable, En, are depicted in Table 1 and Figure 2, respectively. As you can see, the Set and Reset operations are expected to be mutually exclusive, meaning they cannot happen at the same time. However, when neither Set nor Reset is active, the value of Q (and consequently Q) remains the same. Hence, the value of Q is latched or stored. From the SR-latch, we can construct a D-latch, also known as a transparent 2 ECEN 248

Laboratory Exercise #8 3 latch, as seen in Figure 3. The function table for the D-latch can be found in Table 2. The behavior of the D-latch is simple. When En is high, the input, D, is forwarded to the output, Q (i.e. the input is transparent); however when En is low, the output simply holds the last value of Q. Table 1: SR-latch Function Table En S R Q Q 0 X X hold 1 0 0 hold 1 0 1 0 1 1 1 0 1 0 1 1 1 undefined Figure 2: SR-latch Gate-level Schematic Table 2: D-latch Function Table En D Q Q 0 X hold 1 0 0 1 1 1 1 0 A D-latch is considered a level-sensitive memory device because the output is controlled by the level (i.e. high or low) of the En signal. Conversely, we can create an edge-sensitive device such that the output changes when the control signal transitions from low to high or vice versa. This sort of device is known as a flip-flop, and the control signal is usually referred to as a Clock (for reasons which will become clear later in the lab) or Clk for short. Consider the circuit in Figure 4 in which a level-sensitive D-latch and an edgesensitive D flip-flop are stimulated with the exact same input. Figure 5 depicts the simulation waveform ECEN 248 3

4 Laboratory Exercise #8 Figure 3: D-latch Gate-level Schematic for the D-latch/D flip-flop circuit. Notice that the output of each memory component is undefined in the simulation until Clk goes high at 10 ns (10,000 ps). While Clk is high, the output of the D-latch (Q latch) matches the input net (D) whereas the output of the D flip-flop (Q flip flop) holds the value that was on the D signal at the exact moment the rising edge of Clk came in. At 15 ns, D drops low as does Q latch; however, Q flip flop does not respond to D dropping low until the next rising edge event from Clk. Notice the pulse on D at 22 ns. Neither the latch nor the flip-flop respond because the Clk signal is low and not transitioning (i.e. no rising edge). Figure 4: Latch/Flip-flop Circuit Figure 5: Simulation Waveform of Latch/Flip-flop Circuit 4 ECEN 248

Laboratory Exercise #8 5 To construct a D flip-flop, we can actually combine two D-latches with two inverters in what is often referred to as a master-slave configuration illustrated in Figure 6. Remember that a rising-edge sensitive D flip-flop essentially samples the input, D, at the rising-edge of Clk. Let us convince ourselves that the circuit in Figure 6 does exactly that. When Clk is low, the master latch is enabled while the slave latch is disabled. Thus, the output of the master latch, Q m, equals the input, D, whereas the output of the slave latch, Q s, is equal to whatever value was last store in that latch. For this example, let us assume D = 1, and the value latched into the slave latch is X. At some point, the Clk will transition from low to high. This event is referred to as a rising-edge. When this happens, the master latch will now become disabled, which means it will hold the value of D immediately before the transition (i.e. 1 will be latched into the master latch). Conversely, the slave latch will become enabled and therefore transparent (i.e. Q s = Q m = 1 ). When the clock returns to a low state, the slave latch will simply hold the previous value of Q m which is 1. In the experiments below, you will have the opportunity to simulate this behavior to help you further understand how the master-slave D flip-flop works. Figure 6: Master-Slave D flip-flop 2.2 Synchronous Sequential Circuits Sequential circuits can be broadly classified into two categories, asynchronous and synchronous. Simply put, asynchronous logic utilizes latches, while synchronous logic utilizes flip-flops. In this lab, we will focus on synchronous logic because asynchronous logic requires a far more advanced understanding of signal timing and propagation. Synchronous logic, as opposed to asynchronous logic, requires an external synchronizing control signal appropriately named the clock signal. Often abbreviated, Clk, the clock signal acts like the heart beat of the synchronous circuit, controlling the exact moment when data transitions from one flip-flop to the next. As an example, consider the circuit in Figure 7, which is a 2-bit synchronous adder. This circuit is constructed from three 2-bit wide flip-flops 1, one 1-bit wide flip-flop, and the familiar ripple carry adder. One thing to note in the synchronous circuit diagram is that the Clk signal is not actually shown. The > symbol found within the flip-flops implies a clock signal is distributed to those components. The clock 1 An n-bit flip-flop (a.k.a n-bit register) is simply n 1-bit wide flips-flops arranged in a parallel fashion. ECEN 248 5

6 Laboratory Exercise #8 signal that drives the synchronous adder is shown below the circuit diagram. The period of oscillation, T, is determined by the propagation delay of the 2-bit ripple carry adder. The rate of oscillation, f, is computed as 1/T. As a digital circuit designer, your goal will often be to reduce the propagation delay through the combinatorial logic within a synchronous circuit in order to drive the circuit with a higher clock rate. Figure 7: Example Synchronous Logic Circuit 3 Pre-lab The pre-lab questions below will test you on your knowledge of the material presented above. Please answer the following questions completely: 1. Complete the waveform below given the circuit in Figure 4. For the S and R, assume the D-latch is constructed as shown in Figure 3. You may submit a hand drawn waveform. 6 ECEN 248

Laboratory Exercise #8 7 2. If the circuit in Figure 7 utilized the 2-bit ripple-carry adder designed in Lab 3, what would be the maximum value of f given that each gate-delay unit is 4 ns? Assume that the flip-flops are ideal and do not add any additional timing constraints to the circuit. 3. (Honors) The circuit in Figure 2 is of a cross-coupling configuration. In other words, combinational feedback exists. Explain in your own words how the SR-latch is able to hold state even though it is constructed using combinational logic. 4 Lab Procedure The following lab exercises serve to reinforce the material discussed in the background section above and in the course lecture. 4.1 Experiment 1 For the first experiment, you will become acquainted with the storage elements discussed in the background section of this lab manual. We will begin by using structural Verilog and the built-in gate-level primitives to describe these storage elements, as well as simulate them in ISE. To do so, we must introduce simulation delays into our Verilog code. Furthermore, we will make use of behavior Verilog to describe some of the same storage components so that in future experiments, we can create synthesizable synchronous logic. Note: Be sure to capture screenshots of all waveforms discussed below. Record the simulation console output as well. 1. Simulate the operation of the SR-latch in Figure 2 using Verilog. The steps below will guide you through the process. (a) Create a new ISE project and call it lab8. (b) Using the code below as a template, describe the SR-latch at the gate-level using structural Verilog. Take note of the delays that have been introduced into the code. When we place a #2 between the module and instance name in Verilog, the output of the module instance will be delays by 2 time units. Because we set the timescale to 1ns, the simulation delay will be 2ns. 1 t i m e s c a l e 1 ns / 1 ps / / s p e c i f y 1 ns f o r each d e l a y u n i t d e f a u l t n e t t y p e none 3 / Use s t r u c t u r a l V e r i l o g and t h e b u i l t i n gate l e v e l 5 p r i m i t i v e s t o c o n s t r u c t t h e SR l a t c h d e s c r i b e d i n l a b / 7 module s r l a t c h (Q, notq, En, S, R ) ; ECEN 248 7

8 Laboratory Exercise #8 9 / a l l p o r t s s h o u l d be w i r e s / output wire Q, notq ; 11 input wire En, S, R ; 13 / i n t e r m e d i a t e n e t s / wire nandsen, nandren ; 15 / woah!!! what i s t h i s #2 t h i n g?!? / 17 / i t s a d e l a y ( s i m u l a t i o n o n l y!!! ) / nand #2 nand0 (Q, nandsen, notq ) ; / / 2 ns g a t e d e l a y 19 / / f i n i s h t h i n g s up h ere... 21 endmodule (c) Copy the sr latch tb.v file from the course directory into your lab8 directory and use it to test your SR-latch in ISE. (d) Once your latch passes all of the tests, add the SR-latch internal signals to the waveform and examine the waveform to gain an understanding of how the SR-latch is functioning. Compare the results to the function table (Table 1). (e) Now, change the 2 unit delays in your code to 4 units and run the test bench again. Explain the results of the simulation. 2. Simulate the D-latch using Verilog in ISE. (a) Figure 3 illustrates the gate-level construction of a D-latch. Using the module interface below and the code above as a starting point, describe the D-latch in structural Verilog. Assume NOT gates also have a delay of 2ns each. module d l a t c h (Q, notq, En, D ) ; (b) Copy over the d latch tb.v test bench file and simulate the operation of your D-latch. Verify that the operation matches that described in Table 2. 3. With the D-latch module you just created, construct a D flip-flop as shown in Figure 6. (a) The template code for the D flip-flop is supplied below. Within your code, instantiate only two D-latch modules and two inverter gates. Assume the inverter gates have a delay of 2ns each. Do not put any additional delay on the D-latches because the delays are built into the module already. 1 t i m e s c a l e 1 ns / 1 ps / / s p e c i f y 1 ns f o r each d e l a y u n i t d e f a u l t n e t t y p e none 3 / Use s t r u c t u r a l V e r i l o g, t h e b u i l t i n gate l e v e l 5 p r i m i t i v e s, and our D l a t c h t o c o n s t r u c t t h e D f l i p f l o p d e s c r i b e d i n l a b / 8 ECEN 248

Laboratory Exercise #8 9 7 module d f l i p f l o p (Q, notq, Clk, D ) ; 9 / a l l p o r t s s h o u l d be w i r e s / output wire Q, notq ; / / o u t p u t s o f s l a v e l a t c h 11 input wire Clk, D; 13 / i n t e r n a l n e t s / wire notclk, notnotclk ; 15 wire Q m ; / / o u t p u t o f master l a t c h wire notq m ; / / notq m w i l l be wired t o t h e d l a t c h b u t t h e n l e f t u n c o n n e c t e d from t h e r e 17 / s t r u c t u r a l l e v e l w i r i n g / 19 / / i n s t a n t i a t e and wire up t h e n o t g a t e s here... 21 / / i n s t n t i a t e and wire up t h e d l a t c h e s based on s c h e m a t i c i n l a b 23 endmodule (b) Simulate your D flip-flop using the d flip flop tb.v file in the course directory. Add the internal nets within your D flip-flop to the waveform and examine the waveform after restarting the simulation. Do the latches behave as expected? Why or why not? 4. Behavior Verilog can be used to describe the components we have simulated so far. In fact, when developing a synthesizable Verilog module (i.e. something we intend to put on the FPGA), we should only use behavior Verilog to describe storage components. This is due to the fact that delays are part of the non-synthesizable Verilog subset, and latches and flip-flops require the delays to function properly. Luckily, describing storage components in behavior Verilog is very easy. The following example show how to create a D-latch with an always statement. Please read over the code including the comments which have been provided. 1 t i m e s c a l e 1 ns / 1 ps / / s p e c i f y 1 ns f o r each d e l a y u n i t d e f a u l t n e t t y p e none 3 / V e r i l o g b e h a v i o r a l model o f a D l a t c h 5 BTW, i f we s y n t h e s i z e d t h i s t h i n g f o r our f a n c y FPGA, t h e s y n t h e s i z e r would y e l l a t us. We w i l l t a l k 7 about why l a t e r on i n t h e l a b / 9 module d l a t c h b e h a v i o r a l ( output reg Q, / / Q i s d r i v e n w i t h a b e h a v i o r a l s t a t e m e n t! 11 output wire notq, / / d r i v e n w i t h a d a t a f l o w s t a t e m e n t! input wire D, En / / w i r e s can d r i v e r e g s 13 ) ; 15 / d e s c r i b e b e h a v i o r o f D l a t c h / always@ ( En or D) 17 i f ( En ) / / i f En!= 1 b0 Q = D; / / t r a n s p a r e n t! ECEN 248 9

10 Laboratory Exercise #8 19 e l s e / / t h i s p a r t i s a c t u a l l y n o t needed! Q = Q; / / i f l e f t out, i t w i l l be i m p l i e d 21 / so f a r we have d e s c r i b e d t h e o u t p u t Q b u t have made no mention 23 o f what notq i s so h ere goes... t h i s s h o u l d l o o k f a m i l i a r / a s s i g n notq = Q; / / r e g s can d r i v e w i r e s! 25 endmodule Although the code above is syntactically correct, it is not appropriate for an FPGA due to the fact that the FPGA was designed to implement synchronous logic and latches are used create asynchronous logic. One way of thinking about it is that the code above falls into a gray area between synthesizable and non-synthesizable logic. The synthesizer will not error out but will produce warnings because we are using latches. Unless you have a deep understanding of what it is you are doing, your logic will probably not function correctly on the FPGA even if it works in simulation. Instead, you should use only flip-flops in your sequential designs and do so as shown below. t i m e s c a l e 1 ns / 1 ps / / s p e c i f y 1 ns f o r each d e l a y u n i t 2 d e f a u l t n e t t y p e none 4 / V e r i l o g b e h a v i o r a l model o f a f l i p f l o p w i t h o u t an e n a b l e. Our FPGA p r e f e r s t h i s s o r t o f s t o r a g e e l e m e n t over t h e 6 D l a t c h. / 8 module d f l i p f l o p b e h a v i o r a l ( output reg Q, / / yeah y a l l know what t h i s s t u f f does 10 output wire notq, input wire D, 12 input wire Clk / / Clock i s our t r i g g e r s i g n a l. S t u f f happens / / d u r i n g t r a n s i s t i o n s o f Clk 14 ) ; 16 / d e s c r i b e b e h a v i o r o f D f l i p f l o p / always@ ( posedge Clk ) / / t r i g g e r edge i s t h e p o s i t i v e ( r i s i n g ) edge 18 Q <= D; / / woah!!! what i s t h i s <= t h i n g?!? i t s a non b l o c k i n g / / a s s i g n m e n t s t a t e m e n t. Don t worry about i t r i g h t now! 20 / so f a r we have d e s c r i b e d t h e o u t p u t Q b u t have made no mention 22 o f what notq i s so h ere goes... t h i s s h o u l d l o o k f a m i l i a r / a s s i g n notq = Q; / / r e g s can d r i v e w i r e s! 24 endmodule (a) Type the code above into two source files named d latch behavioral.v and d flip flop behavioral.v, respectively, and simulate each of them with the appropriate test bench to ensure proper functionality. 10 ECEN 248

Laboratory Exercise #8 11 (b) Compare the waveforms you captured from the behavioral Verilog to those captured from the structural Verilog. Are they different? If so, how? 4.2 Experiment 2 For this experiment, we will describe the 2-bit synchronous adder drawn in Figure 7 and simulate it in Verilog. As with the previous experiment, we will begin with gate-level descriptions in Verilog so that we can demonstrate the effects of combinational circuit delay on a synchronous circuit. Then for comparison, we will show how the same circuit can be described using only behavioral constructs. 1. Use the full-adder Verilog module you created in lab 5 to construct a 2-bit ripple-carry adder. (a) Copy the full adder.v file in your lab5 directory into your lab8 directory and add delays to the assign statements in order to simulate gate delays. The code snippet below shows how you can add delay to the three input XOR gate found within the full-adder. Assume that 3-input AND, OR, and XOR gates have a delay of 6ns, while 2-input AND, OR, and XOR gates have a delay of 4ns. NOT, NAND, and NOR gates can be assumed to have a delay of 2ns. a s s i g n #6 S = A ˆ B ˆ Cin ; / / t h e h a t ( ˆ ) i s f o r XOR (b) Create a new Verilog source file called adder 2bit.v with the following module interface: module a d d e r 2 b i t ( Carry, Sum, A, B ) ; (c) To test the 2-bit adder circuit, we will use the file adder 2bit tb.v as a template. Copy this file from the course directory into your lab8 directory and complete the test bench code based on the hints found within the comments. (d) Add the test bench to your ISE project and simulate it. Correct any errors with the test bench or the ripple carry adder. Have the TA ensure that what you have done is correct so far. (e) Use the simulation waveform to determine the worst case propagation delay through the ripplecarry adder. Hint: The signal with the longest propagation path is Carry. You may use the time markers in the simulation window to aide in this measurement. 2. Now that we have our ripple-carry adder, we can complete the logic shown in Figure 7. To simplify the experiment, we will use Verilog code to complete the synchronous aspect of the design and assume the flip-flops (i.e. the storage portion of the design) are idea and do not contribute to our timing constraints. This is not always a safe assumption so be aware! (a) The code below should get you started. Name the source file adder synchronous.v. Take note of how we are able to create n-bit flip-flops (a.k.a. n-bit registers) very easily in Verilog. ECEN 248 11

12 Laboratory Exercise #8 1 t i m e s c a l e 1 ns / 1 ps / / s p e c i f y 1 ns f o r each d e l a y u n i t d e f a u l t n e t t y p e none 3 / T h i s module c o u l d p o s s i b l y be t h e f i r s t s y n c h r o n o u s c i r c u i t you ve 5 e v e r w r i t t e n. How e x c i t i n g?!? You w i l l p r o b a b l y remember t h i s moment f o r t h e r e s t o f your l i f e... / 7 module a d d e r s y n c h r o n o u s ( C a r r y r e g, Sum reg, Clk, A, B ) ; 9 / Output p o r t s are r e g s!!! why? w e l l t h e y need t o be a b l e t o 11 hold s t a t e / output reg C a r r y r e g ; 13 output reg [ 1 : 0 ] Sum reg ; 15 / I n p u t s are s t i l l w i r e s / input wire Clk ; 17 input wire [ 1 : 0 ] A, B ; 19 / i n t e r m e d i a t e n e t s / reg [ 1 : 0 ] A reg, B reg ; / / w i l l use t h e s e as 2 b i t r e g i s t e r s 21 wire Carry ; / / need t h i s t o c o n n e c t t o t h e r e g i s t e r s d e s c r i b e d below wire [ 1 : 0 ] Sum ; 23 / i n s t a n t i a t e your 2 b i t adder here... / 25 27 / okay h ere i s where t h i n g g e t i n t e r e s t i n g... / / t h i s b e h a v i o r a l b l o c k d e s c r i b e s two 2 b i t r e g i s t e r s / 29 / remember r e g i s t e r s are n o t h i n g more than grouped f l i p f l o p s / always@ ( posedge Clk ) / / t h e t r i g g e r c o n d i t i o n i s t h e p o s t i v e edge o f c l o c k! 31 begin / / w i l l need t h i s because we w i l l p u t two s t a t e m e n t s i n here A reg <= A; / / we use non b l o c k a s s i g m e n t s here because we want 33 B reg <= B ; / / t h e s e two s t a t e m e n t s t o happen c o n c u r r e n t l y end 35 / w e l l t h a t was e asy... / 37 / l e t s d e s c r i b e t h e r e g i s t e r s f o r t h e r e s u l t / always@ ( posedge Clk ) 39 begin C a r r y r e g <= Carry ; / / woah! i s t h i s r i g h t?!? ooh yea w i r e s can d r i v e r e g s 41 Sum reg <= Sum ; / / t h e s e two s t a t e m e n t s l o o k t h e same even though t h e end / / b i t w i d t h i s d i f f e r e n t 43 / we c o u l d have a c t u a l l y grouped t h e s e a l l i n t o one always b l o c k ; however 45 i t i s n i c e t o c l e a r l y d i v i d e up t h e i n p u t s and o u t p u t s o f t h e c i r c u i t / 47 endmodule / / t h a t s a l l f o l k s (b) Copy the test bench file, adder synchronous tb.v, from the course directory into your lab8 di- 12 ECEN 248

Laboratory Exercise #8 13 rectory. Add the test bench to your ISE project and simulate it to ensure your synchronous adder circuit passes all of the tests. (c) Once your synchronous circuit is working properly, open the test bench file and locate the behavioral code that computes the KnownAnswer value. It turns out, this succinct description found within the test bench could replace the code we just wrote. Both Verilog descriptions would synthesize to the same logic. You will be asked to compare these two descriptions at the end of the lab assignment. 3. For the last part of this experiment, we would like to drive our synchronous adder circuit at a higher clock rate to gain an understanding of how the propagation delays through combinational logic effects the speed at which synchronous circuits are able to operate. (a) Once your synchronous circuit is working properly, open the test bench and change the define CLOCK PERIOD from 40 to 18. This will force the clock signal generated within the test bench to run at a higher rate. Re-simulate the test bench and take note of the results. If some tests failed, use the console output along with the waveform viewer to determine exactly why those particular tests failed. (b) Now increase the define CLOCK PERIOD by one and re-simulate. Repeat the process until all tests pass. (c) Compare the final value of the define CLOCK PERIOD with the propagation delay of your ripple adder that you measured earlier. You will need these results to answer a question at the end of the lab assignment. 5 Post-lab Deliverables Please include the following items in your post-lab write-up in addition to the deliverables mentioned in the Policies and Procedures document. 1. Include the source code with comments for all modules you simulated. You do not have to include test bench code that was provided; however, you must supply the test bench code that you wrote! Code without comments will not be accepted! 2. Include screenshots of all waveforms captured during simulation in addition to the test bench console output for each test bench simulation. 3. Answer all questions throughout the lab manual. 4. Compare the behavioral description of the synchronous adder found in the test bench code with the combination of structural and dataflow Verilog you used in the lab assignment. What are the advantages and disadvantages of each? Which do you prefer and why? ECEN 248 13

14 Laboratory Exercise #8 5. Based on the clock period you measured for your synchronous adder, what would be the theoretical maximum clock rate? What would be the effect of increasing the width of the adder on the clock rate? How might you improve the clock rate of the design? 6. (Honors) In the lab, we assumed that the flip-flops did not contribute to the timing constraints of the circuit. Unfortunately, this is not the case. As you saw when you simulated the D flip-flop, the sampling action does not happen instantaneously. In fact, a flip-flop will be come unstable if the inputs to not remain stable for a certain amount of time prior to the rising-edge event (setup time) and a certain amount of time after the rising-edge event (hold time). Assume a setup and hold time of 2ns and 1ns, respectively. What would the theoretical maximum clock rate for the synchronous adder be in this scenario? Explain your answer. What would the throughput of the adder be in terms of operations/second at this rate? 6 Important Student Feedback The last part of lab requests your feedback. We are continually trying to improve the laboratory exercises to enhance your learning experience, and we are unable to do so without your feedback. Please include the following post-lab deliverables in your lab write-up. Note: If you have any other comments regarding the lab that you wish to bring to your instructor s attention, please feel free to include them as well. 1. What did you like most about the lab assignment and why? What did you like least about it and why? 2. Were there any section of the lab manual that were unclear? If so, what was unclear? Do you have any suggestions for improving the clarity? 3. What suggestions do you have to improve the overall lab assignment? 14 ECEN 248