• [笔记]DE2115 VGA Color Pattern Generator


    1 module vga_controler(
    2 input CLOCK_50,
    3 input[3:0] KEY,
    4 output VGA_CLK, //should be 25MHz
    5  output[7:0] VGA_R,
    6 output[7:0] VGA_G,
    7 output[7:0] VGA_B,
    8 output VGA_BLANK_N,
    9 output VGA_SYNC_N,
    10 output VGA_HS,
    11 output VGA_VS
    12 );
    13 reg[9:0] H_Cont; //行扫描计数器
    14  reg[9:0] V_Cont; //列扫描计数器
    15 reg[7:0] vga_r;
    16 reg[7:0] vga_g;
    17 reg[7:0] vga_b;
    18 reg vga_hs;
    19 reg vga_vs;
    20 reg[10:0] X;
    21 reg[10:0] Y;
    22 assign VGA_R=vga_r;
    23 assign VGA_G=vga_g;
    24 assign VGA_B=vga_b;
    25 assign VGA_HS=vga_hs;
    26 assign VGA_VS=vga_vs;
    27
    28 //Horizontal Parameter
    29 parameter H_FRONT=16;
    30 parameter H_SYNC=96;
    31 parameter H_BACK=48;
    32 parameter H_ACT=640;
    33 parameter H_BLANK=H_FRONT+H_SYNC+H_BACK;
    34 parameter H_TOTAL=H_FRONT+H_SYNC+H_BACK+H_ACT;
    35 //Vertical Parameter
    36 parameter V_FRONT=11;
    37 parameter V_SYNC=2;
    38 parameter V_BACK=32;
    39 parameter V_ACT=480;
    40 parameter V_BLANK=V_FRONT+V_SYNC+V_BACK;
    41 parameter V_TOTAL=V_FRONT+V_SYNC+V_BACK+V_ACT;
    42
    43
    44
    45 wire CLK_25;
    46 wire RST_N;
    47 wire clk;
    48
    49 // Generator DAC_CLOCK 25MHz
    50 pll pll_inst (
    51 .inclk0 ( CLOCK_50 ),
    52 .c0 ( CLK_25 )
    53 );
    54 //Select DAC CLOCK
    55 assign VGA_CLK=CLK_25;
    56 assign VGA_SYNC_N=1'b0; //If not SOG, Sync input should be tied to 0;
    57 assign VGA_BLANK_N=~((H_Cont<H_BLANK)||(V_Cont<V_BLANK));
    58 assign RST_N=KEY[0];
    59
    60 //Horizontal Generator:Refer to the pixel clock
    61 always@(posedge CLK_25, negedge RST_N)begin
    62 if(!RST_N)begin
    63 H_Cont<=0;
    64 vga_hs<=1;
    65 X<=0;
    66 end
    67 else begin
    68 if(H_Cont<H_TOTAL)
    69 H_Cont<=H_Cont+1'b1;
    70 else
    71 H_Cont<=0;
    72
    73 //horizontal Sync
    74 if(H_Cont==H_FRONT-1) //Front porch end
    75 vga_hs<=1'b0;
    76 if(H_Cont==H_FRONT+H_SYNC-1)
    77 vga_hs<=1'b1;
    78 //Current X
    79 if(H_Cont>=H_BLANK)
    80 X<=H_Cont-H_BLANK;
    81 else
    82 X<=0;
    83 end
    84 end
    85 //vertical Generator: Refer to the horizontal sync
    86 always@(posedge VGA_HS, negedge RST_N)begin
    87 if(!RST_N)begin
    88 V_Cont<=0;
    89 vga_vs<=1;
    90 Y<=0;
    91 end
    92 else begin
    93 if(V_Cont<V_TOTAL)
    94 V_Cont<=V_Cont+1'b1;
    95 else
    96 V_Cont<=0;
    97 //Vertical Sync
    98 if(V_Cont==V_FRONT-1)
    99 vga_vs<=1'b0;
    100 if(V_Cont==V_FRONT+V_SYNC-1)
    101 vga_vs<=1'b1;
    102 //Current Y
    103 if(V_Cont>=V_BLANK)
    104 Y<=V_Cont-V_BLANK;
    105 else
    106 Y<=0;
    107 end
    108 end
    109
    110 //Pattern Generator
    111 always@(posedge CLK_25, negedge RST_N)begin
    112 if(!RST_N)begin
    113 vga_r<=0;
    114 vga_g<=0;
    115 vga_b<=0;
    116 end
    117 else begin
    118 vga_r <= (Y < 120) ? 256 :
    119 (Y >= 120 && Y < 240) ? 512 :
    120 (Y >= 240 && Y < 360) ? 768 :
    121 1023;
    122
    123 vga_g <= (X < 80) ? 128 :
    124 (X >= 80 && X < 160) ? 256 :
    125 (X >= 160 && X < 240) ? 384 :
    126 (X >= 240 && X < 320) ? 512 :
    127 (X >= 320 && X < 400) ? 640 :
    128 (X >= 400 && X < 480) ? 768 :
    129 (X >= 480 && X < 560) ? 896 :
    130 1023;
    131
    132 vga_b <= (Y < 60) ? 1023:
    133 (Y >= 60 && Y < 120) ? 896 :
    134 (Y >= 120 && Y < 180) ? 768 :
    135 (Y >= 180 && Y < 240) ? 640 :
    136 (Y >= 240 && Y < 300) ? 512 :
    137 (Y >= 300 && Y < 360) ? 384 :
    138 (Y >= 360 && Y < 420) ? 256 :
    139 128;
    140 end
    141 end
    142 endmodule

    本例参考http://www.cnblogs.com/oomusou/archive/2008/11/16/vga_color_pattern_generator.html

  • 相关阅读:
    重新温习软件设计之路(4)
    重新温习软件设计之路(3)
    技术判断力
    GIS基本函数类库Delphi代码
    C#文本转语音并保存wav和MP3文件
    多网卡多网关浏览器访问外网
    自信与乐观
    System.Security.SecurityException when writing to Event Log
    4010 An unhandled security exception has occurred. IIS 8.5
    How to make a grid (like graph paper grid) with just css?
  • 原文地址:https://www.cnblogs.com/spartan/p/2038167.html
Copyright © 2020-2023  润新知