-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVGA_driver.v
84 lines (75 loc) · 1.84 KB
/
VGA_driver.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 10/31/2022 05:28:39 PM
// Design Name:
// Module Name: VGA_driver
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module VGA_driver(
input clk_25M,
input [2:0] redIn,
input [2:0] greenIn,
input [1:0] blueIn,
output reg [2:0] vgaRed = 0,
output reg [2:0] vgaGreen = 0,
output reg [2:1] vgaBlue = 0,
output reg Hsync = 0,
output reg Vsync = 0,
output reg [9:0] x_pos = 0,
output reg [9:0] y_pos = 0
);
reg [9:0] h_count = 0;
reg [9:0] v_count = 0;
always @(posedge clk_25M)
begin
// Control counter for h_sync and v_sync control
if (h_count == 799)
begin
h_count <= 0;
if (v_count == 524)
v_count <= 0;
else
v_count <= v_count + 1'b1;
end
else
h_count <= h_count + 1'b1;
// control Hsync signal
if ((h_count >= 0) && (h_count <= 95))
Hsync <= 1;
else
Hsync <= 0;
// control Vsync signal
if ((v_count >= 0) && (v_count <= 1))
Vsync <= 1;
else
Vsync <= 0;
// Set color to black when outside of video bounds and output position
if ((h_count >= 144) && (h_count <= 783) && (v_count >= 35) && (v_count <= 514))
begin
vgaRed <= redIn;
vgaGreen <= greenIn;
vgaBlue <= blueIn;
end
else
begin
vgaRed <= 0;
vgaGreen <= 0;
vgaBlue <= 0;
end
x_pos <= (h_count + 1'b1) - 9'd144; // X position being output is the next position. Will be between 0 and 639 for valid inputs
y_pos <= v_count - 9'd35; // Y position is current position. Between 0 and 479 for valid inputs
end
endmodule