-
Notifications
You must be signed in to change notification settings - Fork 0
/
vga.v
136 lines (120 loc) · 3.26 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
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
`default_nettype none
module vga
(input wire clk_50M, reset,
output reg HS, VS,
output wire [9:0] row,
output wire [9:0] col,
output wire pixel_clk);
reg clr_row,
clr_col,
clr_hs,
clr_vs;
reg inc_row,
inc_col,
inc_hs,
inc_vs;
wire [11:0] hsCount;
wire [19:0] vsCount;
wire [9:0] rowCount;
wire [9:0] colCount;
wire //isVSDisp,
isHSDisp,
isVSPW,
isHSPW;
/* Assigns for location */
assign row = rowCount;
assign col = colCount;
/* Counters for row, column, HS, VS */
counter #(10) rowC(.clk(clk_50M),
.rst(reset),
.clr(clr_row),
.inc(inc_row),
.count(rowCount));
counter #(10) colC(.clk(clk_50M),
.rst(reset),
.clr(clr_col),
.inc(inc_col),
.count(colCount));
counter #(12) hsC(.clk(clk_50M),
.rst(reset),
.clr(clr_hs),
.inc(inc_hs),
.count(hsCount));
counter #(20) vsC(.clk(clk_50M),
.rst(reset),
.clr(clr_vs),
.inc(inc_vs),
.count(vsCount));
/* Display Times */
/* range_check #(20) vsCheck(.low(20'd49600),
.high(20'd817600),
.val(vsCount),
.is_between(isVSDisp));*/
range_check #(12) hsCheck(.low(12'd288),
.high(12'd1567),
.val(hsCount),
.is_between(isHSDisp));
/* Pulse times */
range_check #(20) vsCheck1(.low(20'd0),
.high(20'd3199),
.val(vsCount),
.is_between(isVSPW));
range_check #(12) hsCheck1(.low(12'd0),
.high(12'd192),
.val(hsCount),
.is_between(isHSPW));
// Counter Control logic
always @(*) begin
// Cycle HS counter
// 1599
clr_hs = (hsCount >= 12'd1599) ? 1'b1 : 1'b0;
inc_hs = (hsCount >= 12'd1599) ? 1'b0 : 1'b1;
// Cycle VS counter
clr_vs = (vsCount >= 20'd833599) ? 1'b1 : 1'b0;
inc_vs = (vsCount >= 20'd833599) ? 1'b0 : 1'b1;
end
counter #(1) pixClk(.clk(clk_50M),
.rst(reset),
.clr(clr_hs),
.inc(inc_hs),
.count(pixel_clk));
// HS control logic
always @(*) begin
// Pulse or no pulse
HS = (isHSPW) ? 1'b0 : 1'b1;
end
// VS control logic
always @(*) begin
VS = (isVSPW) ? 1'b0 : 1'b1;
end
// Row control logic
always @(*) begin
if (clr_col) begin
inc_row = 1'b1;
clr_row = 1'b0;
end
else if (isVSPW) begin
clr_row = 1'b1;
inc_row = 1'b0;
end
else begin
clr_row = 1'b0;
inc_row = 1'b0;
end
end
// Column control logic
always @(*) begin
if (isHSDisp && hsCount[0]) begin
inc_col = 1'b1;
clr_col = 1'b0;
end
else if (col >= 10'd640) begin
clr_col = 1'b1;
inc_col = 1'b0;
end
else begin
clr_col = 1'b0;
inc_col = 1'b0;
end
end
endmodule