@@ -3,6 +3,25 @@ use ieee.std_logic_1164.all;
33use ieee.numeric_std.all ;
44
55entity vga is
6+ generic (
7+ COLOR_IN_WIDTH : natural := 2 ;
8+ COLOR_OUT_WIDTH : natural := 2 ;
9+
10+ -- tinyvga.com/vga-timing
11+ -- Default - 1024 x 768 @ 60Hz
12+ -- 65 MHz Pixel Clock
13+ H_VISIBLE_AREA : natural := 1024 ;
14+ H_FRONT_PORCH : natural := 24 ;
15+ H_SYNC_PULSE : natural := 136 ;
16+ H_BACK_PORCH : natural := 160 ;
17+ H_WHOLE_LINE : natural := 1344 ;
18+
19+ V_VISIBLE_AREA : natural := 768 ;
20+ V_FRONT_PORCH : natural := 3 ;
21+ V_SYNC_PULSE : natural := 6 ;
22+ V_BACK_PORCH : natural := 29 ;
23+ V_WHOLE_LINE : natural := 806
24+ );
625 port (
726 clk : in std_logic ;
827 rst : in std_logic ;
@@ -11,37 +30,22 @@ entity vga is
1130 vsync : out std_logic ;
1231
1332 -- Input colors
14- i_red : in std_logic_vector (1 downto 0 );
15- i_blue : in std_logic_vector (1 downto 0 );
16- i_green : in std_logic_vector (1 downto 0 );
33+ i_red : in std_logic_vector (COLOR_IN_WIDTH - 1 downto 0 );
34+ i_blue : in std_logic_vector (COLOR_IN_WIDTH - 1 downto 0 );
35+ i_green : in std_logic_vector (COLOR_IN_WIDTH - 1 downto 0 );
1736
1837 -- '1' if ready for pixel else '0'
1938 pxl_rdy : out std_logic ;
2039
2140 -- Output colors
2241 -- 4 x 4 x 4 yields 64 different colors
23- o_red : out std_logic_vector (1 downto 0 );
24- o_blue : out std_logic_vector (1 downto 0 );
25- o_green : out std_logic_vector (1 downto 0 )
42+ o_red : out std_logic_vector (COLOR_OUT_WIDTH - 1 downto 0 );
43+ o_blue : out std_logic_vector (COLOR_OUT_WIDTH - 1 downto 0 );
44+ o_green : out std_logic_vector (COLOR_OUT_WIDTH - 1 downto 0 )
2645 );
2746end entity vga;
2847
2948architecture RTL of vga is
30-
31- -- Timing - 1024 x 768 @ 60Hz
32- -- 65 MHz Pixel Clock
33-
34- constant H_VISIBLE_AREA : natural := 1024 ;
35- constant H_FRONT_PORCH : natural := H_VISIBLE_AREA + 0 ;
36- constant H_SYNC_PULSE : natural := H_FRONT_PORCH + 24 ;
37- constant H_BACK_PORCH : natural := H_SYNC_PULSE + 136 ;
38- constant H_WHOLE_LINE : natural := H_BACK_PORCH + 160 ;
39-
40- constant V_VISIBLE_AREA : natural := 768 ;
41- constant V_FRONT_PORCH : natural := V_VISIBLE_AREA + 0 ;
42- constant V_SYNC_PULSE : natural := V_FRONT_PORCH + 3 ;
43- constant V_BACK_PORCH : natural := V_SYNC_PULSE + 6 ;
44- constant V_WHOLE_LINE : natural := V_BACK_PORCH + 29 ;
4549
4650 procedure SyncCount(signal count : inout natural ;
4751 constant wrap : in natural ;
@@ -61,7 +65,6 @@ architecture RTL of vga is
6165
6266 signal h_count : natural := 0 ;
6367 signal v_count : natural := 0 ;
64-
6568
6669begin
6770
@@ -85,15 +88,15 @@ begin
8588 SyncCount(v_count, V_WHOLE_LINE, wrapped, wrapped);
8689
8790 -- Sync Pulses
88- if h_count = H_SYNC_PULSE then
91+ if h_count = H_VISIBLE_AREA + H_FRONT_PORCH then
8992 hsync <= '0' ;
90- elsif h_count = H_BACK_PORCH then
93+ elsif h_count = H_VISIBLE_AREA + H_FRONT_PORCH + H_SYNC_PULSE then
9194 hsync <= '1' ;
9295 end if ;
9396
94- if v_count = V_SYNC_PULSE then
97+ if v_count = V_VISIBLE_AREA + V_FRONT_PORCH then
9598 vsync <= '0' ;
96- elsif v_count = V_BACK_PORCH then
99+ elsif v_count = V_VISIBLE_AREA + V_FRONT_PORCH + V_SYNC_PULSE then
97100 vsync <= '1' ;
98101 end if ;
99102
0 commit comments