-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsource.v
executable file
·88 lines (83 loc) · 1.38 KB
/
source.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
`timescale 1ns/1ns
module source( output reg [1:0] y,
input x,
input rst,
input clk
);
parameter S0 = 3'b000, S1 = 3'b001, S2 = 3'b010, S3 = 3'b011, S4 = 3'b100, S5 = 3'b101, S6 = 3'b110, S7 = 3'b111;
reg [2:0] s;
initial begin
y <= 2'b00;
end
always @(negedge clk) begin
if(rst == 1'b1) begin
s <= S0;
y <= 2'b00;
end
end
always @(posedge clk) begin
begin
if(s == S0) begin
if(x == 1'b0) begin
s <= S1;
y <= 2'b00;
end
else
begin
s <= S0;
y <= 2'b00;
end
end
else if(s == S1) begin
if(x == 1'b0) begin
s <= S1;
y <= 2'b00;
end
else begin
s <= S2;
y <= 2'b00;
end
end
else if(s == S2) begin
if(x == 1'b0) begin
s <= S1;
y <= 2'b01;
end
else begin
s <= S3;
y <= 2'b00;
end
end
else if(s == S3) begin
if(x == 1'b0) begin
s <= S1;
y <= 2'b10;
end
else begin
s <= S4;
y <= 2'b00;
end
end
else if(s == S4) begin
if(x == 1'b0) begin
s <= S1;
y <= 2'b11;
end
else begin
s <= S4;
y <= 2'b00;
end
end
else begin
if(x == 1'b0) begin
s <= S0;
y <= 2'b00;
end
else begin
s <= S0;
y <= 2'b00;
end
end
end
end
endmodule