1、Verilog描述具有有异步清0、异步置1的D触发器
//带有异步清0、异步置1的D触发器模块描述
module D_trigger(clk,set,rst,D,Q);
input clk;
input set;
input rst;
input D;
output Q;
reg Q; //寄存器定义
always @ (posedge clk or negedge rst or negedge set)
begin
if(~rst) //异步清0,低有效
begin
Q <= 1'b0;
end
else if(~set) //异步置1,低有效
begin
Q <= 1'b1;
end
else
begin
Q <= D;
end
end
endmodule
使用Quartus II 11.0综合布线之后的RTL视图如下:
2、Testbench描述
`timescale 1ns/1ns
module D_trigger_tb;
reg clk,set,rst,D;
wire Q;
D_trigger u1(.clk(clk),.set(set),.rst(rst),.D(D),.Q(Q));
initial
begin
clk=0;
set=0;
rst=1;
forever
begin
#60 D <= 1;
#22 D <= 0;
#2 D <= 1;
#2 D <= 0;
#16 D <= 0;
end
end
always #940 rst <= ~rst;
always #360 set <= ~set;
always #20 clk <= ~clk;
endmodule
(1)
`timescale是Verilog HDL `timescale
(2)modelsim仿真Testbench波形