-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdebouncer_tb.v
68 lines (56 loc) · 1.38 KB
/
debouncer_tb.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
`timescale 1 ns/1 ns // time-unit, precision
`default_nettype none
module Debouncer_tb();
parameter CLOCK_HZ = 10_000_000;
parameter HALF_PERIOD_NS = 1_000_000_000 / (2 * CLOCK_HZ);
// Clock generator
reg Clock = 1'b1;
always begin
#HALF_PERIOD_NS;
Clock = !Clock;
end
// Delay task
task Delay_us(input integer DelayTime_us);
repeat((CLOCK_HZ / 1_000_000) * DelayTime_us)
@(posedge Clock);
endtask
// Variable dump
initial begin
$dumpfile("debouncer.vcd");
$dumpvars(0, Debouncer_tb);
end
// Variables
reg Reset = 1'b0;
reg Button = 1'b0;
// Test sequence
integer i;
initial begin
$timeformat(-6, 3, "us", 10);
$display("===== START =====");
$display("CLOCK_HZ = %9d", DUT.CLOCK_HZ);
$display("PERIOD_US = %9d", DUT.PERIOD_US);
$display("DELAY = %9d", DUT.DELAY);
$display("WIDTH = %9d", DUT.WIDTH);
@(posedge Clock)
Reset = 1'b1;
// Toggle state of Button signal and wait longer tine in each loop
for(i=1; i<=20; i=i+1) begin
Delay_us(i);
Button <= ~Button;
end
@(posedge Clock)
$display("====== END ======");
$finish;
end
// Instantiate device under test
Debouncer #(
.CLOCK_HZ(CLOCK_HZ),
.PERIOD_US(10)
) DUT(
.Clock(Clock),
.Reset(Reset),
.NoisySignal_i(Button),
.FilteredSignal_o()
);
endmodule
`default_nettype wire