1. VGA概述
VGA(Video Graphics Array)是IBM在1987年推出的一种视频传输,具有分辨率高、显示速率快、颜色丰富等优点,在彩色显示器领域得到了广泛的应用。不支持热插拔,不支持音频传输。
2. VGA时序
下面以640*480@60Hz为例说明VGA时序和FPGA设计,其他分辨率和帧率的可参考VESA中查找。
计算像素时钟pclk = 800*525*60 = 25200000,注意这里的HSYNC和VSYNC都是低电平有效,且HSYNC在数据行无效区域也要提供。
3. VGA电路图
电路以ADV7123为例:
4. FPGA逻辑代码
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
|
//------------Video Test---------------
parameter IMG_HDISP =16'd640;
parameter IMG_VDISP = 16'd480;
wire pclk;
assign pclk = clk_25m;
//VIDEO input
reg [15:0] vcnt;
reg [11:0] hcnt;
reg vsync;
reg hsync;
reg [7:0] data;
reg data_valid;
always @(posedge pclk)
if
(hcnt>=(IMG_HDISP+159))
hcnt <= 0;
else
hcnt <= hcnt + 1'b1;
always @(posedge pclk)
if
(hcnt>=(IMG_HDISP+159))
if
(vcnt>=(IMG_VDISP+44))
vcnt <= 0;
else
vcnt <= vcnt + 1'b1;
else
vcnt <= vcnt;
always @(posedge pclk)
if
((hcnt>=IMG_HDISP+16) & (hcnt<(IMG_HDISP+96)))
// & (vcnt>=0) & (vcnt<(IMG_VDISP)))
hsync <= 1'b1;
else
hsync <= 1'b0;
always @(posedge pclk)
if
(vcnt>=(IMG_VDISP+9) & vcnt<(IMG_VDISP+11))
vsync <= 1'b1;
else
vsync <= 1'b0;
always @(posedge pclk)
if
((hcnt>=0) & (hcnt<(IMG_HDISP)) & (vcnt>=0) & (vcnt<(IMG_VDISP)))
data_valid <= 1'b1;
else
data_valid <= 1'b0;
always @(posedge pclk)
if
(vsync)
data <= 0;
else
if
((hcnt>=0) & (hcnt<(IMG_HDISP)) & (vcnt>=0) & (vcnt<(IMG_VDISP/4)))
// data <= data + 1'b1;
if
(hcnt>=0 & hcnt<(IMG_HDISP/4))
data <= 8'h00;
else
if
(hcnt>=(IMG_HDISP/4) & hcnt<(2*IMG_HDISP/4))
data <= 8'hff;
else
if
(hcnt>=(2*IMG_HDISP/4) & hcnt<(3*IMG_HDISP/4))
data <= 8'h00;
else
data <= 8'hff;
else
if
((hcnt>=0) & (hcnt<(IMG_HDISP)) & (vcnt>=(IMG_VDISP/4)) & (vcnt<(2*IMG_VDISP/4)))
if
(hcnt>=0 & hcnt<(IMG_HDISP/4))
data <= 8'hff;
else
if
(hcnt>=(IMG_HDISP/4) & hcnt<(2*IMG_HDISP/4))
data <= 8'h00;
else
if
(hcnt>=(2*IMG_HDISP/4) & hcnt<(3*IMG_HDISP/4))
data <= 8'hff;
else
data <= 8'h00;
// data <= data + 1'b1;
else
if
((hcnt>=0) & (hcnt<(IMG_HDISP)) & (vcnt>=(2*IMG_VDISP/4)) & (vcnt<(3*IMG_VDISP/4)))
if
(hcnt>=0 & hcnt<(IMG_HDISP/4))
data <= 8'h00;
else
if
(hcnt>=(IMG_HDISP/4) & hcnt<(2*IMG_HDISP/4))
data <= 8'hff;
else
if
(hcnt>=(2*IMG_HDISP/4) & hcnt<(3*IMG_HDISP/4))
data <= 8'h00;
else
data <= 8'hff;
// data <= data + 1'b1;
else
if
((hcnt>=0) & (hcnt<(IMG_HDISP)) & (vcnt>=(3*IMG_VDISP/4)) & (vcnt<(IMG_VDISP)))
// data <= data + 1'b1;
if
(hcnt>=0 & hcnt<(IMG_HDISP/4))
data <= 8'hff;
else
if
(hcnt>=(IMG_HDISP/4) & hcnt<(2*IMG_HDISP/4))
data <= 8'h00;
else
if
(hcnt>=(2*IMG_HDISP/4) & hcnt<(3*IMG_HDISP/4))
data <= 8'hff;
else
data <= 8'h00;
else
data <= 0;
assign lcd_vs = ~vsync;
assign lcd_hs = ~hsync;
assign vga_red = data;
assign vga_green = data;
assign vga_blue = data;
assign lcd_dclk = clk_25m;
assign lcd_blank = 1'b1;
assign lcd_sync = 1'b0;
wire [7:0] vga_red;
wire [7:0] vga_green;
wire [7:0] vga_blue;
assign lcd_red[9:2] = vga_red;
assign lcd_green[9:2] = vga_green;
assign lcd_blue[9:2] = vga_blue;
|
5.演示结果
下图为方格显示效果:
本文转自 shugenyin 51CTO博客,原文链接:http://blog.51cto.com/shugenyin/1841223