This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvga_800x600.v
120 lines (107 loc) · 2.53 KB
/
vga_800x600.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 13:22:23 05/19/2015
// Design Name:
// Module Name: vga_800x600
// Project Name: https://github.com/ThePedestrian/FPGA-Simple-Maze-Game-Using-VGA-Output
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module vga_800x600(input wire clk,
input wire clr,
output reg hsync,
output reg vsync,
output reg [10:0] PixelX,
output reg [10:0] PixelY,
output reg vidon
);
parameter TotalHorizontalPixels = 11'd1040;
parameter HorizontalSyncWidth = 11'd120;
parameter VerticalSyncWidth = 11'd6;
parameter TotalVerticalLines = 11'd666;
parameter HorizontalBackPorchTime = 11'd184 ;
parameter HorizontalFrontPorchTime = 11'd984 ;
parameter VerticalBackPorchTime = 11'd43 ;
parameter VerticalFrontPorchTime = 11'd643;
reg VerticalSyncEnable;
reg [10:0] HorizontalCounter;
reg [10:0] VerticalCounter;
//Counter for the horizontal sync signal
always @(posedge clk)
begin
if(clr == 1)
HorizontalCounter <= 0;
else
begin
if(HorizontalCounter == TotalHorizontalPixels - 1)
begin //the counter has hreached the end of a horizontal line
HorizontalCounter<=0;
VerticalSyncEnable <= 1;
end
else
begin
HorizontalCounter<=HorizontalCounter+1;
VerticalSyncEnable <=0;
end
end
end
//Generate the hsync pulse
//Horizontal Sync is low when HorizontalCounter is 0-127
always @(*)
begin
if((HorizontalCounter<HorizontalSyncWidth))
hsync = 1;
else
hsync = 0;
end
//Counter for the vertical sync
always @(posedge clk)
begin
if(clr == 1)
VerticalCounter<=0;
else
begin
if(VerticalSyncEnable == 1)
begin
if(VerticalCounter==TotalVerticalLines-1)
VerticalCounter<=0;
else
VerticalCounter<=VerticalCounter+1;
end
end
end
//generate the vsync pulse
always @(*)
begin
if(VerticalCounter < VerticalSyncWidth)
vsync = 1;
else
vsync = 0;
end
always @(posedge clk)
begin
if((HorizontalCounter<HorizontalFrontPorchTime) && (HorizontalCounter>HorizontalBackPorchTime) && (VerticalCounter<VerticalFrontPorchTime) && (VerticalCounter>VerticalBackPorchTime))
begin
vidon <= 1;
PixelX<= HorizontalCounter - HorizontalBackPorchTime;
PixelY<= VerticalCounter - VerticalBackPorchTime;
end
else
begin
vidon <= 0;
PixelX<=0;
PixelY<=0;
end
end
endmodule