Docsity

Verilog Code - Digital Design and Synthesis - Assignment, Exercises of Computer Science

Toggle sidebar
bg1
Please Note: To receive full credit, you should use the following best practices in your
homework assignments:
Follow the coding style guidelines given in class, on previous homework, and in
the “Verilog Styles That Kill” paper
When designing a non-testbench module, your code should use only synthesizable
Verilog constructs.
All figures & graphs should include a number and caption (handwritten is OK).
When printing waveforms, ensure that the relevant signal transitions are clearly
visible.
All code should be typed. Do not submit handwritten code.
You must always turn in a printout of all Verilog code used with each
problem unless explicitly told not to do so.
You must also submit a copy of all Verilog code to the Drop Box on the
course website by the time the homework is due.
[1] (4pts) – Sometimes it’s Better to Finish Last
Construct an original example (i.e. not one copied from Lecture, readings, or other sources) of a
piece of Verilog code that contains a race condition. Clearly explain why the race condition
occurs in your example using the terminology of the Verilog Stratified Event Queue.
[2] (16pts) – Try to be Sensitive
Without using always@(*), fill in the sensitivity lists for the always blocks below to meet the
stated goals. Do not include any unnecessary signals in the sensitivity list. Assume sequential
circuits use positive-edge-triggered clocks unless stated otherwise.
(a) Combinational Logic:
always@( ) begin
a = b | y;
x = ~y;
end
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Verilog Code - Digital Design and Synthesis - Assignment and more Exercises Computer Science in PDF only on Docsity!

Please Note: To receive full credit, you should use the following best practices in your

homework assignments :

 Follow the coding style guidelines given in class, on previous homework, and in

the “Verilog Styles That Kill” paper

 When designing a non-testbench module, your code should use only synthesizable

Verilog constructs.

 All figures & graphs should include a number and caption (handwritten is OK).

 When printing waveforms, ensure that the relevant signal transitions are clearly

visible.

 All code should be typed. Do not submit handwritten code.

 You must always turn in a printout of all Verilog code used with each

problem unless explicitly told not to do so.

 You must also submit a copy of all Verilog code to the Drop Box on the

course website by the time the homework is due.

[1] (4pts) – Sometimes it’s Better to Finish Last

Construct an original example (i.e. not one copied from Lecture, readings, or other sources) of a

piece of Verilog code that contains a race condition. Clearly explain why the race condition

occurs in your example using the terminology of the Verilog Stratified Event Queue.

[2] (16pts) – Try to be Sensitive

Without using always@(*), fill in the sensitivity lists for the always blocks below to meet the

stated goals. Do not include any unnecessary signals in the sensitivity list. Assume sequential

circuits use positive-edge-triggered clocks unless stated otherwise.

(a) Combinational Logic:

always@ ( ) begin

a = b | y;

x = ~y;

end

(b) Combinational Logic:

always@ ( ) begin

if(a)

m = b * n;

else if(b)

c = {3{2’b00,f};

else

r = t & (j << 2);

end

(c) Combinational Logic:

always@ ( ) begin

j = b + k;

d = k | ~b;

m = d ^ j;

n = ~m;

end

(d) Sequential Logic:

always@ ( ) begin

a <= b ^ a;

d <= f | a;

m <= a & d;

c <= ~m;

end

(e) Sequential Logic with synchronous active-low reset (rst_n) and synchronous active-high

set:

always@ ( ) begin

if(~rst_n)

y <= 8’h00;

else if(set)

y <= 8’hFF;

else

y <= x;

end

[4] (10pts) – 3-to-8 Decoder with Enables

Replicate the functionality of a 74HCT138 3-to-8 line decoder using a casex statement. (The

datasheet for the 74HCT138 is available at http://www.ti.com/lit/ds/symlink/cd54hc238.pdf )

Ports that are active-low in the datasheet’s truth table must also be active-low in your module.

Use the port names shown in the datasheet; append them with “_n” to indicate ports that are

active-low. For example: Y 0 should be Y0_n.

[5] (20pts) – Threshold Detection with a Recursive Average and Hysteresis

(a) (14pts) Using only behavioral Verilog, you will design a machine that implements a recursive

averager to filter a continuous stream of incoming data. The recursive average will be computed

on a stream of 8-bit data values, and produce an 8-bit output. Internally, the recursive averager

should use a 16-bit accumulator (i.e. 8 bits of fractional precision). The 8-bit integer output of

the recursive averager will sent to an output port, and will be used to generate an alarm when the

output value exceeds a threshold value supplied to the module. Once active, the alarm output will

not clear until the averager output drops below 0.75 of the threshold value.

A recursive average is implemented according the signal flow diagram below. Note that in signal

processing terminology, z-1^ is a one sample period delay. In our case, this is equivalent to a one-

clock delay. At time step n , the output yn = (1- a )yn-1 + a xn.

Your recursive averager should implement a = 0.125. You must implement all mathematical

operations as integers (i.e. no floating-point operations) and no divide operations may be used.

The output y should be rounded.

Name your module threshold_detector and use the below ports. Do NOT include anything else

(i.e. your testbench code) in the file.

Inputs

d : 8-bit data input

threshold : 8-bit alarm threshold value

clk : Clock signal.

clr_n : An asynchronous, active-low reset.

Outputs

filtered_d : 8-bit filtered data output

alarm : 1-bit output.

(b) (6pts) Write a testbench that does the following;

1. applies a constant threshold value and d value to the module,

2. asserts and releases clr_n ,

3. applies 50 clocks,

4. sets the d value to 0,

5. applies 50 clocks.

Use a clock period of 10 simulation time steps. Use a monitor statement to output the simulation

time and alarm output only when the alarm output changes state. Repeat this sequence for each

of the value sets shown below.

1. threshold = 200, value = 255

2. threshold = 100, value = 200

3. threshold = 100, value = 110

4. threshold = 30, value = 3

[6] (20pts) - Our Friend the Verilog Stratified Event Queue

In this problem, we will examine the interaction of blocking and non-blocking assignment event

timing within the Verilog Stratified Event Queue. (If you haven’t read the Cumming’s

SNUG2000 paper yet, you may find it worthwhile to do so.)

Your job is to fill in the values in Table II. This table has six columns:

Time – The current simulation time.

Type – The type of event being processed by the simulator. We will be breaking events up into

two types: Evaluations ( EVAL) – evaluating the RHS of a Verilog statement, and Updates ( UP )

  • changing the value of a variable on the LHS of a Verilog statement.

Statement – The Verilog RHS or LHS of the statement that triggered the current event.

Result – The result of an evaluation if EVAL type or the value being assigned if UP type.

Values – The current value of all variables

Scheduled Events – Any new events that are added to the queue as the result of the current event.

For example, every EVAL event should schedule a corresponding UP event. If an UP event

triggers an always block, you should also list that here.

Table I gives the example data for Listing I. You must fill in Table II with the corresponding

data for Listing II. You should note that due to the nature of the Verilog Event Queue

standard, you may encounter cases for which the order of events is non-deterministic. In

these cases, you are free to choose any event ordering that conforms to the standard.

a = 4;

b = #7 3;

#2 a = 5;

end

always@(*)

s <= #6 a + c + d + e;

Time Type Statement Result Values Scheduled Events a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= a= b= c= d= e= s= Table II: Event processing timeline for Code Listing II