-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvga.v
104 lines (87 loc) · 2.37 KB
/
vga.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
/*
generate test pattern at 640 x 480 @ 60Hz
total pixels is 800 x 525 @ 60Hz = 25.2Mhz = 39.6ns
Timings from :
* http://hamsterworks.co.nz/mediawiki/index.php/VGA_timings
* http://web.mit.edu/6.111/www/s2004/NEWKIT/vga.shtml
code adapted from VHDL :
* http://hamsterworks.co.nz/mediawiki/index.php/FPGA_VGA
* http://hamsterworks.co.nz/mediawiki/index.php/Dvid_test#vga.vhd
Horizontal Timing
640 h visible
16 front
96 sync
48 back
800 whole
- hsync
Vertical Timing
480 v visible
10 front
2 sync
33 back
525 whole
- vsync
45 blank lines at the bottom, 800 pix wide = 36k clocks for other things
*/
`default_nettype none
module vga (
input wire clk,
input wire reset,
input wire [5:0] color_px,
output reg [1:0] red,
output reg [1:0] green,
output reg [1:0] blue,
output reg [10:0] hcounter,
output reg [9:0] vcounter,
output reg hsync,
output reg vsync,
output reg blank,
output reg lower_blank
);
localparam border_w = 10;
always@(hcounter or vcounter) begin // results in a note about combinatorial logic
// black everywhere
red <= 3'b000;
green <= 3'b000;
blue <= 3'b000;
// sync
hsync <= 1'b1;
vsync <= 1'b1;
blank <= 1'b0;
lower_blank <= 1'b0;
// sync pulses
if(hcounter > 655 && hcounter < 751)
hsync <= 1'b0;
if(vcounter > 489 && vcounter < 491)
vsync <= 1'b0;
// blank is whenever outside of viewable area
if(hcounter > 639 || vcounter > 479)
blank <= 1'b1;
if(vcounter > 479 )
lower_blank <= 1'b1;
if(vcounter < 480 && hcounter < 640) begin
red <= color_px[5:4];
green <= color_px[3:2];
blue <= color_px[1:0];
end else begin
red <= 2'b0;
green <= 2'b0;
blue <= 2'b0;
end
end
// increment counters and wrap them
always@(posedge clk) begin
if(reset == 1) begin
hcounter <= 0;
vcounter <= 0;
end else if(hcounter == 799) begin
hcounter <= 0;
if(vcounter == 524) begin
vcounter <= 0;
end else
vcounter <= vcounter + 1;
end
else
hcounter <= hcounter + 1;
end
endmodule