|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
//上升沿检测,要求信号保持时间至少一个时钟周期
module rising_edge_check(clock, signal, rising_flag);
input clock;
input signal;//input signal
output rising_flag;//rising edge flag
reg [2:0] temp=3'b000;
always @(posedge clock)
temp<={temp[1:0],signal};
assign rising_flag=(temp[1:0]==2'b01)?1'b1:1'b0;
endmodule
//testbench
module test_rising_edge_check_v;
// Inputs
reg clock;
reg signal;
// Outputs
wire rising_flag;
// Instantiate the Unit Under Test (UUT)
rising_edge_check uut (
.clock(clock),
.signal(signal),
.rising_flag(rising_flag)
);
initial begin
// Initialize Inputs
clock = 0;
signal = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
signal=1;
#500;
signal=0;
#500;
signal=1;
#200;
signal=0;
#100;
signal=1;
#300;
signal=0;
end
always #100 clock=~clock ;
endmodule
//下降沿检测,要求信号保持时间至少一个时钟周期
module falling_edge_check(clock, signal, falling_flag);
input clock;
input signal;
output falling_flag;
reg [2:0] temp=3'b111;
always @(posedge clock)
temp<={temp[1:0],signal};
assign falling_flag=(temp[1:0]==2'b10)?1'b1:1'b0;
endmodule
//testbench
module test_falling_edge_check_v;
// Inputs
reg clock;
reg signal;
// Outputs
wire falling_flag;
// Instantiate the Unit Under Test (UUT)
falling_edge_check uut (
.clock(clock),
.signal(signal),
.falling_flag(falling_flag)
);
initial begin
// Initialize Inputs
clock = 0;
signal = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
signal=1;
#500;
signal=0;
#500;
signal=1;
#200;
signal=0;
#100;
signal=1;
#300;
signal=0;
end
always #100 clock=~clock ;
endmodule |
|