信号上升沿检测,下降沿检测,边沿检测
时间:10-02
整理:3721RD
点击:
//上升沿检测,要求信号保持时间至少一个时钟周期
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
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
how can you implement it without a clk signal,
From my point of view, your code is more like a sequence detector (0->1) without clk, which is not correct, and also not synthesizable.
和楼上的同问,若是不使用时钟,怎么检测呢?
ding~
二楼的问错了吧?如果没有时钟,怎么检测信号的上升沿?如果信号不是时钟的话,只能采取延迟逻辑了,但不能进行这种设计,至少数字逻辑上不允许这种设计(定制的特定工艺的IP除外)。
上述的电路实际上是可综合的,不过缺少了复位的话,会给综合、DFT等带来问题。如果带上复位信号就比较完善了。
小兄弟们,思想是正确的,代码质量还有待提高哦,呵呵
不明白什么意思。
