Vlsi Assignment Harry2007
Vlsi Assignment Harry2007
Topic:
VERILOG HDL
B.TECH (ECE)
by
E.Hari Krishna(08BEC113)
VIT
UNIVERSITY
(Estd. U/s 3 of UGC Act 1956)
NOVEMBER , 2010
8 X 3 ENCODER
TRUTH TABLE:
Ip[0 Ip[1 Ip[2 Ip[3 Ip[4 Ip[5 Ip[6 Ip[7 Op[0 Op[1 Op[2]
] ] ] ] ] ] ] ] ] ]
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
output[2:0] op;
always@(ip)
begin
case(ip)
8'b00000001: op=3'b000;
8'b00000010: op=3'b001;
8'b00000100: op=3'b010;
8'b00001000: op=3'b011;
8'b00010000: op=3'b100;
8'b00100000: op=3'b101;
8'b01000000: op=3'b110;
8'b10000000: op=3'b111;
endcase
end
endmodule
TESTBENCH CODE:
module jhvb_v;
// Inputs
reg [7:0] ip;
// Outputs
wire [2:0] op;
// Instantiate the Unit Under Test (UUT)
enco uut (.ip(ip), .op(op));
initial begin
// Initialize Inputs
ip=8'b10000000;
#10 ip=8'b01000000;
#20 ip=8'b00100000;
#30 ip=8'b00010000;
#80 ip=8'b00001000;
#50 ip=8'b00000100;
#90 ip=8'b00000010;
#30 ip=8'b00000001;
end
initial
$monitor ($time," enco_input = %b enco_output = %b",ip,op);
endmodule
OUTPUT:-
0 enco_input = 10000000 enco_output = 111
10 enco_input = 01000000 enco_output = 110
30 enco_input = 00100000 enco_output = 101
60 enco_input = 00010000 enco_output = 100
140 enco_input = 00001000 enco_output = 011
190 enco_input = 00000100 enco_output = 010
280 enco_input = 00000010 enco_output = 001
310 enco_input = 00000001 enco_output = 000
TRUTH TABLE:
Ip[0] Ip[1] Ip[2] Ip[3] Op[0] Op[1]
1 X X X 0 0
0 1 X X 0 1
0 0 1 X 1 0
0 0 0 1 1 1
input [3:0]ip;
always @(ip)
begin
casex (ip)
4'b1xxx :op=2'b00;
4'b01xx :op=2'b01;
4'b001x :op=2'b10;
4'b0001 :op=2'b11;
endcase
end
endmoduleTESTBENCH CODE:
module pri_test_v;
// Inputs
// Outputs
initial begin
// Initialize Inputs
#10 ip=4'b0110;
#10 ip=4'b0010;
#10 ip=4'b0101;
#10 ip=4'b0110;
#10 ip=4'b0111;
#10 ip=4'b1000;
#10 ip=4'b1001;
end
initial
endmodule
OUTPUT:
0 input=0001 output = 11
10 input=0110 output = 01
20 input=0010 output = 10
30 input=0101 output = 01
40 input=0110 output = 01
50 input=0111 output = 01
60 input=1000 output = 00
70 input=1001 output = 00
TIMING DIAGRAM:
3 X 8 DECODER
TRUTH TABLE:
Ip[0] Ip[1] Ip[2] Op[0] Op[1] Op[2] Op[3] O[4] Op[5] Op[6] Op[7]
0 0 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0 1 0 0
0 1 1 0 0 0 0 1 0 0 0
1 0 0 0 0 0 1 0 0 0 0
1 0 1 0 0 1 0 0 0 0 0
1 1 0 0 1 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0
module decoder(ip,op);
input [2:0]ip;
output [7:0]op;
reg [7:0]op;
always@(ip)
begin
case(ip)
3'b000:op=8'b00000001;
3'b001:op=8'b00000010;
3'b010:op=8'b00000100;
3'b011:op=8'b00001000;
3'b100:op=8'b00010000;
3'b101:op=8'b00100000;
3'b110:op=8'b01000000;
3'b111:op=8'b10000000;
endcase
end
endmodule
TESTBENCH CODE:
module fcv_v;
// Inputs
reg [2:0] ip;
// Outputs
wire [7:0] op;
// Instantiate the Unit Under Test (UUT)
decoder uut (.ip(ip),
.op(op));
initial begin
ip=3'b000;
#10 ip=3'b001;
#10 ip=3'b010;
#10 ip=3'b011;
#10 ip=3'b100;
#10 ip=3'b101;
#10 ip=3'b110;
#10 ip=3'b111;
end
initial
Endmodule
OUTPUT:
0 input = 000 output = 10000000
10 input = 001 output = 01000000
20 input = 010 output = 00100000
30 input = 011 output = 00010000
40 input = 100 output = 00001000
50 input = 101 output = 00000100
60 input = 110 output = 00000010
70 input = 111 output = 00000001
TIMING DIAGRAM:
4 BIT RIPPLE CARRY ADDER
CIRCUIT DIAGRAM:
endmodule
TESTBENCH CODE:
module nvbn_v;
// Inputs
reg [3:0] a;
reg [3:0] b;
reg c_in;
// Outputs
wire [3:0] sum;
wire c_out;
initial begin
// Initialize Inputs
$monitor($time,"a=%b,b=%b,c_in=%b,c_out=%b,sum=%b
\n",a,b,c_in,--c_out,sum);
end
OUTPUT:
0 a=0000,b=0000,c_in=0,--c_out=0,sum=0000
10 a=0011,b=0100,c_in=0,--c_out=0,sum=0111
20 a=0010,b=0101,c_in=0,--c_out=0,sum=0111
30 a=1001,b=1001,c_in=0,--c_out=1,sum=0010
40 a=1010,b=1111,c_in=0,--c_out=1,sum=1001
50 a=0000,b=0101,c_in=1,--c_out=1,sum=0000
TIMING DIAGRAM:
8 X 1 MULTIPLEXER
TRUTH TABLE:
s0 s1 s2 O
0 0 0 i0
0 0 1 i1
0 1 0 i2
0 1 1 i3
1 0 0 i4
1 0 1 i5
1 1 0 i6
1 1 1 i7
input [7:0]i;
input [2:0]s;
output reg o;
always @(i or s)
begin
case (s)
3'b000 : o=i[0];
3'b001 : o=i[1];
3'b010 : o=i[2];
3'b011 : o=i[3];
3'b100 : o=i[4];
3'b101 : o=i[5];
3'b110 : o=i[6];
3'b111 : o=i[7];
endcase
end
endmodule
TESTBENCH CODE:
module mutb_v;
// Inputs
// Outputs
wire out;
.in(in),
.sel(sel) );
initial begin
// Initialize Inputs
i=8'b10110010;
s=3'b000;
#10 s=3'b001;
#40 s=3'b010;
#10 s=3'b011;
#30 s=3'b100;
#80 s=3'b101;
#10 s=3'b110;
#20 s=3'b111;
end
initial
OUTPUT:
TIMING DIAGRAM:
1 X 8 DE-MULTIPLEXER
TRUTH TABLE:
s0 s1 s2 I0 I1 I2 I3 I4 I5 I6 I7
0 0 0 I 0 0 0 0 0 0 0
0 0 1 0 I 0 0 0 0 0 0
0 1 0 0 0 I 0 0 0 0 0
0 1 1 0 0 0 I 0 0 0 0
1 0 0 0 0 0 0 I 0 0 0
1 0 1 0 0 0 0 0 I 0 0
1 1 0 0 0 0 0 0 0 I 0
1 1 1 0 0 0 0 0 0 0 I
VERILOG CODE:
module demux(out,in,sel);
input in;
input [2:0]sel;
output reg [7:0]out;
always @(in or out)
begin
out=8'b0;
case (sel)
3'b000 : out[0]=in;
3'b001 : out[1]=in;
3'b010 : out[2]=in;
3'b011 : out[3]=in;
3'b100 : out[4]=in;
3'b101 : out[5]=in;
3'b110 : out[6]=in;
3'b111 : out[7]=in;
endcase
end
endmodule
TESTBENCH CODE:
module demux_v;
// Inputs
reg in;
// Outputs
demux uut (
.out(out),
.ip(ip),
.sel(sel) );
initial begin
// Initialize Inputs
in=1'b1;
sel=3'b000;
#10 sel=3'b001;
#20 sel=3'b010;
#30 sel=3'b011;
#40 sel=3'b100;
#50 sel=3'b101;
#60 sel=3'b110;
#70 sel=3'b111;
end
initial
endmodule
OUTPUT:
0 input = 1 sel = 000 output = 00000001
TIMING DIAGRAM:
D FLIP FLOP (POSITIVE EDGE)
TRUTH TABLE:
D Q Output
0 0 Low
1 1 High
module d_ff(q,d,clk,reset);
output reg q;
input d,clk,reset;
always @(posedge reset or posedge clk)
if(reset)
q<=1'b0;
else
q<=d;
endmodule
TESTBENCH CODE:
module d_ff_t_v;
// Inputs
reg d;
reg clk;
reg reset;
// Outputs
wire q;
initial begin
// Initialize Inputs
d = 0;
clk = 0;
reset = 0;
// Add stimulus here
#10 reset = 1;
#10 reset =0;
#10 d = 1;
#10 d = 0;
#10 d = 0;
#10 d = 1;
#10 d = 1;
end
always
#10 clk = ~clk;
endmodule
TIMING DIAGRAM:
SHIFT REGISTER (SISO)
CIRCUIT DIAGRAM:
TRUTH TABLE:
CLK i0 i1 i2 i3
1 1 1 1 0
2 0 1 1 1
3 0 0 1 1
4 0 0 0 1
module siso(q,clk,i);
output reg [3:0] q;
input clk,i;
always @(posedge clk)
begin
q[0] <=i;
q[1] <=q[0];
q[2] <=q[1];
q[3] <=q[2];
end
endmodule
TESTBENCH CODE:
module siso_t_v;
// Inputs
reg clk;
reg i;
// Outputs
wire [3:0] q;
initial begin
// Initialize Inputs
clk = 0;
i = 0;
// Add stimulus here
#20 in = 1;
#20 in = 1;
#20 in = 1;
#20 in = 0
end
always
#10 clk = ~clk;
endmodule
TIMING DIAGRAM:
MODULO-10 COUNTER
TRUTH TABLE:
a0 b0 c0 d0 a1 b1 c1 d1
0 0 0 0 0 0 0 1
0 0 0 1 0 0 1 0
0 0 1 0 0 0 1 1
0 0 1 1 0 1 0 0
0 1 0 0 0 1 0 1
0 1 0 1 0 1 1 0
0 1 1 0 0 1 1 1
0 1 1 1 1 0 0 0
1 0 0 0 1 0 0 1
1 0 0 1 0 0 0 0
STATE DIAGRAM:
VERILOG CODE:
TIMING DIAGRAM: