-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbar.v
221 lines (188 loc) · 4.28 KB
/
bar.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
module bar(
input clk,
input resetn,
input start,
input fire,
input move,
input [7:0] cooldown,
input no_colour,
input ld_colour,
output [7:0] x,
output [6:0] y,
output [2:0] c_out,
output done);
wire ld_all, enable;
datapath_bar d0(
.clk(clk),
.resetn(resetn),
.ld_all(ld_all),
.enable(enable),
.fire(fire),
.move(move),
.cooldown(cooldown),
.no_colour(no_colour),
.ld_colour(ld_colour),
.x(x),
.y(y),
.c_out(c_out));
control_bar c0(
.clk(clk),
.resetn(resetn),
.start(start),
.ld_all(ld_all),
.enable(enable),
.done(done));
endmodule
module datapath_bar(
input clk,
input resetn,
input ld_all,
input enable,
input fire,
input move,
input [7:0] cooldown,
input no_colour,
input ld_colour,
output reg [7:0] x,
output reg [6:0] y,
output reg [2:0] c_out);
reg [7:0] x_hold;
reg [6:0] y_hold;
reg [2:0] c_hold;
reg [9:0] counter;
reg double;
reg [3:0] increment;
// Registers x_hold, y_hold, c_hold with respective input logic
always @ (posedge clk) begin
if (!resetn)
begin
x_hold <= 8'd0; // Top left x coordinates of bar
y_hold <= 7'd0; // Top left y coordinates of bar
c_hold <= 3'd0;
end
else if (fire)
begin
x_hold <= 8'd127; // Top left x coordinates of bar
y_hold <= 7'd75; // Top left y coordinates of bar
c_hold <= 3'd7;
end
else if (ld_all)
begin
x_hold <= 8'd75; // Top left x coordinates of bar
y_hold <= 7'd120; // Top left y coordinates of bar
c_hold <= 3'd7;
end
else if (move)
begin
if (y_hold < 7'd124)
begin
y_hold = y_hold + 1'd1;
end
end
if (ld_colour)
begin
if (no_colour)
c_hold <= 3'd0;
else
c_hold <= 3'd7;
end
end
always @ (posedge clk) begin
if (!resetn | fire)
begin
x <= 8'd0;
y <= 7'd0;
c_out <= 3'd0;
end
else if (enable)
begin
x <= x_hold + increment[3:1];
y <= y_hold + increment[0:0];
c_out <= c_hold;
end
end
always@(posedge clk)
begin: increment_counter
if(!resetn | !enable | fire)
begin
increment <= 4'd0;
end
else if (enable)
begin
increment <= increment + 1'd1;
end
end // increment
endmodule
module control_bar(
input clk,
input resetn,
input start,
output reg ld_all,
output reg enable,
output reg done);
reg [4:0] current_state, next_state;
reg [9:0] counter;
wire wait_plot = (counter > 10'd16);
localparam S_DRAW = 5'd0,
S_DONE = 5'd1,
S_INITIAL = 5'd2,
S_START = 5'd3,
S_START_WAIT = 5'd4;
// Next state logic aka our state table for plotting
always@(*)
begin: state_table
case (current_state)
S_INITIAL: next_state = start ? S_DRAW : S_INITIAL; // Loads initial x position
S_START: next_state = start ? S_DRAW : S_START;
S_DRAW: next_state = wait_plot ? S_DONE : S_DRAW;
S_DONE: next_state = S_START;
default: next_state = S_INITIAL;
endcase
end // state_table
// Output logic aka all of our datapath control signals
always @(*)
begin: enable_signals
// By default make all our signals 0
ld_all = 1'b0;
enable = 1'b0;
done = 1'b0;
case (current_state)
S_INITIAL:
begin
ld_all = 1'b1;
end
S_DRAW:
begin
enable = 1'b1;
end
S_DONE:
begin
done = 1'b1;
end
default: enable = 1'b0;
endcase
end
always@(posedge clk)
begin: sixteen_counter
if(!resetn | !enable)
begin
counter <= 10'd0;
end
else
begin
counter <= counter + 1'd1;
end
end // counter
// current_state registers
always@(posedge clk)
begin: state_FFs
if(!resetn)
begin
current_state <= S_INITIAL;
end
else
begin
current_state <= next_state;
end
end // state_FFS
endmodule