原创 基于DE1的VGA(4K色彩)测试

2011-3-22 19:00 2400 11 11 分类: FPGA/CPLD

这个测试工程是用的50Mhz的输入脉冲,800*600的分辨率,刷新率为72hz,与上次的8bit测试工程类型。这里因为DE1的RGB是各4位的,共有12bit,即共有4096种色彩。我这里就把800*600分成了4096块,因为800*600/4096=117(约为),即每约117个像素点作为一块,又117=13*9,即变成长为13,宽为9的长方形。电脑屏幕长为800,宽为600,可以把800分成月14份,其中13份为61,1份为7.同理,可以把宽600分成67份,其中有66个为9,1个为6.

接口如图:

其vga时序图如下:

VgaHs:     行控制信号

VgaVs:    场同步信号

RgbRi:    red信号

RgbGi:    green信号

RgbBi:     blank信号

hcount:   行脉冲计数

vcount:   列脉冲计数

其代码如下:

module Vga12BitTest (

        Clk50Mhz,RstN,VgaHs,VgaVs,

        RgbR,RgbG,RgbB

        );                  //the defination of the VGA_8 module

       

input Clk50Mhz,RstN;

output VgaHs,VgaVs;

output[3:0] RgbR,RgbG,RgbB;

reg[10:0] hcount;

reg[9:0]vcount;

//reg VgaHs,VgaVs;

reg VgaHs_r,VgaVs_r;   //í?2?D?o?2úéú

 

wire valid;

wire[10:0] x_point,y_point;

 

always@(posedge Clk50Mhz or negedge RstN)      //x count

begin

    if(!RstN)hcount<=11'd0;

    else if(hcount==1040)hcount<=11'd0;

    else  hcount<=hcount+1;

end

 

always@(posedge Clk50Mhz or negedge RstN)      //y count

begin

    if(!RstN)vcount<=11'd0;

    else if(vcount==666)vcount<=10'd0;

    else if(hcount==1040) vcount<=vcount+1;

end

 

always@(posedge Clk50Mhz or negedge RstN)      //generate the signal VgaHs

begin

    if(!RstN)VgaHs_r<=1'd1;

    else if(hcount==0)VgaHs_r<=1'd0;

    else if(hcount==120)VgaHs_r<=1'd1;

end

 

always@(posedge Clk50Mhz or negedge RstN)      //generate the signal VgaVs

begin

    if(!RstN)VgaVs_r<=1'd1;

    else if(vcount==0)VgaVs_r<=1'd0;

    else if(vcount==6)VgaVs_r<=1'd1;

end

 

assign VgaVs=VgaVs_r;

assign VgaHs=VgaHs_r;

 

assign valid=(hcount>=11'd176)&&(hcount<=11'd976)&&(vcount>=10'd43)&&(vcount<=10'd643);   //the valid display area

assign x_point=hcount-11'd176;                                         //the real x point

assign y_point=vcount-10'd43;

   

reg[11:0] VgaRgb;

always@(posedge Clk50Mhz or negedge RstN)      //generate the signal VgaHs

if(!RstN)VgaRgb<=12'd0;

else if(valid)              //only when the display aera is valid,we can change the vga value

    case(x_point)             //every rectange has the same pixel

        12'd0:  begin         //make sure every line has a different pixel value,and every rectange has the width of 9

                   if(y_point>=0&&y_point<9)VgaRgb<=12'd0;

                   else if(y_point>=9&&y_point<18)VgaRgb<=12'd62;

                   else if(y_point>=18&&y_point<27)VgaRgb<=12'd124;

                   else if(y_point>=27&&y_point<36)VgaRgb<=12'd186;

                   else if(y_point>=36&&y_point<45)VgaRgb<=12'd248;

                   else if(y_point>=45&&y_point<54)VgaRgb<=12'd310;

                   else if(y_point>=54&&y_point<63)VgaRgb<=12'd372;

                   else if(y_point>=63&&y_point<72)VgaRgb<=12'd434;

                   else if(y_point>=72&&y_point<81)VgaRgb<=12'd496;

                   else if(y_point>=81&&y_point<90)VgaRgb<=12'd558;

                   else if(y_point>=90&&y_point<99)VgaRgb<=12'd620;

                   else if(y_point>=99&&y_point<108)VgaRgb<=12'd682;

                   else if(y_point>=108&&y_point<117)VgaRgb<=12'd744;

                   else if(y_point>=117&&y_point<126)VgaRgb<=12'd806;

                   else if(y_point>=126&&y_point<135)VgaRgb<=12'd868;

                   else if(y_point>=135&&y_point<144)VgaRgb<=12'd930;

                   else if(y_point>=144&&y_point<153)VgaRgb<=12'd992;

                   else if(y_point>=153&&y_point<162)VgaRgb<=12'd1054;

                   else if(y_point>=162&&y_point<171)VgaRgb<=12'd1116;

                   else if(y_point>=171&&y_point<180)VgaRgb<=12'd1178;

                   else if(y_point>=180&&y_point<189)VgaRgb<=12'd1240;

                   else if(y_point>=189&&y_point<198)VgaRgb<=12'd1302;

                   else if(y_point>=198&&y_point<207)VgaRgb<=12'd1364;

                   else if(y_point>=207&&y_point<216)VgaRgb<=12'd1426;

                   else if(y_point>=216&&y_point<225)VgaRgb<=12'd1488;

                   else if(y_point>=225&&y_point<234)VgaRgb<=12'd1550;

                   else if(y_point>=234&&y_point<243)VgaRgb<=12'd1612;

                   else if(y_point>=243&&y_point<252)VgaRgb<=12'd1674;

                   else if(y_point>=252&&y_point<261)VgaRgb<=12'd1763;

                   else if(y_point>=261&&y_point<270)VgaRgb<=12'd1798;

                   else if(y_point>=270&&y_point<279)VgaRgb<=12'd1860;

                   else if(y_point>=279&&y_point<288)VgaRgb<=12'd1992;

                   else if(y_point>=288&&y_point<297)VgaRgb<=12'd1984;

                   else if(y_point>=297&&y_point<306)VgaRgb<=12'd2046;

                   else if(y_point>=306&&y_point<315)VgaRgb<=12'd2108;

                   else if(y_point>=315&&y_point<324)VgaRgb<=12'd2170;

                   else if(y_point>=324&&y_point<333)VgaRgb<=12'd2232;

                   else if(y_point>=333&&y_point<342)VgaRgb<=12'd2294;

                   else if(y_point>=342&&y_point<351)VgaRgb<=12'd2356;

                   else if(y_point>=351&&y_point<360)VgaRgb<=12'd2418;

                   else if(y_point>=360&&y_point<369)VgaRgb<=12'd2480;

                   else if(y_point>=369&&y_point<378)VgaRgb<=12'd2542;

                   else if(y_point>=378&&y_point<387)VgaRgb<=12'd2604;

                   else if(y_point>=387&&y_point<396)VgaRgb<=12'd2666;

                   else if(y_point>=396&&y_point<405)VgaRgb<=12'd2728;

                   else if(y_point>=405&&y_point<414)VgaRgb<=12'd2790;

                   else if(y_point>=414&&y_point<423)VgaRgb<=12'd2852;

                   else if(y_point>=423&&y_point<432)VgaRgb<=12'd2914;

                   else if(y_point>=432&&y_point<441)VgaRgb<=12'd2976;

                   else if(y_point>=441&&y_point<450)VgaRgb<=12'd3038;

                   else if(y_point>=450&&y_point<459)VgaRgb<=12'd3100;

                   else if(y_point>=459&&y_point<468)VgaRgb<=12'd3162;

                   else if(y_point>=468&&y_point<477)VgaRgb<=12'd3224;

                   else if(y_point>=477&&y_point<486)VgaRgb<=12'd3286;

                   else if(y_point>=486&&y_point<495)VgaRgb<=12'd3348;

                   else if(y_point>=495&&y_point<504)VgaRgb<=12'd3410;

                   else if(y_point>=504&&y_point<513)VgaRgb<=12'd3472;

                   else if(y_point>=513&&y_point<522)VgaRgb<=12'd3534;

                   else if(y_point>=522&&y_point<531)VgaRgb<=12'd3596;

                   else if(y_point>=531&&y_point<540)VgaRgb<=12'd3658;

                   else if(y_point>=540&&y_point<549)VgaRgb<=12'd3720;

                   else if(y_point>=549&&y_point<558)VgaRgb<=12'd3782;

                   else if(y_point>=558&&y_point<567)VgaRgb<=12'd3844;

                   else if(y_point>=567&&y_point<576)VgaRgb<=12'd3906;

                   else if(y_point>=576&&y_point<585)VgaRgb<=12'd3968;

                   else if(y_point>=585&&y_point<594)VgaRgb<=12'd4030;

                   else if(y_point>=594&&y_point<=599)VgaRgb<=12'd4092;             

                end

            12'd13,12'd26,12'd39,12'd52,12'd65,12'd78,12'd91,12'd104,12'd117,12'd130,12'd143,12'd156,

            12'd169,12'd182,12'd195,12'd208,12'd221,12'd234,12'd247,12'd260,12'd273,12'd286,12'd299,

            12'd312,12'd325,12'd338,12'd351,12'd364,12'd377,12'd390,12'd403,12'd416,12'd429,12'd442,

            12'd455,12'd468,12'd481,12'd494,12'd507,12'd520,12'd533,12'd546,12'd559,12'd572,12'd585,

            12'd598,12'd611,12'd624,12'd637,12'd650,12'd663,12'd676,12'd689,12'd702,12'd715,12'd728,

                12'd741,12'd754,12'd767,12'd780,12'd793,12'd799:VgaRgb<=VgaRgb+12'd1;   //every rectange has the long of 13;

                                                                                      //the adjoing of every rectange's pixel value differ 1   

                default:;

    endcase

    else VgaRgb<=12'd0;

assign  RgbR=VgaRgb[11:8];  //give the value  of rgb

assign  RgbG=VgaRgb[7:4];

assign  RgbB=VgaRgb[3:0];

 

endmodule

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
11
关闭 站长推荐上一条 /3 下一条