1 |
19 |
robfinch |
// ============================================================================
|
2 |
|
|
// __
|
3 |
|
|
// \\__/ o\ (C) 2012-2020 Robert Finch, Waterloo
|
4 |
|
|
// \ __ / All rights reserved.
|
5 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
6 |
|
|
// ||
|
7 |
|
|
//
|
8 |
|
|
// VGASyncGen.v
|
9 |
|
|
// VGA sync generator
|
10 |
|
|
//
|
11 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
12 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
13 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
14 |
|
|
// (at your option) any later version.
|
15 |
|
|
//
|
16 |
|
|
// This source file is distributed in the hope that it will be useful,
|
17 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
|
|
// GNU General Public License for more details.
|
20 |
|
|
//
|
21 |
|
|
// You should have received a copy of the GNU General Public License
|
22 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
23 |
|
|
//
|
24 |
|
|
//
|
25 |
|
|
//
|
26 |
|
|
// VGA video sync generator.
|
27 |
|
|
//
|
28 |
|
|
// This module generates the basic sync timing signals required for a
|
29 |
|
|
// VGA display.
|
30 |
|
|
//
|
31 |
|
|
// ============================================================================
|
32 |
|
|
|
33 |
|
|
module VGASyncGen(rst, clk, eol, eof, hSync, vSync, hCtr, vCtr,
|
34 |
|
|
blank, vblank, vbl_int, border,
|
35 |
|
|
hTotal_i, vTotal_i,
|
36 |
|
|
hSyncOn_i, hSyncOff_i, vSyncOn_i, vSyncOff_i,
|
37 |
|
|
hBlankOn_i, hBlankOff_i, vBlankOn_i, vBlankOff_i,
|
38 |
|
|
hBorderOn_i, vBorderOn_i, hBorderOff_i, vBorderOff_i);
|
39 |
|
|
input rst; // reset
|
40 |
|
|
input clk; // video clock
|
41 |
|
|
output reg eol;
|
42 |
|
|
output reg eof;
|
43 |
|
|
output reg hSync, vSync; // sync outputs
|
44 |
|
|
output [11:0] hCtr;
|
45 |
|
|
output [11:0] vCtr;
|
46 |
|
|
output reg blank; // blanking output
|
47 |
|
|
output reg vblank;
|
48 |
|
|
output reg vbl_int;
|
49 |
|
|
output border;
|
50 |
|
|
input [11:0] hTotal_i;
|
51 |
|
|
input [11:0] vTotal_i;
|
52 |
|
|
input [11:0] hSyncOn_i;
|
53 |
|
|
input [11:0] hSyncOff_i;
|
54 |
|
|
input [11:0] vSyncOn_i;
|
55 |
|
|
input [11:0] vSyncOff_i;
|
56 |
|
|
input [11:0] hBlankOn_i;
|
57 |
|
|
input [11:0] hBlankOff_i;
|
58 |
|
|
input [11:0] vBlankOn_i;
|
59 |
|
|
input [11:0] vBlankOff_i;
|
60 |
|
|
input [11:0] hBorderOn_i;
|
61 |
|
|
input [11:0] hBorderOff_i;
|
62 |
|
|
input [11:0] vBorderOn_i;
|
63 |
|
|
input [11:0] vBorderOff_i;
|
64 |
|
|
|
65 |
|
|
//---------------------------------------------------------------------
|
66 |
|
|
//---------------------------------------------------------------------
|
67 |
|
|
|
68 |
|
|
reg hBlank1;
|
69 |
|
|
wire vBlank1;
|
70 |
|
|
wire vBorder,hBorder;
|
71 |
|
|
wire hSync1,vSync1;
|
72 |
|
|
reg border;
|
73 |
|
|
|
74 |
|
|
wire eol1 = hCtr==hTotal_i;
|
75 |
|
|
wire eof1 = vCtr==vTotal_i;
|
76 |
|
|
|
77 |
|
|
assign vSync1 = vCtr >= vSyncOn_i && vCtr < vSyncOff_i;
|
78 |
|
|
assign hSync1 = hCtr >= hSyncOn_i && hCtr < hSyncOff_i;
|
79 |
|
|
assign vBlank1 = ~(vCtr < vBlankOn_i && vCtr >= vBlankOff_i);
|
80 |
|
|
assign vBorder = ~(vCtr < vBorderOn_i && vCtr >= vBorderOff_i);
|
81 |
|
|
assign hBorder = ~(hCtr < hBorderOn_i && hCtr >= hBorderOff_i);
|
82 |
|
|
|
83 |
|
|
counter #(12) u1 (.rst(rst), .clk(clk), .ce(1'b1), .ld(eol1), .d(12'd1), .q(hCtr), .tc() );
|
84 |
|
|
counter #(12) u2 (.rst(rst), .clk(clk), .ce(eol1), .ld(eof1), .d(12'd1), .q(vCtr), .tc() );
|
85 |
|
|
|
86 |
|
|
always @(posedge clk)
|
87 |
|
|
if (rst)
|
88 |
|
|
hBlank1 <= 1'b0;
|
89 |
|
|
else begin
|
90 |
|
|
if (hCtr==hBlankOn_i)
|
91 |
|
|
hBlank1 <= 1'b1;
|
92 |
|
|
else if (hCtr==hBlankOff_i)
|
93 |
|
|
hBlank1 <= 1'b0;
|
94 |
|
|
end
|
95 |
|
|
|
96 |
|
|
always @(posedge clk)
|
97 |
|
|
blank <= #1 hBlank1|vBlank1;
|
98 |
|
|
always @(posedge clk)
|
99 |
|
|
vblank <= #1 vBlank1;
|
100 |
|
|
always @(posedge clk)
|
101 |
|
|
border <= #1 hBorder|vBorder;
|
102 |
|
|
always @(posedge clk)
|
103 |
|
|
hSync <= #1 hSync1;
|
104 |
|
|
always @(posedge clk)
|
105 |
|
|
vSync <= #1 vSync1;
|
106 |
|
|
always @(posedge clk)
|
107 |
|
|
eof <= eof1;
|
108 |
|
|
always @(posedge clk)
|
109 |
|
|
eol <= eol1;
|
110 |
|
|
always @(posedge clk)
|
111 |
|
|
vbl_int <= hCtr==12'd8 && vCtr==12'd1;
|
112 |
|
|
|
113 |
|
|
endmodule
|
114 |
|
|
|