module D_FF(D,clk,sync_reset,Q);
input D; // Data input
input clk; // clock input
input sync_reset; // synchronous reset
output reg Q; // output Q
always @(posedge clk)
begin
if(sync_reset==1'b1)
Q <= 1'b0;
else
Q <= D;
end
endmodule
`timescale 100ns/1ns
module TB;
reg D,clk,sync_reset;
wire Q;
D_FF UUT(D,clk,sync_reset,Q);
initial begin
clk=0;
forever #5 clk = ~clk;
end
initial begin
D=0; sync_reset=0;
#10 sync_reset=1;
#10 sync_reset=0;
#12 D=1;
#12 D=0;
#12 D=1;
#10 sync_reset=1;
#12 D=1;
#10 $stop;
end
endmodule
module T(T,clk,sync_reset,Q); // T Flip Flop
input T; // Data input
input clk; // clock input
input sync_reset; // synchronous reset
output reg Q; // output Q
always @(posedge clk)
begin
if(sync_reset==1'b1)
Q <= 1'b0;
else
if (T)
Q <= ~Q;
else
Q <= Q;
end
endmodule
`timescale 100ns/1ns
module TB;
reg T,clk,sync_reset;
wire Q;
T UUT(T,clk,sync_reset,Q);
initial begin
clk=0;
forever #5 clk = ~clk;
end
initial begin
T=0; sync_reset=0;
#10 sync_reset=1;
#10 sync_reset=0;
#12 T=1;
#12 T=0;
#18 T=1;
#10 sync_reset=1;
#25 T=1;
#10 $stop;
end
endmodule
module JK_FF (J,K,clk,sync_reset,Q);
input J,K,clk,sync_reset;
output reg Q;
always @ (posedge clk) begin
if (sync_reset==1'b1)
Q <= 1'b0;
else
case ({J,K})
2'b00 : Q <= Q;
2'b01 : Q <= 0;
2'b10 : Q <= 1;
2'b11 : Q <= ~Q;
endcase
end
endmodule
`timescale 100ns/1ns
module TB;
reg J,K,clk,sync_reset;
wire Q;
JK_FF UUT (J,K,clk,sync_reset,Q);
initial begin
clk=0;
forever #5 clk = ~clk;
end
initial begin
J=1;K=0; sync_reset=0;
#10 sync_reset=1;
#10 sync_reset=0;
#12 J=1;K=0;
#12 J=1;K=1;
#12 J=0;K=1;
#10 sync_reset=1;
#12 J=1;K=1;
#10 sync_reset=0;
#12 J=0;K=1;
#12 J=1;K=0;
#10 $stop;
end
endmodule
沒有留言:
張貼留言