【慢一拍】— 什么时候该慢一拍

判断准则:

首先看输入信号和输出信号是同步还是异步

  • 同步:看输入信号0-
  • 异步:看输入信号0+

 

实验测试:

1.异步

always@(posedge clk or negedge rst_n)

1.1组合逻辑、时序逻辑

module test_01
(
input clk,
input rst_n,
input in_01,

output out_01,
output reg out_02,
output reg out_03

);

assign out_01 = in_01;

always@(posedge clk or negedge rst_n)begin
if(rst_n == 1'b0)
out_02 <= 1'b0;
else
out_02 <= in_01;

end

always@(posedge clk or negedge rst_n)begin
if(rst_n == 1'b0)
out_03 <= 1'b0;
else if(in_01 == 1'b1)//同步
out_03 <= ~ out_03;
else 
out_03 <= 1'b0;
end

endmodule 

测试文件

`timescale 1ns/1ns

module tb_test_01;
reg clk;
reg rst_n;
reg in_01;

wire out_01;
wire out_02;
wire out_03;

initial begin
clk = 1'b0;
rst_n = 1'b0;
in_01 = 1'b0;
#16;

rst_n = 1'b1;

end

always #18 in_01 = {$random}%2;

initial begin 
$display("in_01 = %d ",in_01);
end

always #10 clk = ~ clk;


test_01 test_01_inst
(
.clk(clk),
.rst_n(rst_n),
.in_01(in_01),

. out_01(out_01),
. out_02(out_02),
. out_03(out_03)

);


endmodule 

 

posted @ 2022-04-27 20:15  刘小颜  阅读(27)  评论(0编辑  收藏  举报