-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.sv
68 lines (54 loc) · 1.22 KB
/
simple.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
module simple (clk, reset, w, out);
input logic clk, reset, w;
output logic out;
// State variables.
enum { A, B, C } ps, ns;
// Next State logic
always_comb
case (ps)
A: if (w) ns = B;
else ns = A;
B: if (w) ns = C;
else ns = A;
C: if (w) ns = C;
else ns = A;
// default: ns = 2'bxx;
endcase
// Output logic - could also be another always, or part of above block.
assign out = (ps == C);
// DFFs
always_ff @(posedge clk)
if (reset)
ps <= A;
else
ps <= ns;
endmodule
module simple_testbench();
logic clk, reset, w;
logic out;
simple dut (clk, reset, w, out);
// Set up the clock.
parameter CLOCK_PERIOD=100;
initial begin
clk <= 0;
forever #(CLOCK_PERIOD/2) clk <= ~clk;
end
// Set up the inputs to the design. Each line is a clock cycle.
initial begin
@(posedge clk);
reset <= 1; @(posedge clk);
reset <= 0; w <= 0; @(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
w <= 1; @(posedge clk);
w <= 0; @(posedge clk);
w <= 1; @(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
w <= 0; @(posedge clk);
@(posedge clk);
$stop; // End the simulation.
end
endmodule