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 ;
作者: Steady_Chou 时间: 2010-4-12 14:28
感谢分享 ,请问要更改分辨率要改哪些值阿?作者: hdhuang 时间: 2010-4-13 09:17
这个是我转载的一部分,还有时序模块没有加,最近自己尝试写了个很简单的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;作者: hdhuang 时间: 2010-5-12 09:18 本帖最后由 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;作者: 培培 时间: 2010-5-12 14:53
能具体说一下这段程序的功能和达到的目的吗?
还有出来什么样的图呀?作者: hdhuang 时间: 2010-5-24 11:23
这个只是一个时序发生器,如果要加入简单彩条图案的话,还得自己编写计数器类型的规律数据发送器才可以。