多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
` `在使用FPGA时,常使用时序电路,利用时钟边沿来读数据或者写数据,若是对于同一个时钟,在想通边沿写数据和读数据,是怎么样的结果? ` `以下是在[iverilog网页版](https://hdlbits.01xz.net/wiki/Iverilog)测试的module和仿真结果。 ``` module top_module (); reg clk; reg din; reg rst_n; wire [0:0]dout; always #4 clk = ~clk; // Create clock with period=10 initial `probe_start; // Start the timing diagram //`probe(clk); // Probe signal "clk" // A testbench initial begin clk=0; rst_n=0; #10 din = 0; #4 rst_n=1; #4 din=1; #9 din=0; //$display ("Hello world! The current time is (%0d ps)", $time); #100 $finish; // Quit the simulation end test inst1( .rst_n(rst_n), .clk(clk), .div(32'd1) ); `probe(clk); endmodule module test ( input rst_n, input wire clk, input [31:0]div, output clk_ot ); reg [3:0]data; reg rd; always@(posedge clk) if(!rst_n)data <= 0; else data <= data + 1; reg [2:0]cnt; always@(posedge clk) begin if(!rst_n)cnt <= 0; else begin cnt <= cnt + 1; end end reg [3:0]rdata; always@(posedge clk) begin if(!rst_n)rd <= 0; else begin rd <= (cnt%3 == 0)? 1:0; rdata <= (cnt%3 == 0)? data:0; end end `probe(rst_n); `probe(clk); `probe(data); `probe(rd); `probe(rdata); endmodule ``` ![](https://img.kancloud.cn/8c/43/8c43c185bd7abfd4d2e5fcdb49e6eea2_1092x540.png) ` `可以看到读出的数据,是上一次写入数据,因此根据时序图写时序模块时,读取的数据是跳变沿之前紧跟着的数据。