Professional Documents
Culture Documents
JK Flip flop
Code:
//21BCT0226
//Mohammed Mohsin Jawed
module jk_ff ( input j, input k, input clk, output q);
reg q;
.k(k),
.clk(clk),
.q(q));
k <= 0;
#5 j <= 0;
k <= 1;
#20 j <= 1;
k <= 0;
#20 j <= 1;
k <= 1;
initial
initial begin
clk <= 0;
d <= 0;
rstn <= 0;
#15 d <= 1;
#10 rstn <= 1;
for (int i = 0; i < 5; i=i+1) begin
delay = $random;
#(delay) d <= i;
end
end
endmodule
T Flip flop
Code:
//21BCT0226
//Mohammed Mohsin Jawed
module tff ( input clk, input rstn, input t, output reg q);
//21BCT0226
module tb;
reg clk;
reg rstn;
reg t;
tff u0 ( .clk(clk),
.rstn(rstn),
.t(t),
.q(q));
initial begin
rstn <= 1;
end
#20 $finish;
end
endmodule
2. Write the Verilog code and Testbench for SISO, SIPO, PISO,
SIPO.
SISO:
Code:
//21BCT0226
if (clear)
end
endmodule
Test bench:
//21BCT0226
module sisot_b;
clk = 0;
clear = 0;
si = 0;
#5 clear=1’b1;
#5 clear=1’b0;
#10 si=1’b1;
#10 si=1’b0;
#10 si=1’b0;
#10 si=1’b1;
#10 si=1’b0;
#10 si=1’bx;
end
endmodule
SIPO:
Code:
//21BCT0226
//Mohammed Mohsin Jawed
module sipot_b;
clk = 0;
clear = 0;
si = 0;
#5 clear=1’b1;
#5 clear=1’b0;
#10 si=1’b1;
#10 si=1’b0;
#10 si=1’b0;
#10 si=1’b1;
#10 si=1’b0;
#10 si=1’bx;
end
endmodule
PISO:
Code:
//21BCT0226
//Mohammed Mohsin Jawed
module pipot_v;
reg clk; reg clear;
reg [3:0] pi;
wire [3:0] po;
pipomod uut
(.clk(clk),.clear(clear),.pi(pi),.po(po
) ); initial begin
clk = 0;
clear = 0;
pi = 0;
#5 clear=1’b1;
#5 clear=1’b0;
#10 pi=4’b1001;
#10 pi=4’b1010;
#10 pi=4’b1011;
#10 pi=4’b1110;
#10 pi=4’b1111;
#10 pi=4’b0000;
end
always #5 clk = ~clk;
initial #150 $stop;
endmodule
3. Design bit universal shift register and write Verilog code.
Code:
//21BCT0226
//Mohammed Mohsin Jawed
module juniversalShiftRegister(DATAOUT, clock, reset, MODE, DATAIN);
output reg [3:0] DATAOUT;
input clock, reset;
input [1:0] MODE;
input [3:0] DATAIN;
always @(posedge clock)
begin
if(reset) DATAOUT <= 0;
else
begin
case(MODE)
2'b00 : DATAOUT <= DATAOUT;
2'b01 : DATAOUT <= {DATAIN[0], DATAOUT[3:1]};
2'b10 : DATAOUT <= {DATAOUT[2:0], DATAIN[0]};
2'b11 : DATAOUT <= DATAIN;
endcase
end
end
endmodule
Testbench:
//21BCT0226
module juniversalShiftRegisterTb;
juniversalShiftRegister
MODE, DATAIN);
initial
begin
= 4'b0000;
reset = 0; #10;
4'b0011; #10;
$display("PASS\t%p is %p with
else
$display("FAIL\t%p is %p with
4'b0011; #10;
$display("PASS\t%p is %p with
else
$display("FAIL\t%p is %p with
$display("PASS\t%p is %p with
else
$display("FAIL\t%p is %p with
4'b0111; #10;
$display("PASS\t%p is %p with
else
$display("FAIL\t%p is %p with
$display("PASS\t%p is %p with
else
$display("FAIL\t%p is %p with
#20;
$finish;
end
initial
begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule