我根据特权同学的FPGA教程,写了一个VGA的程序。程序下进去后,提示
输入信号超出范围。我的电脑最低分辨率800*600,程序里是640*480.
然后我改了一下,不超出范围了,却提示节点模式。
程序如下:
module VGA(
clk,rst_n, //系统控制
hsync,vsync,
vga_r,vga_g,vga_b //VGA控制
);
input clk; //50M
input rst_n; //低电平复位
//FPGA与VGA接口信号
output hsync; //行同步信号
output vsync; //场同步信号
output[2:0] vga_r;
output[2:0] vga_g;
output[1:0] vga_b;
//坐标计数
reg[10:0] x_cnt; //行坐标
reg[9:0] y_cnt; //列坐标
always @(posedge clk or negedge rst_n)
if(!rst_n) x_cnt <= 10'd0;
else if(x_cnt == 10'd1039) x_cnt <= 10'd0;
else x_cnt <= x_cnt+1'b1;
always @(posedge clk or negedge rst_n)
if(!rst_n) y_cnt <= 10'd0;
else if(y_cnt == 10'd665) y_cnt <= 10'd0;
else if(x_cnt == 10'd1039) y_cnt <= y_cnt+1'b1;
//VGA场同步,行同步信号
reg hsync_r,vsync_r; //同步信号
always @(posedge clk or negedge rst_n)
if(!rst_n) hsync_r <= 1'b1;
else if(x_cnt == 10'd0) hsync_r <= 1'b0; //产生hsync信号
else if(x_cnt == 10'd120) hsync_r <= 1'b1;
always @(posedge clk or negedge rst_n)
if(!rst_n) vsync_r <= 1'b1;
else if(y_cnt == 10'd0) vsync_r <= 1'b0; //产生vsync信号
else if(y_cnt == 10'd6) vsync_r <= 1'b1;
assign hsync =hsync_r;
assign vsync = vsync_r;
//有效显示标志位产生
reg valid_yr; //行显示有效信号
always @(posedge clk or negedge rst_n)
if(!rst_n) valid_yr <= 1'b0;
else if(y_cnt == 10'd32) valid_yr <= 1'b1;
else if(y_cnt == 10'd632) valid_yr <= 1'b0;
wire valid_y=valid_yr;
reg valid_r;
always @(posedge clk or negedge rst_n)
if(!rst_n) valid_r <= 1'b0;
else if((x_cnt == 10'd187) && valid_y) valid_r <= 1'b1;
else if((x_cnt == 10'd987) && valid_y) valid_r <= 1'b0;
wire valid=valid_r;
wire[9:0] x_dis; //横坐标显示有效区域0-639
wire[9:0] y_dis; //纵坐标显示有效区域0-479
assign x_dis = x_cnt - 10'd187;
assign y_dis = y_cnt - 10'd33;
//VGA色彩信号产生
/*
RGB = 000 黑色 RGB = 100 红色
= 001 蓝色 = 101 紫色
= 010 绿色 = 110 黄色
= 011 青色 = 111 白色
*/
/*
一共640*480个像素点,需要显示256种颜色;
那么每个颜色显示区域为40*30,就正好。
*/
reg[7:0] vga_rgb; //VGA色彩显示寄存器
always @(posedge clk)
if(!valid) vga_rgb <= 8'd0;
else begin
case(x_dis)
10'd0: begin //当x坐标画到0时,让显示色彩数据根据当前的y坐标值重新
if(y_dis >= 10'd0 && y_dis < 10'd30) vga_rgb <= 8'd0;
else if(y_dis >= 10'd30 && y_dis < 10'd60) vga_rgb <= 8'd16;
else if(y_dis >= 10'd60 && y_dis < 10'd90) vga_rgb <= 8'd32;
else if(y_dis >= 10'd90 && y_dis < 10'd120) vga_rgb <= 8'd48;
else if(y_dis >= 10'd120 && y_dis < 10'd150) vga_rgb <= 8'd64;
else if(y_dis >= 10'd150 && y_dis < 10'd180) vga_rgb <= 8'd80;
else if(y_dis >= 10'd180 && y_dis < 10'd210) vga_rgb <= 8'd96;
else if(y_dis >= 10'd210 && y_dis < 10'd240) vga_rgb <= 8'd112;
else if(y_dis >= 10'd240 && y_dis < 10'd270) vga_rgb <= 8'd128;
else if(y_dis >= 10'd270 && y_dis < 10'd300) vga_rgb <= 8'd144;
else if(y_dis >= 10'd300 && y_dis < 10'd330) vga_rgb <= 8'd160;
else if(y_dis >= 10'd330 && y_dis < 10'd360) vga_rgb <= 8'd176;
else if(y_dis >= 10'd360 && y_dis < 10'd390) vga_rgb <= 8'd192;
else if(y_dis >= 10'd390 && y_dis < 10'd420) vga_rgb <= 8'd208;
else if(y_dis >= 10'd420 && y_dis < 10'd450) vga_rgb <= 8'd224;
else if(y_dis >= 10'd450 && y_dis < 10'd480) vga_rgb <= 8'd240;
else if(y_dis >= 10'd480 && y_dis < 10'd510) vga_rgb <= 8'd256;
else if(y_dis >= 10'd510 && y_dis < 10'd540) vga_rgb <= 8'd272;
else if(y_dis >= 10'd540 && y_dis < 10'd570) vga_rgb <= 8'd288;
else vga_rgb <= 8'd304;
end
10'd40,10'd80,10'd120,10'd160,10'd200,10'd240,10'd280,10'd320,10'd360,10'd400,10'd440,10'd480,
10'd520,10'd560,10'd600,10'd640,10'd680,10'd720,10'd760,10'd800: vga_rgb <= vga_rgb + 1'b1;
default:;
endcase
end
assign vga_r = vga_rgb[7:5];
assign vga_g = vga_rgb[4:2];
assign vga_b = vga_rgb[1:0];
endmodule
请高手看看,哪里有问题?谢谢!
|