Index: S.No Experiment Name Date of Experiment Date of Submission Remark & Sign 1
Index: S.No Experiment Name Date of Experiment Date of Submission Remark & Sign 1
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
1
A
LAB REPORT
ON
MICROELECTRONICS AND VLSI DESIGN LAB
EC-1653
Submitted to:
Submitted by:
2
DATE- 08/01/2018
EXPERIMENT NO. : 01
AIM : To design and simulate different logic gates using Verilog HDL.
EDA TOOL USED :- Xilinx ISE Design Suit 14.4
METHODOLOGY :-
LOGIC GATE :- In electronics, a logic gate is a device which performs logical operation on
one or more logical inputs and produces a single logical output. NAND Gate and NOR Gate
are universal gates.
AND GATE :- Output of a AND gate is logic high if all the inputs are set (logic high).
Otherwise output is logic low.
OR GATE :- Output of a OR gate is logic high if any one of the inputs is set (logic high). If
all the inputs are clear then the output is logic low.
NAND GATE :- Output of a NAND gate is logic low if all the inputs are set (logic high).
Otherwise output is logic high.
NOR GATE :- Output of a NOR gate is logic low if any one of the inputs is set (logic high).
If all the inputs are clear then the output is logic high.
XOR GATE :- If odd number of inputs are set then the output is logic high, otherwise
output is logic low.
XNOR GATE :-
If odd number of inputs are set then the output is logic low, otherwise output is logic high.
3
XNOR gate: NAND gate:
INPUTS OUTPUTS
A B And Or Nand Nor Xor Xnor
0 0 0 0 1 1 0 1
0 1 0 1 1 0 1 0
1 0 0 1 1 0 1 0
1 1 1 1 0 0 0 1
GATE LEVEL:
VERILOG CODE :-
`timescale 1ns / 1ps
module logic_gates(
output And_op,Or_op,Nand_op,Nor_op,Xor_op,Xnor_op,
input a,b);
4
and a1(And_op,a,b);
xor a2(Xor_op,a,b);
nand a3(Nand_op,a,b);
or a4(Or_op,a,b);
nor a5(Nor_op,a,b);
xnor a6(Xnor_op,a,b);
endmodule
DATA FLOW:
VERILOG CODE :
`timescale 1ns / 1ps
module data( output y1,y2,y3,y4,y5,y6,y7,y8,
input a,b);
assign y1=a&b; //and gate
assign y2=~y1; //nand gate
assign y3=a|b; //or gate
assign y4=~y3; //nor gate
assign y5=a^b; //xor gate
assign y6=~y5; //xnor gate
assign y7=~a; //not gate
assign #100 y8=a; //buffer
endmodule
BEHAVIOR LEVEL :
VERILOG CODE:
module exp1
(input a,
input b,
output reg o1,
output reg o2,
output reg o3,
output reg o4,
5
output reg o5,
output reg o6);
always @(a or b)
case({a,b})
2'b00 : begin
o1 = 0;
o2 = 1;
o3 = 0;
o4 = 1;
o5 = 0;
o6 = 1;
end
2'b01 : begin
o1 = 0;
o2 = 1;
o3 = 1;
o4 = 0;
o5 = 1;
o6 = 0;
end
2'b10 : begin
o1 = 0;
o2 = 1;
o3 = 1;
o4 = 0;
o5 = 1;
o6 = 0;
end
2'b11 : begin
6
o1 = 1;
o2 = 0;
o3 = 1;
o4 = 0;
o5 = 0;
o6 = 1;
end
endcase
endmodule
RTL SCHEMATIC :
TEST BENCH :
module exp1test;
// Inputs
reg a;
reg b;
// Outputs
wire o1;
wire o2;
7
wire o3;
wire o4;
wire o5;
wire o6;
// Instantiate the Unit Under Test (UUT)
exp1 uut (
.a(a),
.b(b),
.o1(o1),
.o2(o2),
.o3(o3),
.o4(o4),
.o5(o5),
.o6(o6)
);
initial begin
// Initialize Inputs
a = 0;b = 0;
#100;
a = 0;b = 1;
#100;
a = 1;b = 0;
#100;
a = 1;b = 1;
#100;
// Wait 100 ns for global reset to finish
#100;
end
endmodule
8
OUTPUT :
RESULT:- Different logic gates are implemented using gate level modeling and
operations are verified by simulation.
9
DATE- 08/01/2018
EXPERIMENT NO 02
AIM: To design and simulate half and full adder, half and full subtractor using Verilog
HDL.
S=A xor B
C=A and B
10
Table 2.1 Truth table of half adder
Input A Input B Sum S Carry C
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
D= A xor B
B = (not A) and B
11
Table 2.3 Truth table of half subtractor
Input A Input B Difference D Borrow B
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
HALF ADDER:
VERILOG CODE:
GATE LEVEL:
module ha1(
input a,
input b,
output s,
output c
);
xor(s,a,b);
and(c,a,b);
endmodule
DATA FLOW:
12
module ha2(
input a,
input b,
output s,
output c );
assign s=a^b;
assign c=a&b;
endmodule
BEHAVIOURAL LEVEL:
module ha3(
input a,
input b,
output reg s,
output reg c );
always@(a,b)
begin
case({a,b})
2'b00: begin s=0;c=0; end
2'b01: begin s=1;c=0; end
2'b10: begin s=1;c=0; end
2'b11: begin s=0;c=1; end
endcase
end
endmodule
RTL:
13
Fig 2.5 RTL of half adder
TEST BENCH:
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
OUTPUT WAVEFORM:
14
input x,
input y,
output b,
output d
);
assign d=x^y;
assign b=(!x)&y;
endmodule
BEHAVIOURAL LEVEL:
module hs3(
input x,
input y,
output reg b,
output reg d );
always@(x,y)
begin
case({x,y})
2'b00: begin b=0;d=0; end
2'b01: begin b=1;d=1; end
2'b10: begin b=0;d=1; end
2'b11: begin b=0;d=0; end
endcase
end
endmodule
RTL:
15
Fig 2.9 RTL of half subtractor
TEST BENCH:
x = 0;y = 0;#100;
x = 0;y = 1;#100;
x = 1;y = 0;#100;
x = 1;y = 1;#100;
OUTPUT WAVEFORM:
16
endmodule
DATA FLOW:
module fa2(
input a,
input b,
input ci,
output s,
output c );
assign s=a^b^ci;
assign c=(ci&(a^b))|(a&b);
endmodule
BEHAVIOURAL LEVEL:
module ha3(
input a,
input b,
input ci,
output reg s,
output reg c
);
always@(a,b,ci)
begin
case({a,b,ci})
3'b000: begin s=0;c=0; end
3'b001: begin s=1;c=0; end
3'b010: begin s=1;c=0; end
3'b011: begin s=0;c=1; end
3'b100: begin s=1;c=0; end
3'b101: begin s=0;c=1; end
3'b110: begin s=0;c=1; end
3'b111: begin s=1;c=1; end
endcase
end
17
endmodule
RTL :
18
input y,
input z,
output d,
output b
);
wire p,q,r,s,t,m,n,u,v;
xor(p,y,z);
not(q,x);
not(r,p);
or(m,y,z);
and(n,y,z);
and(u,q,m);
or(b,u,n);
and(s,q,p);
and(t,x,r);
or(d,s,t);
endmodule
DATA FLOW:
module fs2(
input x,
input y,
input z,
output b,
output d );
assign b=((!x)&(y+z))+(y&z);
assign d=((!x)&(y^z))+(x&(!(y^z)));
endmodule
BEHAVIOURAL LEVEL:
module fs3(
input x,
input y,
input z,
19
output reg b,
output reg d
);
always@(x,y,z)
begin
case({x,y,z})
3'b000:begin b=0;d=0; end
3'b001:begin b=1;d=1; end
3'b010:begin b=1;d=1; end
3'b011:begin b=1;d=0; end
3'b100:begin b=0;d=1; end
3'b101:begin b=0;d=0; end
3'b110:begin b=0;d=0; end
3'b111:begin b=1;d=1; end
endcase
end
endmodule
RTL:
20
x = 1; y = 0; z = 0; #100;
x = 1; y = 0; z = 1; #100;
x = 1; y = 1; z = 0; #100;
x = 1; y = 1; z = 1; #100;
OUTPUT WAVEFORM:
RESULT: Half adder, half subtractor, full adder and full subtractor was successfully
implemented using Xilinx.
21
DATE- 15/01/2018
EXPERIMENT NO 03
AIM: Design and simulation of 4 bit parallel adder.
TOOLS: Xilinx ISE Design Software
METHODOLOGY: The full adder is capable of adding only two single digit binary
number along with a carry input. But in practical we need to add binary numbers which are
much longer than just one bit. To add two n-bit binary numbers we need to use the n-bit
previous full adder is connected to carry input of the next full adder. Therefore this method
can be used to design a 4 bit parallel adder that can add A and B each of 4 bit.
VERILOG CODE:
GATE LEVEL:
module pa1(input [3:0]a, input [3:0]b, output [3:0]c, output cout, output [3:0]sum );
22
fa A0(a[0],b[0],0,sum[0],c[0]);
fa A1(a[1],b[1],c[0],sum[1],c[1]);
fa A2(a[2],b[2],c[1],sum[2],c[2]);
fa A3(a[3],b[3],c[2],sum[3],c[3]);
buf(cout,c[3]);
endmodule
module fa(
input a ,
input b,
input ci,
output s,
output c
);
wire p,q,r;
xor(p,a,b);
xor(s,p,ci);
and(q,p,ci);
and(r,a,b);
or(c,q,r);
endmodule
BEHAVIOURAL LEVEL:
23
module exp3(
input [3:0] a,
input [3:0] b,
output [3:0] s,
output cout
);
wire w1, w2, w3;
fa i1(a[0],b[0],1'b0,s[0],w1);
fa i2(a[1],b[1],w1,s[1],w2);
fa i3(a[2],b[2],w2,s[2],w3);
fa i4(a[3],b[3],w3,s[3],cout);
endmodule
module fa(
input c,
input d,
input e,
output reg s,
output reg cy
);
always @(c or d or e)
case({c,d,e})
3'b000 : begin
s = 0;
cy = 0;
end
3'b001 : begin
s = 1;
cy = 0;
end
24
3'b010 : begin
s = 1;
cy = 0;
end
3'b011 : begin
s = 0;
cy= 1;
end
3'b100 : begin
s = 1;
cy = 0;
end
3'b101 : begin
s = 0;
cy = 1;
end
3'b110 : begin
s = 0;
cy = 1;
end
3'b111 : begin
s = 1;
cy= 1;
end
endcase
endmodule
RTL:
25
Fig 3.2 RTL of 4 bit parallel adder
TEST BENCH:
module exp3test;
// Inputs
reg [3:0] a;
reg [3:0] b;
// Outputs
wire [3:0] s;
wire cout;
// Instantiate the Unit Under Test (UUT)
exp3 uut (
.a(a),
.b(b),
.s(s),
.cout(cout)
);
initial begin
// Initialize Inputs
a = 0;
b = 0;
// Wait 100 ns for global reset to finish
#100;
26
a = 4'b1000; b = 4'b1111;
#100;
a = 4'b1011; b = 4'b1011;
#100;
a = 4'b0000; b = 4'b1110;
#100;
a = 4'b1011; b = 4'b0111;
#100;
end
endmodule
OUTPUT WAVEFORM:
27
DATE- 15/01/2018
EXPERIMENT NO 04
AIM: Design and simulation of a full adder using half adder.
TOOLS: Xilinx ISE Design Software
METHODOLOGY: Full adder is a digital circuit used to calculate the sum of three
binary bits which is the main difference between this and half adder. Full adders are complex
and difficult to implement when compared to half adders. Two of the three bits are same as
before which are A, the augend bit and B, the addend bit. The additional third bit is carry bit
from the previous stage and is called Carry – in generally represented by CIN. It calculates
the sum of three bits along with the carry. The output carry is called Carry – out and is
represented by COUT. A full adder can be formed by logically connecting two half adders.
The block diagram that shows the implementation of a full adder using two half adders is
shown below.
VERILOG CODE:
BEHAVIOURAL LEVEL:
module exp4(
input a,
28
input b,
input c,
output s,
output cout
);
wire w1, w2,w3;
ha i1(a,b,w3,w1);
ha i2(w3,c,s,w2);
assign cout = (w1|w2);
endmodule
module ha(
input d,e,
output reg sum,
output reg cy
);
always @(d or e)
case({d,e})
2'b00 : begin
sum = 0;
cy = 0;
end
2'b01 : begin
sum = 1;
cy = 0;
end
2'b10 : begin
sum = 1;
cy = 0;
end
29
2'b11 : begin
sum = 0;
cy= 1;
end
endcase
endmodule
RTL:
TEST BENCH:
module exp4test;
// Inputs
reg a;
reg b;
reg c;
// Outputs
wire s;
wire cout;
// Instantiate the Unit Under Test (UUT)
exp4 uut (
.a(a),
.b(b),
30
.c(c),
.s(s),
.cout(cout)
);
initial begin
// Initialize Inputs
a = 0;
b = 0;
c = 0;
// Wait 100 ns for global reset to finish
a = 0;b = 0;c = 0;
#100;
a = 0;b = 0;c = 1;
#100;
a = 0;b = 1;c = 0;
#100;
a = 0;b = 1;c = 1;
#100;
a = 1;b = 0;c = 0;
#100;
a = 1;b = 0;c = 1;
#100;
a = 1;b = 1;c = 0;
#100;
a = 1;b = 1;c = 1;
#100;
end
endmodule
OUTPUT WAVEFORM:
31
Output waveform of a full adder
32