-
Notifications
You must be signed in to change notification settings - Fork 0
/
vga.v
143 lines (122 loc) · 3.06 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
137
138
139
140
141
142
143
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 11:22:30 10/14/2011
// Design Name:
// Module Name: vga
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
`define PAL 640 //--Pixels/Active Line (pixels)
`define LAF 480 //--Lines/Active Frame (lines)
`define PLD 800 //--Pixel/Line Divider
`define LFD 521 //--Line/Frame Divider
`define HPW 96 //--Horizontal synchro Pulse Width (pixels)
`define HFP 16 //--Horizontal synchro Front Porch (pixels)
//`define HBP 48 --Horizontal synchro Back Porch (pixels)
`define VPW 2 //--Vertical synchro Pulse Width (lines)
`define VFP 10
`define PRV 50
`define PRH 200
`define PRVF 306
`define PRHF 456
`define INITIAL 0
//--Vertical synchro Front Porch (lines)
//`define VBP 29 //--Vertical synchro Back Porch (lines)
module vga(ck, Hcnt, Vcnt, HS, VS, outRed, outGreen, outBlue);
input ck;
output reg HS, VS;
output reg [2:0] outRed, outGreen;
output reg [1:0] outBlue;
//reg INITIAL;
output reg [9:0] Hcnt, Vcnt;
reg ck25MHz;
// -- divide 50MHz clock to 25MHz
always @ (posedge ck)
ck25MHz<= ~ck25MHz;
always @ (posedge ck25MHz) begin
if (Hcnt == `PLD-1) begin
Hcnt<= 10'h0;
if (Vcnt == `LFD-1)
Vcnt <= 10'h0;
else
Vcnt <= Vcnt + 10'h1;
end
else
Hcnt<= Hcnt +10'h1;
end
//-- Generates HS - active low
always @(posedge ck25MHz) begin
if (Hcnt == `PAL-1 +`HFP)
HS<=1'b0;
else if (Hcnt == `PAL-1+`HFP+`HPW)
HS<=1'b1;
end
//-- Generates VS - active low
always @(posedge ck25MHz) begin
if (Vcnt ==`LAF-1+`VFP)
VS <= 1'b0;
else if (Vcnt== `LAF-1+`VFP+`VPW)
VS <= 1'b1;
end
reg [0:0] cycle;
reg [1:0] btur;
reg [1:0] tur;
reg [14:0] addra;
wire [7:0] douta;
always @ (posedge ck25MHz) begin
if ((Hcnt <`PAL) && (Vcnt < `LAF)) begin
if((Hcnt==`INITIAL) &&(Vcnt==`INITIAL))begin
addra<=15'b00000000000000;
outRed<=3'b000;
outGreen<=3'b00;
outBlue<=2'b00;
tur <= 0;
cycle <= 0;
end
else if((Hcnt>= 100 && Hcnt<=355) && (Vcnt>=100 && Vcnt<=355))begin
if(tur==0 && Hcnt==355)begin
addra<=addra-128;
tur<=1;
end
else if(tur==1 && Hcnt==355) begin
tur<=0;
end
else if(cycle == 1'b1) begin
addra<=addra+14'b00000000000001;
end
cycle <= cycle + 1'b1;
outRed<=douta[7:5];
outGreen<=douta[4:2];
outBlue<=douta[1:0];
end
else begin
addra<=addra;
outRed<=3'b000;
outGreen<=3'b00;
outBlue<=2'b00;
end
end
else begin
outRed <= 3'b000;
outGreen <= 3'b000;
outBlue <= 2'b00;
end
end
frameBuffer inst_parrot (
.clka(ck25MHz), // input clka
.addra(addra), // input [14 : 0] addra
.douta(douta) // output [7 : 0] douta
);
endmodule