帶有同步清0、同步置1的D觸發器模組描述及其Testbench測試
阿新 • • 發佈:2019-01-31
1、Verilog描述具有有非同步清0、非同步置1的D觸發器
使用Quartus II 11.0綜合佈線之後的RTL檢視如下://同步復位、置位D觸發器模組描述 module D_synctrigger(clk,rst,set,D,Q); input clk,rst,set,D; output Q; reg Q;//暫存器定義 always @(posedge clk) 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
2、Testbench描述
modelsim模擬Testbench波形//同步復位、置位D觸發器Testbench描述 `timescale 1ns/1ns module D_synctrigger_tb; reg clk,rst,set,D; wire Q; D_synctrigger u1(.clk(clk),.rst(rst),.set(set),.D(D),.Q(Q)); initial begin clk = 0; rst = 0; set = 0; 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