-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_drawer.sv
161 lines (147 loc) · 3.6 KB
/
line_drawer.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
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
// Jose Jaime
// 3/6/20
// EE 371
// line_drawer Module
//
// Draws a column at each x coordinate to represent the magnitude of a particular frequency n
module line_drawer #(parameter N = 1024, data_width = 24, fp_width = 32, mag_width = 10, MAX_X = 640, MAX_Y = 480)
(
input logic clk, reset, is_idle,
// current magnitude to draw at frequency bin (x)
input logic [8:0] curr_peak,
//outputs cooresponding to the coordinate pair (x, y)
output logic [9:0] x,
output logic [8:0] y,
output logic pixel_color, draw_done,
output logic draw_state, clear_state
);
enum {drawing, clearing} ps, ns;
logic clear_done;
integer draw_reps;
assign draw_state = (ps == drawing);
assign clear_state = (ps == clearing);
assign pixel_color = (ps == drawing);
always_comb begin
case (ps)
drawing: if (draw_done) ns = clearing;
else ns = drawing;
clearing: if (clear_done && is_idle) ns = drawing;
else ns = clearing;
endcase
end
always_ff @(posedge clk) begin
if (reset) begin
ps <= clearing;
end else begin
ps <= ns;
end
end
always_ff @(posedge clk) begin
// Clear the screen
if (ps == clearing) begin
draw_done <= 1'b0;
if (x < N / 2) begin
x <= x + 1'b1;
end else begin
x <= 0;
if (y > 0) begin
y <= y - 1'b1;
end else begin
y <= 479;
clear_done <= 1'b1;
end
end
end
// Draw the column
if (ps == drawing) begin
clear_done <= 1'b0;
if (y > (479 - curr_peak)) begin
y <= y - 1'b1;
end else begin
y <= 479;
if (x < N / 2) begin
x <= x + 1'b1;
end else begin
x <= 0;
draw_reps <= draw_reps + 1;
if (draw_reps == 10) begin
draw_reps <= 0;
draw_done <= 1'b1;
end
end
end
end
end
endmodule
//// Used to test the line_drawer module
//module line_drawer_testbench();
// logic clk, reset, drawDone;
//
// // x and y coordinates for the start and end points of the line
// logic [9:0] x0, x1;
// logic [8:0] y0, y1;
//
// //outputs cooresponding to the coordinate pair (x, y)
// logic [9:0] x;
// logic [8:0] y;
//
// // debug signals
// logic is_steep;
// logic [10:0] calc_x0, calc_x1, calc_x;
// logic [10:0] calc_y0, calc_y1, calc_y;
// logic signed [10:0] error;
// logic signed [10:0] calc_error;
// logic signed [10:0] abs_dx;
// logic signed [10:0] abs_dy;
// logic signed [10:0] calc_dx;
// logic signed [10:0] calc_abs_dy;
// logic signed [1:0] y_step;
//
// parameter CLK_Period = 100;
//
// initial begin
// clk <= 1'b0;
// forever #(CLK_Period/2) clk <= ~clk;
// end
//
// line_drawer dut (clk, reset, drawDone, x0, x1, y0, y1, x, y, is_steep, calc_x0, calc_x1, calc_x, calc_y0, calc_y1, calc_y, error, calc_error, abs_dx, abs_dy, calc_dx, calc_abs_dy, y_step);
//
// initial begin
// reset <= 1; x0 <= 0; y0 <= 0; x1 <= 240; y1 <= 240; @(posedge clk);
// reset <= 0; @(posedge clk);
//
// repeat(500) begin
// @(posedge clk);
// end
//
// reset <= 1; x0 <= 0; y0 <= 0; x1 <= 10; y1 <= 240; @(posedge clk);
// reset <= 0; @(posedge clk);
//
// repeat(500) begin
// @(posedge clk);
// end
//
// reset <= 1; x0 <= 260; y0 <= 0; x1 <=40; y1 <= 240; @(posedge clk);
// reset <= 0; @(posedge clk);
//
// repeat(500) begin
// @(posedge clk);
// end
//
// reset <= 1; x0 <= 40; y0 <= 0; x1 <=260; y1 <= 240; @(posedge clk);
// reset <= 0; @(posedge clk);
//
// repeat(500) begin
// @(posedge clk);
// end
//
// reset <= 1; x0 <= 40; y0 <= 120; x1 <=260; y1 <= 120; @(posedge clk);
// reset <= 0; @(posedge clk);
//
// repeat(500) begin
// @(posedge clk);
// end
//
// $stop();
// end
//endmodule