Beruflich Dokumente
Kultur Dokumente
E1 E0 0 0 01 11 10 E1 E0 0 0 01 11 10
E3 E2 E3 E2
00 ϕ ϕ 0 ϕ 00 ϕ ϕ 0 ϕ
01 0 0 0 0 01 0 0 1 0
C3 C2
11 1 ϕ ϕ ϕ 11 1 ϕ ϕ ϕ
10 1 1 1 1 10 0 0 0 0
E1 E0 0 0 01 11 10 E1 E0 0 0 01 11 10
E3 E2 E3 E2
00 ϕ ϕ 0 ϕ 00 ϕ ϕ 0 ϕ
01 0 1 0 1 01 1 0 0 1
C1 C0
11 0 ϕ ϕ ϕ 11 0 ϕ ϕ ϕ
10 0 0 1 1 10 0 1 1 0
(b) Read the K-maps to obtain minimal SoP expressions for the two output variables C3 C2 and
minimal PoS expressions for the two output variables C1 C0. [4]
C3 = E3, C2 = E3 E2 + E2 E1 E0,
C1 = (E3 + E1’ + E0’)(E1 + E0)(E3’ + E1) and C0 = (E3 + E0’)(E3’ + E0).
(c) Find the minimum number of chips required for generating the four output bits, realising the SoP
expressions with 2-level NAND-NAND circuits, and the PoS expressions with 2-level NOR-NOR
circuits, given that both NAND and NOR gate chips are available in quad 2-input, triple 3-input and
dual 4-input configurations. [2]
Gate requirements:
Output 2-input 3-input 4-input NOT Chips
C3 - - - - 1 Triple 3-input NAND chip
C2 2 1 -
C1 2 2 - 3 1 triple 3-input and 2 quad 2-input NOR chips
C0 3 - -
Question 4 (10 marks):
The Karnaugh maps for two functions Q1 and Q2 of four variables A, B, C, D are given below. These
functions have to be realised using two 4-input multiplexers and NAND/NOR/XOR gates.
Q1 Q2
CD 0 0 0 1 1 1 1 0 CD 0 0 0 1 1 1 1 0
AB AB
00 1 0 00 0 1
01 1 0 1 01 1 0 0
11 0 0 1 11 0 1
10 1 0 10 0 1 1
(a) Tabulate the Data Inputs required for the two multiplexers for three different choices of the
Select inputs of the multiplexers in the format given below. [3x2]
Select AB CD AC
Output Q1 Q2 Q1 Q2 Q1 Q2
Input
X0 D’ D’ A’ / B’ A’ / B B + D’ D’
- X1 C’ + D’ C’ D’ A’ B B’ D’ B’ D’
X2 D C+D A’ / B B’ 0 B’ D
X3 C C A A/B D 1
(b) Hence find the minimum number of gates required for a realisation using only one kind (NAND
or NOR) of gate for each of the above choices of the Select inputs. [3]
Select AB CD AC
NAND D’, (CD)’, ((C’D’)’)’, (C’D’)’ 6 B’, ((A’B)’)’ 4 D’, (B’D)’, ((B’D’)’)’, ((B’D)’)’ 6
NOR D’, ((C’+D’)’)’, (C+D)’, ((C+D)’)’ 6 B’, (A+B’)’ 2 D’, ((B+D’)’)’, (B+D)’, (B+D’)’ 4
Minimum 6 gates 2 gates 4 gates
So the choice Select = C D gives the minimum number of gates: only 2 NOR gates.
Question 5 (8 marks):
(a) Write the Verilog code for a full adder. It has 3 inputs, a, b, cin (carry in) and 2 outputs (sout
and cout). You may use any kind of coding style. [3]
module full_adder(a,b,cin,sout,cout);
input a,b,cin;
output reg sout,cout;
always@(*) begin
{cout,sout}=a+b+cin;
end
endmodule
(b) Write a Verilog code for a D latch. It has 2 inputs, “din” and “en” and one output “q”. When the
en input is high the value of din should pass on q and when en is zero, the old “latched” value of
din should remain at q. [3]
module dlatch (
din ,
en ,
q );
input din, en ;
output q;
reg q;
always @ ( en or din)
if (en) begin
q <= din;
end
endmodule
(c) In the below code snippet, “a” carries a value of 4(0100) and “b” carries a value of 7 (0111) in
beginning. Write a code in the space provided so that you can swap the values of a and b without
using a 3rd variable or register. So, the displayed values should be “7” for a and “4” for b. [2]
`timescale 1ns / 1ps
module test();
reg [3:0] a;
reg [3:0] b ;
initial
begin
a = 4'b0100;
b = 4'b0111;
//Write your code here
a<=b;
b<=a;
#5;
(b) Draw a timing waveform for the reg ”a” from the below Verilog code. [1]
module test;
reg a;
initial
begin
a = 0;
end
always
#5 a =! a;
Endmodule
(c) What are the displayed values of a, b,c,d if you compile and run the below Verilog code? [2]
module test ();
reg a, b, c, d;
initial
begin
#5;
a = 1;
$display("Value of a is ",a);
b <= #5 a;
$display("Value of b is ",b);
c <= b;
#10;
$display("Value of c is ",c);
d =b;
$display("Value of d is ",d);
end
endmodule
a =1
b = x (undefined)
c = x (undefined)
d=1
Question 7 (6 marks):
(a) What is the difference between structural and behavioral coding style in Verilog? Give a small
example. [2]
In structural data flow modelling, digital design functions are defined using components
such as an inverter, a MUX, an adder, a decoder, basic digital logic gates etc.
input A, B;
output sum, carry;
xor (.in1(A), .in2(B), .out(sum));
and (.in1(A), .in2(B), .out(carry));
Behavioral code uses direct assigns, procedural blocks like always etc
input A, B;
output sum, carry;
wire sum, carry;
assign sum = A ^ B;
assign carry = A & B;
(b) Is it compulsory for an always block to have a sensitivity list? Explain its significance. What can
happen if some of the signals being read inside the always block are omitted from the sensitivity
list? [2]
No, it is not compulsory for an always block to have a sensitivity list. If there are n signals
in the sensitivity list of always block, any change on any of the n signals causes the
statements inside the always block to execute. If some signals are omitted which are being
read, it might lead to synthesis – simulation mismatch
(c) State one advantage of Verilog over C which makes it popular as a hardware description
language. [1]
C language does not support concurrent execution of statements which is an important
aspect of modelling any Hardware system
(d) Consider the following Verilog code
module test();
wire temp;
always
begin
#5;
temp = 1 ;
$display ("Value of temp is", temp);
end
endmodule