RTL lab manual
RTL lab manual
OF INSTITUTIONS
(Approved by AICTE & Affiliated to JNTU-KAKINADA)
Vizianagaram-535216
LAB MANUAL
Regulation : R19
Department : ECE
List of Experiments:
1) Verilog implementation of
i) 8:1 Mux/Demux,
7) Verilog implementation of Arithmetic circuits like serial adder/ subtractor, parallel adder/subtractor,
serial/parallel multiplier.
Course Outcomes: At the end of the laboratory work, students will be able to:
Aim:To verify and perform the operation of logic gates using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input a;
input b;
always@(a or b)
begin
not1=~a;
or2=a|b;
and3=a&b;
nor4=~(a|b);
nand5=~(a&b);
xor6=(a^b);
xnor7=~(a^b);
endmodule
input a;
input b;
output[6:0]c;
and(c[0],a,b);
or(c[1],a,b);
not(c[2],a);
nand(c[3],a,b);
nor(c[4],a,b);
xor(c[5],a,b);
xnor(c[6],a,b);
endmodule
Testbench:
module logicgates_v;
reg a,b;
wire[6:0]c;
basicgates uut(.a(a),.b(b),.c(c));
initial begin
#10 a=1'b0;b=1'b0;
#10 a=1'b0;b=1'b1;
#10 a=1'b1;b=1'b0;
#10 a=1'b1;b=1'b1;
#10 $stop;
endmodule
Output Waveform:
Half adder
Aim:To verify and perform the operation of half adder using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input a;
input b;
output sum;
output carry;
reg sum,carry;
always@(a or b)
begin
sum=a^b;
carry=a&b;
end
endmodule
input a;
input b;
output sum;
output carry;
assign sum=a^b;
endmodule
Testbench:
module halfadderd_v;
reg a,b;
wire sum,carry;
halfadder uut(.a(a),.b(b),.sum(sum),.carry(carry));
initial begin
#10 a=1'b0;b=1'b0;
#10 a=1'b0;b=1'b1;
#10 a=1'b1;b=1'b0;
#10 a=1'b1;b=1'b1;
#10 $stop;
end
endmodule
Output Waveform:
Aim:To verify and perform the operation of full adder using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input a;
input b;
input cin;
always@(a or b or cin)
begin
case({a,b,cin})
3'b000:begin sum=1'b0;
carry=1'b0;
end
3'b001:begin sum=1'b1;
carry=1'b0;
end
3'b010:begin sum=1'b1;
carry=1'b0;
end
3'b011:begin sum=1'b0;
end
3'b100:begin sum=1'b1;
carry=1'b0;
end
3'b101:begin sum=1'b0;
carry=1'b1;
end
3'b110:begin sum=1'b0;
carry=1'b1;
end
3'b111:begin sum=1'b1;
carry=1'b1;
end
default:begin sum=1'b0;
carry=1'b0;
end
endcase
end
endmodule
module fulladder_b(a,b,cin,sum,cout);
input a,b,cin;
always@(a or b or cin)
begin
cout = (a&b)|(b&cin)|(a&cin);
end
endmodule
module fulladder_d(a,b,cin,sum,cout);
input a,b,cin;
output sum,cout;
assign sum=a^b^cin;
assign cout=(a&b)|(b&cin)|(a&cin);
endmodule
Testbench:
module fulladder_v;
reg a,b,cin;
wire sum,cout;
fulladder uut(.a(a),.b(b),.cin(cin),.sum(sum),.cout(cout));
initial begin
#10 a=1'b0;b=1'b0;cin=1'b0;
#10 a=1'b0;b=1'b0;cin=1'b1;
#10 a=1'b0;b=1'b1;cin=1'b0;
#10 a=1'b0;b=1'b1;cin=1'b1;
#10 a=1'b1;b=1'b0;cin=1'b0;
#10 a=1'b1;b=1'b0;cin=1'b1;
#10 a=1'b1;b=1'b1;cin=1'b0;
#10 a=1'b1;b=1'b1;cin=1'b1;
#10$stop;
endmodule
Output Waveform:
Half Subtractor:
Aim:To verify and perform the operation of Half Subtractor using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input a;
input b;
output reg D;
always@(a or b)
begin
D=a^b;
Borrow=(~a)&b;
End
module hs_d(a,b,D,Bor);
input a,b;
output D,Bor;
assign D=a^b;
assign Bor=!a&b;
endmodule
Testbench:
module halfsubtractor_v;
wire D,Bor;
hs uut(.a(a),.b(b),.D(D),.Bor(Bor));
initial begin
#10 a=1'b0;b=1'b0;
#10 a=1'b0;b=1'b1;
#10 a=1'b1;b=1'b0;
#10 a=1'b1;b=1'b1;
#10 $stop;
end
endmodule
endmodule
Output Waveform:
Aim:To verify and perform the operation of Full Subtractor using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input a ;
input b;
input cin;
output reg D;
always@(a or b or cin)
begin
D=a^b^cin;
borow=(cin&~(a^b))|((~a)&b);
end
endmodule
input a ;
input b;
input cin;
output D;
output borow;
assign D=a^b^cin;
endmodule
Testbench:
module fullsubtractor;
reg a,b,cin;
wire D,borow;
fs1 uut(.a(a),.b(b),.cin(cin),.D(D),.borow(borow));
initial begin
#10 a=1'b0;b=1'b0;cin=1'b0;
#10 a=1'b0;b=1'b0;cin=1'b1;
#10 a=1'b0;b=1'b1;cin=1'b0;
#10 a=1'b0;b=1'b1;cin=1'b1;
#10 a=1'b1;b=1'b0;cin=1'b0;
#10 a=1'b1;b=1'b0;cin=1'b1;
#10 a=1'b1;b=1'b1;cin=1'b0;
#10 a=1'b1;b=1'b1;cin=1'b1;
#10$stop;
end
endmodule
Aim:To verify and perform the operation of 4x1 Multiplexer using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input [3:0]a;
input [1:0]s;
output c;
reg c;
always@(a or s)
begin
case(s)
2'b00:c=a[0];
2'b01:c=a[1];
2'b10:c=a[2];
2'b11:c=a[3];
default:c=a[0];
endcase
end
endmodule
input [0:3]a;
input [1:0]s;
assign c=(!s[0]&!s[1]&a[0])|(s[0]&!s[1]&a[1])|(!s[0]&s[1]&a[2])|(s[0]&s[1]&a[3]);
endmodule
Testbench:
module mux41_tst_v;
reg[3:0]a;
reg[1:0]s;
wire c;
mux41 uut(.a(a),.s(s),.c(c));
initial begin
a=4'b0101;
s=2'b00;
#100s=2'b00;
#100s=2'b01;
#100s=2'b10;
#100s=2'b11;
end
endmodule
Aim:To verify and perform the operation of 1x4 Demultiplexer using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input a;
input [1:0]s;
output [0:3]c;
reg c;
always@(a or s)
begin
case(s)
2'b00:c={a,3'b000};
2'b01:c={1'b0,a,2'b00};
2'b10:c={2'b00,a,1'b0};
2'b11:c={3'b000,a};
default:c={a,3'b000};
endcase
end
endmodule
input a;
input [1:0]s;
assign c={(!s[0]&!s[1]&a),(s[0]&!s[1]&a),(!s[0]&s[1]&a),(s[0]&s[1]&a)};
endmodule
Testbench:
module demux1to4_tst_v;
reg a;
reg[1:0]s;
wire [0:3]c;
demux1to4 uut(.a(a),.s(s),.c(c));
initial begin
a=1;
s=2'b00;
#100s=2'b00;
#100s=2'b01;
#100s=2'b10;
#100s=2'b11;
end
endmodule
Aim:To verify and perform the operation of 4x2 Encoder using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input[3:0] a;
always@(a)
begin
case(a)
4'b0001:b=2'b00;
4'b0010:b=2'b01;
4'b0100:b=2'b10;
4'b1000:b=2'b11;
default:b=2'b00;
endcase
end
endmodule
Testbench
module encoder_tst_v;
reg [3:0] a;
wire [1:0]b;
begin
a= 4'b0001;
#100 a=4'b0010;
#100 a=4'b0100;
#100 a=4'b1000;
#100 $stop;
end
endmodule
Output Waveform:
Aim:To verify and perform the operation of 2x4 Decoder using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input[1:0] a;
output[3:0] b;
reg[3:0]b;
always@(a)
begin
b[3]=a[1]&a[0];
b[2]=!a[1]&a[0];
b[1]=a[1]&!a[0];
b[0]=!a[1]&!a[0];
end
endmodule
Testbench
module dec_v;
reg[1:0]a;
wire[3:0]b;
dec uut(.a(a),.b(b));
initial
begin
#100a=2'b01;
#100a=2'b10;
#100a=2'b11;
end
endmodule
Output Waveform
Aim:To verify and perform the operation of D Flipflop using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input d;
input clk;
input reset;
output q;
reg q;
begin
if(reset)
q<=1'b0;
else
q<=d;
end
endmodule
Testbench:
module dff_tst_v;
reg d;
reg clk;
reg reset;
dff uut(.d(d),.clk(clk),.reset(reset),.q(q));
initial begin
d=0;
clk=1;
reset=1;
#20 reset=0;
d=1;
#10 d=0;
#20 d=1;
#10 d=0;
end
always
#5 clk=~clk;
Endmodule
Output Waveform
Aim:To verify and perform the operation of JK Flipflop using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input j;
input k;
input clk;
input reset;
output q;
reg q;
begin
if(reset==1'b1)
q<=1'b0;
else
case({j,k})
2'b00:q<=q;
2'b01:q<=1'b0;
2'b10:q<=1'b1;
2'b11:q<=~q;
default:q<=q;
endcase
endmodule
Testbench
module jkff_tst_v;
reg j;
reg k;
reg clk;
reg reset;
wire q;
jkff uut(.j(j),.k(k),.clk(clk),.reset(reset),.q(q));
initial begin
j=0;
k=0;
clk=1;
reset=1;
#20 reset=0;
#10j=0;
k=1;
#10j=1;
k=0;
#10j=1;
k=1;
#40 $stop;
end
always
Endmodule
Output Waveform:
Aim:To verify and perform the operation of SR Flipflop using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input s,r,clk,reset;
output q;
reg q;
reg [1:0]sr;
begin
sr={s,r};
if(reset==0)
begin
case(sr)
2'd1:q=1'b0;
2'd2:q=1'b1;
2'd3:q=1'bx;
default:begin end
endcase
end
else
q=1'b0;
endmodule
Testbench
module srff_tst_v;
reg s;
reg r;
reg clk;
reg reset;
wire q;
srff uut(.s(s),.r(r),.clk(clk),.reset(reset),.q(q));
initial begin
s=0;
r=0;
clk=1;
reset=1;
#20 reset=0;
#10s=0;
r=1;
#10s=1;
r=0;
#10s=1;
r=1;
#40 $stop;
end
always
Endmodule
Output Waveform:
Aim:To verify and perform the operation of SISO registers using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
module siso1(sin,clk,reset,sout);
input sin;
input clk;
input reset;
reg r1,r2,r3;
begin
if(!reset)
begin
sout<=1'b0;
r1<=1'b0;
r2<=1'b0;
r3<=1'b0;
end
else
begin
r1<=sin;
r2<=r1;
end
end
endmodule
Testbench:
module siso_tst_v;
reg sin;
reg clk;
reg reset;
wire sout;
siso1 uut(.sin(sin),.clk(clk),.reset(reset),.sout(sout));
initial
begin
sin=0;
clk=1;
reset=1;
#20reset=0;
sin=1'b1;
#40sin=1'b0;
#40sin=1'b1;
#40sin=1'b1;
#80;
end
always
#5clk=~clk;
Output Waveform:
Aim:To verify and perform the operation of SISO register using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
module sipo(sin,clk,reset,pout);
input sin;
input clk;
input reset;
output [3:0]pout;
dff a1(.d(sin),.clk(clk),.reset(reset),.q(pout[0]));
dff a2(.d(pout[0]),.clk(clk),.reset(reset),.q(pout[1]));
dff a3(.d(pout[1]),.clk(clk),.reset(reset),.q(pout[2]));
dff a4(.d(pout[2]),.clk(clk),.reset(reset),.q(pout[3]));
endmodule
Testbench:
module sipo_tst_v;
reg sin;
reg clk;
reg reset;
wire[3:0]pout;
sipo uut(.sin(sin),.clk(clk),.reset(reset),.pout(pout));
initial
begin
clk=1;
reset=1;
#300reset=1'b0;
sin=1'b1;
#100sin=1'b0;
#100sin=1'b1;
#100sin=1'b1;
end
always
#50clk=~clk;
Endmodule
Output Waveform:
Aim:To verify and perform the operation of 2 bit comparator using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
module comparator_2bit(a,b,equal,greater,lower);
input [1:0]a;
input [1:0]b;
output equal;
output greater;
output lower;
assign equal=(a==b)?1:0;
assign greater=(a>b)?1:0;
assign lower=(a<b)?1:0;
endmodule
Testbench:
module comparator2_tst_v;
reg [1:0]a;
reg [1:0]b;
wire equal;
wire greater;
wire lower;
comparator_2bit uut(.a(a),.b(b),.equal(equal),.greater(greater),.lower(lower));
initial
a=10;
b=01;
#40 $stop;
end
endmodule
Output Waveform:
Aim:To verify and perform the operation of decade counter using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input reset,
always@(posedge clock)
begin
if(reset)
q <=4'b0000;
else if(q<=4'b1000)
q <= q+1'b1;
else
q <= 4'b0000;
end
endmodule
Testbench:
module mod_10_counter_test;
// Inputs
reg clock;
reg reset;
// Outputs
decade_counter uut (
.clock(clock),
.reset(reset),
.q(q)
);
always
initial begin
clock=0;
// Initialize Inputs
reset = 1;
#100;
reset=0;
#100;
reset=0;
#100;
end
endmodule
Aim:To verify and perform the operation of 4 bit parallel adder using Veilog HDL.
Apparatus:
2.Personal Computer
Program:
input [3:0]p,q;
input carry_in;
wire c1,c2,c3;
fa u1(p[0],q[0],carry_in,sum[0],c1);
fa u2(p[1],q[1],c1,sum[1],c2);
fa u3(p[2],q[2],c2,sum[2],c3);
fa u4(p[3],q[3],c3,sum[3],carry_out);
endmodule
Testbench:
module parallel_adder_tst_v;
reg[3:0]p,q;
reg carry_in;
wire[3:0]sum;
wire carry_out;
parallel_adder(.p(p),.q(q),.carry_in(carry_in),.sum(sum),.carry_out(carry_out));
initial
p=4'b0100;
q=4'b0011;
carry_in=1'b1;
#10
#10 p=4'b1010;
#10 q=4'b1010;
#10 carry_in=1'b0;
end
endmodule
Output Waveform:
Result: The operation of 4 bit parallel adder is verified using Verilog HDL.
module UART_TX
input i_Clock,
input i_TX_DV,
output o_TX_Active,
output o_TX_Done
);
reg r_TX_Done = 0;
reg r_TX_Active = 0;
begin
case (r_SM_Main)
IDLE :
begin
r_Clock_Count <= 0;
r_Bit_Index <= 0;
if (i_TX_DV == 1'b1)
begin
end
else
TX_START_BIT :
begin
begin
end
else
begin
r_Clock_Count <= 0;
end
TX_DATA_BITS :
begin
begin
end
else
begin
r_Clock_Count <= 0;
if (r_Bit_Index < 7)
begin
end
else
begin
r_Bit_Index <= 0;
end
end
TX_STOP_BIT :
begin
begin
end
else
begin
r_Clock_Count <= 0;
end
CLEANUP :
begin
end
default :
endcase
end
endmodule
TESTBENCH
`timescale 1ns/10ps
`include "UART_TX.v"
reg r_Clock = 0;
reg r_TX_DV = 0;
wire w_TX_Serial;
(.i_Clock(r_Clock),
.i_RX_Serial(w_UART_Line),
.o_RX_DV(w_RX_DV),
.o_RX_Byte(w_RX_Byte)
);
(.i_Clock(r_Clock),
.i_TX_DV(r_TX_DV),
.i_TX_Byte(r_TX_Byte),
.o_TX_Active(w_TX_Active),
.o_TX_Serial(w_TX_Serial),
.o_TX_Done()
);
always
// Main Testing:
initial
begin
@(posedge r_Clock);
@(posedge r_Clock);
@(posedge r_Clock);
@(posedge w_RX_DV);
if (w_RX_Byte == 8'h3F)
else
$finish();
end
initial
begin
$dumpfile("dump.vcd");
$dumpvars(0);
end
endmodule
OUTPUT WAVEFORMS
// Outputs
wire detector_out;
end
endmodule
RESULT: The Moore FSM Sequence Detector is designed and verified using Verilog HDL.