This commit is contained in:
@@ -1,8 +1,63 @@
|
||||
`timescale 1ns / 1ps
|
||||
module debouncer_tb;
|
||||
|
||||
logic clk,reset,source;
|
||||
wire out;
|
||||
|
||||
int errors;
|
||||
|
||||
debouncer Dut (.*);
|
||||
|
||||
initial begin
|
||||
clk = 0;
|
||||
forever #10 clk = ~clk;
|
||||
end
|
||||
|
||||
initial begin
|
||||
$display("Testing debouncer");
|
||||
reset = 1;
|
||||
source = 0;
|
||||
@(posedge clk);
|
||||
@(posedge clk);
|
||||
reset = 0;
|
||||
@(posedge clk);
|
||||
source = 1;
|
||||
#1;
|
||||
assert (out == 1) else begin
|
||||
$error("Output not brought high during first press");
|
||||
errors++;
|
||||
end
|
||||
@(posedge clk);
|
||||
#1;
|
||||
assert (out == 0) else begin
|
||||
$error("Output not brought low after first press");
|
||||
errors++;
|
||||
end
|
||||
@(posedge clk);
|
||||
source = 0;
|
||||
@(posedge clk);
|
||||
source = 1;
|
||||
#1;
|
||||
assert (out == 1) else begin
|
||||
$error("Output not brought high during second press");
|
||||
errors++;
|
||||
end
|
||||
source = 0;
|
||||
@(posedge clk);
|
||||
#1;
|
||||
assert (out == 0) else begin
|
||||
$error("Output not brought low after second press");
|
||||
errors++;
|
||||
end
|
||||
|
||||
if (errors == 0)
|
||||
$display("Found no errors while testing debouncer");
|
||||
|
||||
$finish;
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
endmodule
|
||||
|
||||
Reference in New Issue
Block a user