这是一道触发器的题目,但是仿真波形和我分析出来的不太一样下面是我的代码:
module T_ff(input T,input clk,input rst,output reg Q, output reg Qn);
initial
begin
Q <= 0;
Qn <= 1;
end
always @(posedge clk,negedge rst)
begin
if(~rst)
begin
Q <= 0;
Qn <= 1;
end
else
case(T)
1'b0: begin Q <= Q; Qn <= ~Q; end
1'b1: begin Q <= ~Q; Qn <= Q; end
default: begin Q <= Q; Qn <= ~Q; end
endcase
end
endmodule
module D_ff(input D,input clk,output reg Q,output reg Qn);
initial
begin
Q = 0;
Qn = 1;
end
always @(negedge clk)
begin
Q <= D;
Qn <= ~D;
end
endmodule
module jK_ff(input J,input K,input clk,output reg Q,output reg Qn);
initial
begin
Q = 0;
Qn = 1;
end
always @(negedge clk)
begin
case({J,K})
2'b00: begin Q <= Q; Qn <= ~Q; end
2'b01: begin Q <= 0; Qn <= 1; end
2'b10: begin Q <= 1; Qn <= 0; end
2'b11: begin Q <= ~Q; Qn <= Q; end
default: begin Q<=Q; Qn<= ~Q;end
endcase
end
endmodule
module FF(input clk, input t,output Q3);
wire Q1,Q2,Q1n,Q2n,Q3n,rst;
and(rst,Q2n,Q3n);
T_ff t_ff(.T(t),.clk(clk),.rst(rst),.Q(Q1),.Qn(Q1n));
D_ff d_ff(.D(Q1),.clk(clk),.Q(Q2),.Qn(Q2n));
JK_ff jk_ff(.J(Q2),.K(Q1n),.clk(clk),.Q(Q3),.Qn(Q3n));
endmodule
`timescale 1ns/1ns
module tb();
reg CLK,t;
wire Q3;
initial
begin
CLK<=0;
t<=1;
repeat(100)#10 CLK <= ~CLK;
end
FF ff(.clk(CLK),.t(t),.Q3(Q3));
endmodule
有大佬帮帮刚学数电的萌新吗
|