zoukankan      html  css  js  c++  java
  • VGA实验:点亮屏幕

    要在屏幕上随意显示自己想要的东西,首先要做的是要点亮屏幕。这个实验的显示标准是640*480@60Hz,VGA控制模块的时钟频率为25MHz,实验主要包括三个模块:同步模块,VGA控制模块,PLL模块。本实验是基于DE2开发板,器件型号是:cyclone II   ep2c35f672c6。这款器件的内部时钟是50MHz,所以需要一个PLL模块将50MHz分屏为25MHz。同步控制模块是控制显示标准,本实验为640*480,同时还向VGA控制模块提供坐标。VGA控制模块是设计的核心,控制屏幕的色彩。

     1 module sync_module (clk_25m,rst_n,valid,hsync,vsync);
    2 input clk_25m;
    3 input rst_n;
    4 output valid;
    5 output hsync,vsync;
    6
    7 /************************************/
    8
    9
    10 /************************************/
    11
    12 reg [9:0]count_h;
    13
    14 always @ (posedge clk_25m or negedge rst_n)
    15 if (!rst_n)
    16 count_h<=10'd0;
    17 else if (count_h==10'd799)
    18 count_h<=10'd0;
    19 else
    20 count_h<=count_h+1'b1;
    21
    22 /*************************************/
    23
    24
    25 /*************************************/
    26
    27 reg [9:0]count_v;
    28
    29 always @ (posedge clk_25m or negedge rst_n)
    30 if(!rst_n)
    31 count_v<=10'd0;
    32 else if(count_v==10'd524)
    33 count_v<=10'd0;
    34 else if (count_h==10'd799)
    35 count_v<=count_v+1'b1;
    36
    37 /**************************************/
    38
    39
    40 /**************************************/
    41
    42 reg isready;
    43
    44 always @ (posedge clk_25m or negedge rst_n)
    45 if (!rst_n)
    46 isready<=1'b0;
    47 else if ((count_h >=10'd144 && count_h <=10'd784) &&
    48 (count_v >=10'd35 && count_v <=10'd515))
    49 isready <=1'b1;
    50 else
    51 isready <=1'b0;
    52
    53 /****************************************/
    54
    55
    56 /****************************************/
    57 assign valid=isready;
    58 assign hsync= (count_h<10'd96)?1'b0:1'b1;
    59 assign vsync= (count_v<10'd2)?1'b0:1'b1;
    60
    61
    62 /***************************************/
    63
    64 endmodule

    上图为同步模块。

          12行定义了一个列像素计数器count_h,用于对列像素进行计数,每40ns就会累加,从0计数到799,然后转为下一行,又从0开始计数。

          27行定义了一个行计数器count_v,每当count_h计数到799行计数器就会加1.从0计数到524.

          41行定义了一个有效区域标志寄存器,只有在这个区域内才会显示颜色。
          58行表示了hsync的a段,在这段期间,hsync保持低电平,其他段保持高电平。

          59行表示了vsync的0段,在这段期间vsync保持低电平,其他段为高电平。

     1 module vga_control (clk_25m,rst_n,vga_r,vga_g,vga_b,valid);
    2 input clk_25m;
    3 input rst_n;
    4 input valid;
    5 output [9:0]vga_r;
    6 output [9:0]vga_g;
    7 output [9:0]vga_b;
    8
    9 /*****************************/
    10
    11
    12 /********************************/
    13
    14 reg [9:0]r;
    15 reg [9:0]g;
    16 reg [9:0]b;
    17
    18 always @ (posedge clk_25m)
    19 if(!valid) begin
    20 r<=10'd0;
    21 g<=10'd0;
    22 b<=10'd0;
    23 end
    24 else begin
    25 r<=10'h3ff;
    26 g<=10'h3ff;
    27 b<=10'h3ff;
    28 end
    29
    30 /********************************/
    31
    32
    33 /********************************/
    34 assign vga_r=r;
    35 assign vga_b=b;
    36 assign vga_g=g;
    37
    38 endmodule
    39
    40
    41
    42
    43
    44
    45
    46

    以上代码为VGA控制模块。

    14-16行定义了10为的R,G,B。

    18-29行,当进入有效区域,r=10‘h3ff,g=10’h3ff,b=10‘h3ff,即10位的rgb全为1,就可以让屏幕显示白色,点亮屏幕。

     1 module vga_1 (vga_clk,clk,rst_n,hsync,vsync,sync_n,blank_n,vga_r,vga_b,vga_g);
    2 input clk;
    3 input rst_n;
    4 output hsync;
    5 output vsync;
    6 output sync_n;
    7 output blank_n;
    8 output [9:0]vga_r;
    9 output [9:0]vga_g;
    10 output [9:0]vga_b;
    11 output vga_clk;
    12
    13
    14 /****************************/
    15
    16
    17 assign sync_n=1'b0;
    18 assign blank_n=hsync && vsync;
    19
    20 /****************************/
    21
    22 wire vga_clk;
    23
    24 vga_pll U1(
    25 .inclk0(clk),
    26 .c0(vga_clk));
    27
    28 /***************************/
    29
    30
    31
    32 /**************************/
    33
    34
    35 sync_module U2(
    36 .clk_25m(vga_clk),
    37 .rst_n(rst_n),
    38 .valid(valid),
    39 .hsync(hsync),
    40 .vsync(vsync));
    41
    42 /**************************/
    43
    44
    45 /**************************/
    46
    47 vga_control U3(
    48 .clk_25m(vga_clk),
    49 .rst_n(rst_n),
    50 .vga_r(vga_r),
    51 .vga_g(vga_g),
    52 .vga_b(vga_b),
    53 .valid(valid));
    54
    55
    56
    57
    58 /*****************************/
    59
    60
    61 endmodule

    以上代码为整个顶层模块。
    17行为同步信号,这里设为低电平。

    18行为blank信号,定义为行同步与列同步想与。
    24-27行为调用PLL模块,输入为50MHz,输出为25MHz。

  • 相关阅读:
    iOS7 Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2903.2/UIView.m:8536
    mac上launchpad上顽固图标的删除办法
    证书和配置文件
    直接调用对象方法的两种方式
    Instrument使用
    ios第三方库和工具类
    pod 私有 pod 库创建和使用
    iOS 新 app 上架准备
    iOS 上架记录:Other
    ios Permission denied Command PhaseScriptExecution failed with a nonzero exit code
  • 原文地址:https://www.cnblogs.com/tony1224/p/2241368.html
Copyright © 2011-2022 走看看