1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 |
|
4 | -- Uncomment the following library declaration if using
|
5 | -- arithmetic functions with Signed or Unsigned values
|
6 | use IEEE.NUMERIC_STD.ALL;
|
7 |
|
8 | -- Uncomment the following library declaration if instantiating
|
9 | -- any Xilinx primitives in this code.
|
10 | --library UNISIM;
|
11 | --use UNISIM.VComponents.all;
|
12 |
|
13 | entity vga is
|
14 | Port ( clk50 : in STD_LOGIC;
|
15 | vga_red : out STD_LOGIC_VECTOR (2 downto 0);
|
16 | vga_green : out STD_LOGIC_VECTOR (2 downto 0);
|
17 | vga_blue : out STD_LOGIC_VECTOR (2 downto 1);
|
18 | vga_hsync : out STD_LOGIC;
|
19 | vga_vsync : out STD_LOGIC;
|
20 | frame_addr : out STD_LOGIC_VECTOR (14 downto 0);
|
21 | frame_pixel : in STD_LOGIC_VECTOR (7 downto 0));
|
22 | end vga;
|
23 |
|
24 | architecture Behavioral of vga is
|
25 | -- Timing constants
|
26 | constant hRez : natural := 640;
|
27 | constant vRez : natural := 480;
|
28 |
|
29 | constant hMaxCount : natural := 799;
|
30 | constant hStartSync : natural := 655;
|
31 | constant hEndSync : natural := 751;
|
32 | constant vMaxCount : natural := 525;
|
33 | constant vStartSync : natural := 490;
|
34 | constant vEndSync : natural := 491;
|
35 | constant hsync_active : std_logic := '1';
|
36 | constant vsync_active : std_logic := '1';
|
37 |
|
38 | signal hCounter : unsigned(10 downto 0) := (others => '0');
|
39 | signal vCounter : unsigned(9 downto 0) := (others => '0');
|
40 | signal address : unsigned(16 downto 0) := (others => '0');
|
41 | signal blank : std_logic := '1';
|
42 | SIGNAL clk25 :STD_LOGIC;
|
43 |
|
44 | begin
|
45 | frame_addr <= std_logic_vector(address(16 downto 2));
|
46 |
|
47 | process (clk50)
|
48 | begin
|
49 | if clk50'event and clk50='1' then
|
50 | if (clk25 = '0')then
|
51 | clk25 <= '1';
|
52 | else
|
53 | clk25 <= '0';
|
54 | end if;
|
55 | end if;
|
56 | end process;
|
57 |
|
58 | process(clk25)
|
59 | begin
|
60 | if rising_edge(clk25) then
|
61 | -- Count the lines and rows
|
62 | if hCounter = hMaxCount-1 then
|
63 | hCounter <= (others => '0');
|
64 | if vCounter = vMaxCount-1 then
|
65 | vCounter <= (others => '0');
|
66 | else
|
67 | vCounter <= vCounter+1;
|
68 | end if;
|
69 | else
|
70 | hCounter <= hCounter+1;
|
71 | end if;
|
72 |
|
73 | if blank = '0' then
|
74 | vga_red <= frame_pixel(7 downto 5);
|
75 | vga_green <= frame_pixel(4 downto 2);
|
76 | vga_blue <= frame_pixel(1 downto 0);
|
77 | else
|
78 | vga_red <= (others => '0');
|
79 | vga_green <= (others => '0');
|
80 | vga_blue <= (others => '0');
|
81 | end if;
|
82 |
|
83 | if vCounter >= vRez then
|
84 | address <= (others => '0');
|
85 | blank <= '1';
|
86 | else
|
87 | if hCounter >= 0 and hCounter < 640 then
|
88 | blank <= '0';
|
89 |
|
90 | address <= address+1;
|
91 |
|
92 | else
|
93 | blank <= '1';
|
94 | end if;
|
95 | end if;
|
96 |
|
97 |
|
98 | if hCounter > hStartSync and hCounter <= hEndSync then
|
99 | vga_hSync <= hsync_active;
|
100 | else
|
101 | vga_hSync <= not hsync_active;
|
102 | end if;
|
103 |
|
104 |
|
105 | if vCounter >= vStartSync and vCounter <= vEndSync then
|
106 | vga_vSync <= vsync_active;
|
107 | else
|
108 | vga_vSync <= not vsync_active;
|
109 | end if;
|
110 | end if;
|
111 | end process;
|
112 | end Behavioral;
|