You are on page 1of 5

1/11/2016

EE 241 DIGITAL CIRCUITS


MIDTERM I SOLUTION MANUAL

Name:

Q1) (20 points) A combinational circuit is represented by the truth table below. Describe this circuit
in Verilog using dataflow modeling.

Inputs Output
x y z w
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 0

Note: The simplest description will get a 5 points bonus.

Solution:

Inputs Output SOP


x y z w
0 0 0 1 𝑥̅ . 𝑦̅. 𝑧̅
0 0 1 0
0 1 0 1 𝑥̅ . 𝑦. 𝑧̅
0 1 1 0
1 0 0 1 𝑥. 𝑦̅. 𝑧̅
1 0 1 0
1 1 0 1 𝑥. 𝑦. 𝑧̅
1 1 1 0

𝑤 = 𝑥̅ . 𝑦̅. 𝑧̅ + 𝑥̅ . 𝑦. 𝑧̅ + 𝑥. 𝑦̅. 𝑧̅ + 𝑥. 𝑦. 𝑧̅
(Bonus) look at the relationship with input z and output w.

𝑤 = 𝑧̅
-----------------------------------------
module question1(w,x,y,z);

output w;
input x,y,z;

assign w=~z;
endmodule
-----------------------------------------
Q2) (30 points) What will be the value of arrays y2, y1, y0 when the below Verilog description is
simulated? The input array is set as x=8h’4F for simulation.

Note: Correct answer for y2, y1, y0 will get 10 points each. Besides, no partial points will be granted in
this question.
-----------------------------------------
module question2(y2, y1, y0, x);

output reg [7:0] y2, y1, y0;


input [7:0] x;

initial
begin
y0=8'h00;
y1=8'h00;
y2=8'h00;
end

always @ (x)
begin
y0 <= x/2;
y1 <= y0 + x;
y2 <= y1 + x*2;
end

endmodule
-----------------------------------------

Solution:

Hexadecimal Decimal

You can use the below testbench file to obtain the results.
-----------------------------------------
Testbench file
module question2_tb;

// Inputs
reg [7:0] xt;

// Outputs
wire [7:0] y2t,y1t,y0t;
// Instantiate the Unit Under Test (UUT)
question2 uut(y2t,y1t,y0t,xt);

initial begin
#10 xt=8'h4F;
end

endmodule
-----------------------------------------
Q3) (50 points) A two-axis joystick provides analog voltage values corresponding to its horizontal (x-
axis) and vertical (y-axis) position when an analog interfacing is done. These analog voltage values can
be converted to digital form by an analog to digital converter (ADC) module. Assume that, the analog
interfacing is done and the ADC module is set to work. Hence, you get two arrays as xp and yp each
with eight bits. Hexadecimal values of these arrays with respect to the joystick position is given below.

yp
FF

7F

00
xp
00 7F FF

We will use LEDs and switches on the Basys3 board for our operation. Therefore, LEDs and switches
15 to 8 are assigned to the vertical position (yp array) reading. LEDs and switches 7 to 0 are assigned
to the horizontal position (xp array) reading.

a- (20 points) Form a Verilog description to display the joystick axes values directly via designated
LEDs.

Solution:

-----------------------------------------
module question3a(led,xp,yp);

output [15:0] led;


input [7:0] xp,yp;

assign led={yp,xp};

endmodule
-----------------------------------------
b- (30 points) Let’s design a simple game using our setup. The first user forms a 16-bit pattern with
setting each switch as ‘on’ or ‘off’. The second user (without seeing this pattern) tries to match this
pattern by moving the joystick in x and y axis. When the second user matches the pattern with the
joystick position, all LEDs will turn off. Form a Verilog description to realize this game.

Solution:

-----------------------------------------
module question3b(led,xp,yp,sw);

output [15:0] led;


input [15:0] sw;
input [7:0] xp,yp;

assign led={yp,xp}-sw;

endmodule
-----------------------------------------

You might also like