-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanInput.sv
70 lines (61 loc) · 1.3 KB
/
cleanInput.sv
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
69
70
module cleanInput (Clock, Reset, in, out);
input logic Clock, Reset, in;
output logic out;
enum {up, down, hold} ps, ns;
always_comb
case (ps)
up: begin
if (in) ns = down;
else ns = up;
end
down: begin
if (in) ns = hold;
else ns = up;
end
hold: begin
if (in) ns = hold;
else ns = up;
end
default: ns = up;
endcase
assign out = (ns == down);
always_ff @(posedge Clock)
if (Reset)
ps <= down;
else
ps <= ns;
endmodule
module cleanInput_testbench();
logic Clock, Reset, in, out;
cleanInput dut (Clock, Reset, in, out);
// Set up the clock
parameter CLOCK_PERIOD=100;
initial begin
Clock <= 0;
forever #(CLOCK_PERIOD/2) Clock <= ~Clock;
end
// Set up the inputs to the design. Each line is a clock cycle.
initial begin
@(posedge Clock); Reset <= 1;
@(posedge Clock);
@(posedge Clock); Reset <= 0;
@(posedge Clock);
@(posedge Clock); in <= 0;
@(posedge Clock);
@(posedge Clock);
@(posedge Clock);
@(posedge Clock); in <= 1;
@(posedge Clock);
@(posedge Clock);
@(posedge Clock);
@(posedge Clock); in <= 0;
@(posedge Clock);
@(posedge Clock); in <= 1;
@(posedge Clock);
@(posedge Clock); in <= 0;
@(posedge Clock); in <= 1;
@(posedge Clock); in <= 0;
@(posedge Clock);
$stop;
end
endmodule