MyFPGA Forum

 找回密码
 注册
搜索
查看: 6917|回复: 5
打印 上一主题 下一主题

VGA简单控制器(ZZ)

[复制链接]
跳转到指定楼层
1#
发表于 2010-3-24 20:37:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1、    输入信号
   clk : 时钟(每个象素点的显示时钟)
   reset : 复位信号
2、    输出信号
    vga_hs_control                   :      行同步   
        vga_vs_control                   :      场同步 ;

        vga_read_dispaly               :      红
        vga_green_dispaly              :      绿
        vga_blue_dispaly       :   蓝
3、    技术参数
clk : 24M   hs : 30KHZ   vs : 57.14HZ



   设计原理
VGA( 视频图形阵列 ) 作为一种标准的显示接口得到广泛的应用 , 一般有专用芯片,本实验采用 FPGA( 现场可编程门阵列 ) 设计 VGA 接口可以将要显示的数据直接送到显示器,节省了计算机的处理过程,加快了数据的处理速度,节约了硬件成本。
显示适配器有多种形式,它可按照所符合的视频显示标准来分类,业界制定了多种显示标准,从最初的 MDA 经历了 CGA , EGA , VGA , XGA,SVGA 等的发展过程。与相应的显示适配器标准相配的显示器也称之为 EGA , VGA , XGA 显示器等。实际上显示器的标准主要反映在它们的接口,显示功能和行,场工作频率上。

  

CRT 显示器的扫描方式
(1)    当栅扫描方式 从上向下依次顺序扫描
完一场称逐行扫描。一行用行频控制( hs ) ,

一场用场频控制( vs )。扫完一行回来叫行消
隐,扫完一场回来叫场消隐
(2)    随机扫描方式
  

VGA 接口标准
时钟频率: 25 . 175 MHz( 像素输出的频率 ) ;行频: 31. 469 Hz ;场频: 59 . 94 Hz 。
  

设计 VGA

设计 VGA 图像显示控制需要注意两个问题 L2] :一个是时序的驱动,这是完成设计的关键,时序稍有偏差,显示必然不正常,甚至会损坏彩色显示器;另一个是 VGA 信号的电平驱动。显示控制器设计提示:显示器技术规格提供的行频一般在 30 kHz 45 kHz( 保守数据 ) ,场频一般在 50 Hz ~ 75 Hz( 保守数据 ) 。针对以上保守数据,设计分辨率为 640x480 的显示接口(如图 4 所示),以 30 kHz 的行频进行扫描时所需时钟频率为: 30 kHz × 800( 行周期 )=24 MHz ,则场频为: 30 kHz ÷ 525( 场周期 )=5.14 Hz 。本实验实现在显示器上显示彩条的设计,初始时时 GRB= “ 000 ”,用一记数器过一段时间使 R 取反,即变为红色。这样就有黑、红彩条了。



library ieee;
use ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity vga is
port(
  reset     : in std_logic;
  clk      : in  std_logic;
  vga_hs_control   : out std_logic;
  vga_vs_control   : out std_logic;
  vga_read_dispaly   : out std_logic;
  vga_green_dispaly  : out std_logic;
  vga_blue_dispaly  : out std_logic  
);
end vga;
ARCHITECTURE a OF vga IS
SIGNAL hs: STD_LOGIC;
SIGNAL vs: STD_LOGIC:='1';
    SIGNAL GRB: STD_LOGIC_VECTOR(2 DOWNTO 0);
BEGIN
PROCESS (clk) --clk = 24MHZ  hs = 30 Khz vs = 57hz
VARIABLE i : integer range 0 to 799:=0;
VARIABLE j : integer range 0 to 79:=0;
BEGIN
if reset = '1' then
   GRB <= "000"; i:=96; j:=0;  hs <= '1';
elsif clk'event and clk = '1'  then
   if i < 96 then
      hs <= '0';
   elsif i = 799 then
      i:=0;
   else
      hs <= '1';
   end if;
   if j = 79 then
      GRB(1) <= not GRB(1);
      j:=0;
   end if;
   i:=i+1;
   j:=j+1;     
end if;
vga_hs_control <= hs;
END PROCESS ;
PROCESS (hs)
VARIABLE k : integer range 0 to 524:=0;
BEGIN
if reset = '1' then
   k:=2; vs <= '1';
elsif hs'event and hs = '1' then
     if k < 2 then
        vs <= '0';
     elsif k = 524 then
        k:=0;
     else
        vs <= '1';
     end if;
     k:=k+1;
   end if;
  vga_vs_control <= vs;
END PROCESS ;
2#
发表于 2010-4-12 14:28:47 | 只看该作者
感谢分享 ,请问要更改分辨率要改哪些值阿?
3#
 楼主| 发表于 2010-4-13 09:17:22 | 只看该作者
这个是我转载的一部分,还有时序模块没有加,最近自己尝试写了个很简单的TFT LCD时序模块,可以通过更改常数的方式适应不同的LCD,不过nclk也需要做相应调整才是(用PLL生成):
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity LTM is
   port(nclk : in  std_logic;
        reset: in  std_logic;
        DEN  : out std_logic;
        HD   : out std_logic;
        VD   : out std_logic);
end entity;

architecture behav of LTM is
constant hori_line :integer :=1056;
constant hori_back :integer :=216;
constant hori_front:integer :=40;
constant vert_line :integer :=525;
constant vert_back :integer :=45;
constant vert_front:integer :=10;
signal h_cnt :std_logic_vector(10 downto 0);
signal v_cnt :std_logic_vector(9 downto 0);
signal hori_valid,vert_valid,cHD,cVD,cDEN :std_logic;



begin
-- synchronous signal generate
process(nclk,reset)
begin
  if reset='1' then
     h_cnt<=(others=>'0');
     v_cnt<=(others=>'0');
  elsif falling_edge(nclk) then
     if conv_integer(h_cnt)=hori_line-1 then
        h_cnt<=(others=>'0');
        if conv_integer(v_cnt)=vert_line-1 then
           v_cnt<=(others=>'0');
        else
           v_cnt<=v_cnt+1;
        end if;
     else
        h_cnt<=h_cnt+1;
     end if;
  end if;
end process;
cHD<= '0' when conv_integer(h_cnt)=0 else
     '1';
cVD<= '0' when conv_integer(v_cnt)=0 else
     '1';
--
hori_valid<= '1' when (conv_integer(h_cnt)<=(hori_line-hori_front) and conv_integer(h_cnt)>=hori_back) else
             '0';
vert_valid<= '1' when (conv_integer(v_cnt)<=(vert_line-vert_front) and conv_integer(v_cnt)>=vert_back) else
             '0';
-----
cDEN<=hori_valid and vert_valid;
---
process
begin
  wait until nclk='0';
  HD<=cHD;
  VD<=cVD;
  DEN<=cDEN;
end process;
---
end behav;
4#
 楼主| 发表于 2010-5-12 09:18:29 | 只看该作者
本帖最后由 hdhuang 于 2010-5-12 09:21 编辑

实在有些不好意思,这两天调试,发现上述模块DEN信号每一行都多了一个脉冲,是左边取了等号的缘故,上次在TFT上没有用图形验证,没有发现。再发个在VGA上验证通过的:
--------------------------------------------------------------------------------
--
--VGA Timing
--Horizontal :
--                               ______________                               _____________
--                              |                           |                              |
--_______________|  VIDEO               |_______________|  VIDEO (next line)

--___________   _____________________   ______________________
--                     |_|                                        |_|
--                      B <-C-><----D------><--E-->
--                     <------------A------------------>
--The Unit used below are pixels;  
--  B->Sync_cycle                   :H_sync_cycle
--  C->Back_porch                   :hori_back
--  D->Visable Area
--  E->Front porch                  :hori_front
--  A->horizontal line total length :hori_line
--Vertical :
--                             ______________                               _____________
--                            |                           |                              |         
--______________|  VIDEO               |_______________|  VIDEO (next frame)
--
--__________   _____________________   ______________________
--                   |_|                                         |_|
--                   P <-Q-><-----R------><--S-->
--                  <----------------O----------- --->
--The Unit used below are horizontal lines;  
--  P->Sync_cycle                   :V_sync_cycle
--  Q->Back_porch                   :vert_back
--  R->Visable Area
--  S->Front porch                  :vert_front
--  O->horizontal line total length :vert_line


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity LTM is
   port(nclk : in  std_logic;
        reset: in  std_logic;
        DEN  : out std_logic;
        HD   : out std_logic;
        VD   : out std_logic);
end entity;

architecture behav of LTM is
constant hori_line :integer :=1056;
constant hori_back :integer :=216;
constant hori_front:integer :=40;
constant vert_line :integer :=525;
constant vert_back :integer :=35;
constant vert_front:integer :=10;
constant H_sync_cycle :integer :=96;
constant V_sync_cycle :integer :=2;
signal h_cnt :std_logic_vector(10 downto 0);
signal v_cnt :std_logic_vector(9 downto 0);
signal hori_valid,vert_valid,cHD,cVD,cDEN :std_logic;



begin
-- synchronous signal generate
process(nclk,reset)
begin
  if reset='1' then
     h_cnt<=(others=>'0');
     v_cnt<=(others=>'0');
  elsif falling_edge(nclk) then
     if conv_integer(h_cnt)=hori_line-1 then
        h_cnt<=(others=>'0');
        if conv_integer(v_cnt)=vert_line-1 then
           v_cnt<=(others=>'0');
        else
           v_cnt<=v_cnt+1;
        end if;
     else
        h_cnt<=h_cnt+1;
     end if;
  end if;
end process;
cHD<= '0' when conv_integer(h_cnt)<H_sync_cycle else
     '1';
cVD<= '0' when conv_integer(v_cnt)=V_sync_cycle else
     '1';
--
hori_valid<= '1' when (conv_integer(h_cnt)<(hori_line-hori_front) and conv_integer(h_cnt)>=hori_back) else
             '0';
vert_valid<= '1' when (conv_integer(v_cnt)<(vert_line-vert_front) and conv_integer(v_cnt)>=vert_back) else
             '0';
-----
cDEN<=hori_valid and vert_valid;
---
process
begin
  wait until nclk='0';
  HD<=cHD;
  VD<=cVD;
  DEN<=cDEN;
end process;
---
end behav;
5#
发表于 2010-5-12 14:53:13 | 只看该作者
能具体说一下这段程序的功能和达到的目的吗?
还有出来什么样的图呀?
6#
 楼主| 发表于 2010-5-24 11:23:45 | 只看该作者
这个只是一个时序发生器,如果要加入简单彩条图案的话,还得自己编写计数器类型的规律数据发送器才可以。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|MyFPGA

GMT+8, 2024-5-3 17:24 , Processed in 0.048714 second(s), 17 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表