FPGA VGA彩条显示实验
此实验的功能是在显示屏上显示红黄蓝三个颜色的色条
VGA 视频图形阵列,一种使用模拟信号进行视频传输的标准。
VGA分为行同步与场同步
行同步与场同步都分为同步脉冲、显示后沿、有效数据段、显示前沿。
本实验选用的VGA为640*480,行有效数据的像素点个数为640个,场有效数据的像素点个数为480个,利用25mhz的时钟进行驱动。
module vga(clk,rst_n,hsync,vsync,rgb);
input clk;
input rst_n;
output hsync;
output vsync;
output [15:0] rgb;
wire vga_clk;
vga_xianshi inst2(vga_clk,rst_n,rgb,hsync,vsync);
fenpin inst1(clk,rst_n,vga_clk);
endmodule
module fenpin(clk,rst_n,vga_clk);
input clk,rst_n;
output reg vga_clk;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
vga_clk<=0;
else
vga_clk<=~vga_clk;
end
endmodule
module vga_xianshi(vga_clk,rst_n,rgb,hsync,vsync);
input vga_clk;
input rst_n;
output reg [15:0] rgb;
output reg hsync;
output reg vsync;
//分辨率640*480
//行显示数据
parameter h_sync=10’d96; //行同步
parameter h_back=10’d48; //行显示后沿
parameter h_disp=10’d640; //行有效数据
parameter h_front=10’d16; //行显示前沿
parameter h_total=10’d800; //行扫描周期
//场显示数据
parameter v_sync=10’d2; //场同步
parameter v_back=10’d33; //场显示后沿
parameter v_disp=10’d480; //场有效数据
parameter v_front=10’d10; //场显示前沿
parameter v_total=10’d525; //场扫描周期
wire vga_en; //vga有效信号
//行、场计数
reg [9:0] cnt_h; //行计数
reg [9:0] cnt_v; //场计数
//行计数
always @(posedge vga_clk or negedge rst_n)
begin
if(!rst_n)
cnt_h<=0;
else
begin
if(cnt_h==h_total-1)
cnt_h<=0;
else
cnt_h<=cnt_h+1;
end
end
//场计数
always @(posedge vga_clk or negedge rst_n)
begin
if(!rst_n)
cnt_v<=0;
else
begin
if(cnt_hh_total-1)
if(cnt_vv_total-1)
cnt_v<=0;
else
cnt_v<=cnt_v+1;
else
cnt_v<=cnt_v;
end
end
//行同步信号
always @(posedge vga_clk or negedge rst_n)
begin
if(!rst_n)
hsync<=0;
else
begin
if(cnt_h>=0&&cnt_h<=95)
hsync<=1;
else
hsync<=0;
end
end
//场同步信号
always @(posedge vga_clk or negedge rst_n)
begin
if(!rst_n)
vsync<=0;
else
begin
if(cnt_v>=0&&cnt_v<=1)
vsync<=1;
else
vsync<=0;
end
end
//使能信号
assign vga_en=(cnt_v>=3&&cnt_v<=15&&cnt_h>=144&&cnt_h<=784)?1:0;
//显示红黄蓝
always @(posedge vga_clk or negedge rst_n)
begin
if(!rst_n)
rgb<=0;
else
begin
if(vga_en)
begin
if(cnt_h>=144&&cnt_h<h_disp/51+144)
rgb<=16’b11111_111111_11111;
else if(cnt_h>=h_disp/51+144&&cnt_h<h_disp/52+144)
rgb<=16’b00000_000000_00000;
else if(cnt_h>=h_disp/52+144&&cnt_h<h_disp/53+144)
rgb<=16’b11111_000000_11111;
else if(cnt_h>=h_disp/53+144&&cnt_h<h_disp/5*4+144)
rgb<=16’b00000_111111_00000;
else
rgb<=16’b00000_000000_11111;
end
else
rgb<=0;
end
end
endmodule