我遇到了一个问题,我的模拟中的缓冲区没有按预期工作。
我尝试了一些测试,得到了以下结果。
我在Verilog中创建了以不同方式生成两个缓冲区的代码:
module buffer(
input wire clk,
input wire ena,
output wire buffer,
output wire buffer2
);
reg buffer_reg = 1'b0;
reg buffer_next = 1'b0;
reg buffer2_reg = 1'b0;
assign buffer = buffer_reg;
assign buffer2 = buffer2_reg;
always @(*) begin
buffer_next = ena;
end
always @(posedge clk) begin
buffer_reg <= buffer_next;
buffer2_reg <= ena;
end
endmodule
然后,我在Modelsim中使用以下测试台进行模拟:
`timescale 1ns / 1ns
module buffer_tb();
localparam CLK_CYCLE = 8;
reg clk;
reg ena;
wire buffer;
wire buffer2;
buffer dut(
.clk(clk),
.ena(ena),
.buffer(buffer),
.buffer2(buffer2)
);
// Clock generation
initial begin
clk = 1'b0;
end
always #(CLK_CYCLE/2) clk = ~clk;
// Test sequence
initial begin
// Initialize signals
ena = 0;
// change ena values based on the posedge clk
@(posedge clk) ena = 1;
@(posedge clk) ena = 0;
repeat(5) @(posedge clk);
@(posedge clk) ena = 1;
@(posedge clk) ena = 0;
repeat(2) #CLK_CYCLE;
// change ena values based on the CLK_CYCLE
#(CLK_CYCLE) ena = 1;
#CLK_CYCLE ena = 0;
repeat(5) #CLK_CYCLE;
#CLK_CYCLE ena = 1;
#CLK_CYCLE ena = 0;
// Allow simulation to run for a while
#50 $stop; // Stop simulation
end
endmodule
在模拟中,我得到了以下结果:
有人能解释一下为什么我得到的结果不同吗
buffer2
当我使用
posedge clk
当我使用
CLK_CYCLE
?