-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.v
52 lines (38 loc) · 1.08 KB
/
display.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
module display( input clock, reset, freeze,
input [15:0] data,
output reg [8:0] x,
output reg [7:0] y,
output [2:0] color,
output plot);
localparam sweep_delay = 10000, xmax = 319, ymax = 239;
reg [31:0] delay_counter;
reg st, streg;
// FSM for sweep control
localparam st_ploty = 0, st_done = 1;
always @(*) begin
st = streg;
case(streg)
st_ploty: if(y == ymax) st = st_done;
st_done: if(!freeze && (delay_counter == sweep_delay)) st = st_ploty;
endcase
end
always @(posedge clock)
if(reset) streg <= st_done;
else streg <= st;
// Delay and X counters
always @(posedge clock)
if(reset) begin
delay_counter <= 0;
x <= 0;
end else if(streg == st_done)
if(delay_counter == sweep_delay) begin
delay_counter <= 0;
x <= (x == xmax) ? 0 : x + 1;
end else delay_counter <= delay_counter + 1;
// Y counter
always @(posedge clock)
if(reset || (streg == st_done)) y <= 0;
else if(y < ymax) y <= y + 1;
assign plot = (streg == st_ploty);
assign color = (y == 8'd120+{data[15], data[6:0]});
endmodule