-
Notifications
You must be signed in to change notification settings - Fork 0
/
vga_controller.vhd
137 lines (121 loc) · 5.16 KB
/
vga_controller.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---------------------------------------------------------------------------
-- VGA controller --
-- Kyle Kloepper --
-- 4-05-2005 --
-- --
-- Modified by Stephen Kempf 04-08-2005 --
-- 10-05-2006 --
-- 03-12-2007 --
-- Fall 2009 Distribution --
-- --
-- Used standard 640x480 vga found at epanorama --
-- --
-- reference: http://www.xilinx.com/bvdocs/userguides/ug130.pdf --
-- http://www.epanorama.net/documents/pc/vga_timing.html --
-- --
-- note: The standard is changed slightly because of 25 mhz instead --
-- of 25.175 mhz pixel clock. Refresh rate drops slightly. --
-- --
-- For use with ECE 385 Lab 9 and Final Project --
-- ECE Department @ UIUC --
---------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity vga_controller is
Port ( clk : in std_logic; -- 50 MHz clock
reset : in std_logic; -- reset signal
hs : out std_logic; -- Horizontal sync pulse. Active low
vs : out std_logic; -- Vertical sync pulse. Active low
pixel_clk : out std_logic; -- 25 MHz pixel clock output
blank : out std_logic; -- Blanking interval indicator. Active low.
sync : out std_logic; -- Composite Sync signal. Active low. We don't use it in this lab,
-- but the video DAC on the DE2 board requires an input for it.
DrawX : out std_logic_vector(10 downto 0); -- horizontal coordinate
DrawY : out std_logic_vector(10 downto 0) ); -- vertical coordinate
end vga_controller;
architecture Behavioral of vga_controller is
--800 horizontal pixels indexed 0 to 799
--525 vertical pixels indexed 0 to 524
constant hpixels : std_logic_vector(9 downto 0) := "1100011111";
constant vlines : std_logic_vector(9 downto 0) := "1000001100";
--horizontal pixel and vertical line counters
signal hc, vc : std_logic_vector(10 downto 0);
signal clkdiv : std_logic;
--signal indicates if ok to display color for a pixel
signal display : std_logic;
begin
-- Disable Composite Sync
sync <= '0';
--This cuts the 50 Mhz clock in half to generate a 25 MHz pixel clock
process(clk, reset)
begin
if (reset = '1') then
clkdiv <= '0';
elsif (rising_edge(clk)) then
clkdiv <= not clkdiv;
end if;
end process;
--Runs the horizontal counter when it resets vertical counter is incremented
counter_proc : process(clkdiv, reset)
begin
if (reset = '1') then
hc <= "00000000000";
vc <= "00000000000";
elsif (rising_edge(clkdiv)) then
if (hc = hpixels) then --If hc has reached the end of pixel count
hc <= "00000000000";
if (vc = vlines) then -- if vc has reached end of line count
vc <= "00000000000";
else
vc <= vc + 1;
end if;
else
hc <= hc + 1; -- no statement about vc, implied vc <= vc;
end if;
end if;
end process;
DrawX <= hc;
DrawY <= vc;
-- horizontal sync pulse is 96 pixels long at pixels 656-752
-- (signal is registered to ensure clean output waveform)
hsync_proc : process (reset, clkdiv, hc)
begin
if (reset = '1') then
hs <= '0';
elsif (rising_edge(clkdiv)) then
if ((hc + 1) >= "1010010000" and (hc + 1) < "1011110000") then -- must check next value of hc
hs <= '0';
else
hs <= '1';
end if;
end if;
end process;
-- vertical sync pulse is 2 lines(800 pixels) long at line 490-491
-- (signal is registered to ensure clean output waveform)
vsync_proc : process(reset, clkdiv, vc)
begin
if (reset = '1') then
vs <= '0';
elsif (rising_edge(clkdiv)) then
if ((vc + 1) = "111101010" or (vc + 1) = "111101011") then -- must check next value of vc
vs <= '0';
else
vs <= '1';
end if;
end if;
end process;
-- only display pixels between horizontal 0-639 and vertical 0-479 (640x480)
-- (This signal is registered within the DAC chip, so we can leave it as pure combinational logic here)
blank_proc : process(hc, vc)
begin
if ((hc >= "1010000000") or (vc >= "0111100000")) then
display <= '0';
else
display <= '1';
end if;
end process;
blank <= display;
pixel_clk <= clkdiv;
end Behavioral;