1 |
2 |
smanz |
---------------------------------------------------------------
|
2 |
|
|
-- This code is a simplified port from the Verilog sources that can be found here:
|
3 |
|
|
-- http://embedded.olin.edu/xilinx_docs/projects/bitvga-v2p.php
|
4 |
|
|
--
|
5 |
|
|
-- The Verilog sources are based on code from Xilinx and released under
|
6 |
|
|
-- "Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License"
|
7 |
|
|
--
|
8 |
|
|
-- with the note, that Xilinx claims the following copyright for their
|
9 |
|
|
-- initial code:
|
10 |
|
|
-- XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
|
11 |
|
|
-- SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
|
12 |
|
|
-- XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
|
13 |
|
|
-- AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
|
14 |
|
|
-- OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
|
15 |
|
|
-- IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
|
16 |
|
|
-- AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
|
17 |
|
|
-- FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY
|
18 |
|
|
-- WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
|
19 |
|
|
-- IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
|
20 |
|
|
-- REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
|
21 |
|
|
-- INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
22 |
|
|
-- FOR A PARTICULAR PURPOSE.
|
23 |
|
|
--
|
24 |
|
|
-- (c) Copyright 2004 Xilinx, Inc.
|
25 |
|
|
-- All rights reserved.
|
26 |
|
|
---------------------------------------------------------------
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
library IEEE;
|
30 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
31 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
32 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
33 |
|
|
|
34 |
|
|
-- Needed for 'OFDDRTRSE'
|
35 |
|
|
library UNISIM;
|
36 |
|
|
use UNISIM.VCOMPONENTS.all;
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
entity vga_signals is
|
40 |
|
|
Generic(
|
41 |
|
|
CHARACTER_DECODE_DELAY : integer := 4;
|
42 |
|
|
|
43 |
|
|
-- 640 X 480 @ 60Hz with a 25.175MHz pixel clock
|
44 |
|
|
H_ACTIVE : integer := 640; -- pixels
|
45 |
|
|
H_FRONT_PORCH : integer := 16; -- pixels
|
46 |
|
|
H_SYNCH : integer := 96; -- pixels
|
47 |
|
|
H_BACK_PORCH : integer := 48; -- pixels
|
48 |
|
|
H_TOTAL : integer := 800; -- pixels
|
49 |
|
|
V_ACTIVE : integer := 480; -- lines
|
50 |
|
|
V_FRONT_PORCH : integer := 11; -- lines
|
51 |
|
|
V_SYNCH : integer := 2; -- lines
|
52 |
|
|
V_BACK_PORCH : integer := 31; -- lines
|
53 |
|
|
V_TOTAL : integer := 524; -- lines
|
54 |
|
|
CLK_MULTIPLY : integer := 2; -- 100 * 2/8 = 25.000 MHz
|
55 |
|
|
CLK_DIVIDE : integer := 8
|
56 |
|
|
);
|
57 |
|
|
Port (
|
58 |
|
|
system_clock : in std_logic;
|
59 |
|
|
|
60 |
|
|
VGA_OUT_PIXEL_CLOCK : out std_logic;
|
61 |
|
|
VGA_COMP_SYNCH : out std_logic;
|
62 |
|
|
VGA_OUT_BLANK_Z : out std_logic;
|
63 |
|
|
VGA_HSYNCH : out std_logic;
|
64 |
|
|
VGA_VSYNCH : out std_logic;
|
65 |
|
|
|
66 |
|
|
o_pixel_clock : out std_logic;
|
67 |
|
|
o_pixel_count : out std_logic_vector(10 downto 0);
|
68 |
|
|
o_line_count : out std_logic_vector( 9 downto 0)
|
69 |
|
|
);
|
70 |
|
|
end vga_signals;
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
architecture Behavioral of vga_signals is
|
74 |
|
|
|
75 |
|
|
--******************************************************
|
76 |
|
|
--** Components
|
77 |
|
|
--******************************************************
|
78 |
|
|
|
79 |
|
|
-- Clock Buffer
|
80 |
|
|
component BUFG
|
81 |
|
|
port (
|
82 |
|
|
I: in STD_LOGIC;
|
83 |
|
|
O: out STD_LOGIC
|
84 |
|
|
);
|
85 |
|
|
end component;
|
86 |
|
|
|
87 |
|
|
-- DCM to generate pixel_clock
|
88 |
|
|
component DCM
|
89 |
|
|
generic (
|
90 |
|
|
DLL_FREQUENCY_MODE : string := "LOW";
|
91 |
|
|
DFS_FREQUENCY_MODE : string := "LOW";
|
92 |
|
|
CLK_FEEDBACK : string := "1X";
|
93 |
|
|
DUTY_CYCLE_CORRECTION : boolean := TRUE;
|
94 |
|
|
CLKFX_MULTIPLY : integer := CLK_MULTIPLY;
|
95 |
|
|
CLKFX_DIVIDE : integer := CLK_DIVIDE;
|
96 |
|
|
CLKIN_DIVIDE_BY_2 : boolean := FALSE;
|
97 |
|
|
CLKIN_PERIOD : real := 10.0;
|
98 |
|
|
CLKOUT_PHASE_SHIFT : string := "NONE";
|
99 |
|
|
STARTUP_WAIT : boolean := false;
|
100 |
|
|
PHASE_SHIFT : integer := 0 ;
|
101 |
|
|
CLKDV_DIVIDE : real := 4.0
|
102 |
|
|
);
|
103 |
|
|
port ( CLKIN : in std_logic;
|
104 |
|
|
CLKFB : in std_logic;
|
105 |
|
|
DSSEN : in std_logic;
|
106 |
|
|
PSINCDEC : in std_logic;
|
107 |
|
|
PSEN : in std_logic;
|
108 |
|
|
PSCLK : in std_logic;
|
109 |
|
|
RST : in std_logic;
|
110 |
|
|
CLK0 : out std_logic;
|
111 |
|
|
CLK90 : out std_logic;
|
112 |
|
|
CLK180 : out std_logic;
|
113 |
|
|
CLK270 : out std_logic;
|
114 |
|
|
CLK2X : out std_logic;
|
115 |
|
|
CLK2X180 : out std_logic;
|
116 |
|
|
CLKDV : out std_logic;
|
117 |
|
|
CLKFX : out std_logic;
|
118 |
|
|
CLKFX180 : out std_logic;
|
119 |
|
|
LOCKED : out std_logic;
|
120 |
|
|
PSDONE : out std_logic;
|
121 |
|
|
STATUS : out std_logic_vector(7 downto 0)
|
122 |
|
|
);
|
123 |
|
|
end component;
|
124 |
|
|
|
125 |
|
|
-- 16 Bit Shift Register for Clockgen
|
126 |
|
|
component SRL16
|
127 |
|
|
-- synthesis translate_off
|
128 |
|
|
generic (
|
129 |
|
|
INIT : std_logic_vector := X"000F"
|
130 |
|
|
);
|
131 |
|
|
-- synthesis translate_on
|
132 |
|
|
port (
|
133 |
|
|
Q : out STD_ULOGIC;
|
134 |
|
|
A0 : in STD_ULOGIC;
|
135 |
|
|
A1 : in STD_ULOGIC;
|
136 |
|
|
A2 : in STD_ULOGIC;
|
137 |
|
|
A3 : in STD_ULOGIC;
|
138 |
|
|
CLK : in STD_ULOGIC;
|
139 |
|
|
D : in STD_ULOGIC
|
140 |
|
|
);
|
141 |
|
|
end component;
|
142 |
|
|
|
143 |
|
|
-- ** End Components *************************************
|
144 |
|
|
|
145 |
|
|
signal pixel_count : std_logic_vector(10 downto 0);
|
146 |
|
|
signal line_count : std_logic_vector(9 downto 0);
|
147 |
|
|
signal reset, hsynch, vsynch, comp_synch, blank : std_logic;
|
148 |
|
|
signal dcm_reset, dcm_locked: std_logic;
|
149 |
|
|
signal pixel_clock, pixel_clock_buffered, n_pixel_clock_buffered, system_clock_dcm_in, system_clock_dcm_out : std_logic;
|
150 |
|
|
signal v_c_synch, h_c_synch, h_blank, v_blank : std_logic;
|
151 |
|
|
signal hsynch_delay, hsynch_delay0, vsynch_delay, vsynch_delay0 : std_logic;
|
152 |
|
|
|
153 |
|
|
begin
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
--******************************************************
|
157 |
|
|
--** Clockgen: generate and buffer clocks
|
158 |
|
|
--******************************************************
|
159 |
|
|
|
160 |
|
|
-- buffering clocks
|
161 |
|
|
buffg_for_system_clock: BUFG
|
162 |
|
|
port map (
|
163 |
|
|
I => system_clock_dcm_out,
|
164 |
|
|
O => system_clock_dcm_in
|
165 |
|
|
);
|
166 |
|
|
buffg_for_pixel_clock: BUFG
|
167 |
|
|
port map (
|
168 |
|
|
I => pixel_clock,
|
169 |
|
|
O => pixel_clock_buffered
|
170 |
|
|
);
|
171 |
|
|
|
172 |
|
|
-- DCM for generating pixel_clock
|
173 |
|
|
dcm_for_pixel_clock: DCM
|
174 |
|
|
port map (
|
175 |
|
|
CLKIN => system_clock,
|
176 |
|
|
CLKFB => system_clock_dcm_in,
|
177 |
|
|
DSSEN => '0',
|
178 |
|
|
PSINCDEC => '0',
|
179 |
|
|
PSEN => '0',
|
180 |
|
|
PSCLK => '0',
|
181 |
|
|
RST => dcm_reset,
|
182 |
|
|
CLK0 => system_clock_dcm_out,
|
183 |
|
|
CLKFX => pixel_clock,
|
184 |
|
|
LOCKED => dcm_locked
|
185 |
|
|
);
|
186 |
|
|
|
187 |
|
|
-- 16 Bit Shift Register
|
188 |
|
|
SRL16_INSTANCE_NAME : SRL16
|
189 |
|
|
-- synthesis translate_off
|
190 |
|
|
generic map(
|
191 |
|
|
INIT => X"000F"
|
192 |
|
|
)
|
193 |
|
|
-- synthesis translate_on
|
194 |
|
|
port map (
|
195 |
|
|
Q => dcm_reset,
|
196 |
|
|
A0 => '1',
|
197 |
|
|
A1 => '1',
|
198 |
|
|
A2 => '1',
|
199 |
|
|
A3 => '1',
|
200 |
|
|
CLK => system_clock,
|
201 |
|
|
D => '0'
|
202 |
|
|
);
|
203 |
|
|
|
204 |
|
|
reset <= not dcm_locked;
|
205 |
|
|
-- ** End Clockgen *************************************
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
--******************************************************
|
210 |
|
|
--** Timings: generate timing signals
|
211 |
|
|
--******************************************************
|
212 |
|
|
|
213 |
|
|
--CREATE THE HORIZONTAL LINE PIXEL COUNTER
|
214 |
|
|
process (pixel_clock_buffered, reset)
|
215 |
|
|
begin
|
216 |
|
|
pixel_count <= pixel_count;
|
217 |
|
|
if (reset='1') then
|
218 |
|
|
pixel_count <= (others => '0');
|
219 |
|
|
elsif (pixel_clock_buffered'event and pixel_clock_buffered='1') then
|
220 |
|
|
pixel_count <= pixel_count + 1; --"00000000001";
|
221 |
|
|
if (pixel_count=H_TOTAL-1) then
|
222 |
|
|
pixel_count <= (others => '0'); --"00000000000";
|
223 |
|
|
end if;
|
224 |
|
|
end if;
|
225 |
|
|
end process;
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
-- CREATE THE HORIZONTAL SYNCH PULSE
|
229 |
|
|
process (pixel_clock_buffered, reset)
|
230 |
|
|
begin
|
231 |
|
|
hsynch <= hsynch;
|
232 |
|
|
if (reset='1') then
|
233 |
|
|
hsynch <= '0';
|
234 |
|
|
elsif (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
235 |
|
|
if (pixel_count = (H_ACTIVE + H_FRONT_PORCH -1)) then
|
236 |
|
|
hsynch <= '1';
|
237 |
|
|
elsif (pixel_count = (H_TOTAL - H_BACK_PORCH -1)) then
|
238 |
|
|
hsynch <= '0';
|
239 |
|
|
end if;
|
240 |
|
|
end if;
|
241 |
|
|
end process;
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
-- CREATE THE VERTICAL FRAME LINE COUNTER
|
245 |
|
|
process (pixel_clock_buffered, reset)
|
246 |
|
|
begin
|
247 |
|
|
line_count <= line_count;
|
248 |
|
|
if (reset='1') then
|
249 |
|
|
line_count <= (others => '0');
|
250 |
|
|
elsif (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
251 |
|
|
if ((line_count = (V_TOTAL - 1)) and (pixel_count = (H_TOTAL - 1))) then
|
252 |
|
|
line_count <= (others => '0');
|
253 |
|
|
elsif ((pixel_count = (H_TOTAL - 1))) then
|
254 |
|
|
line_count <= line_count + 1;
|
255 |
|
|
end if;
|
256 |
|
|
end if;
|
257 |
|
|
end process;
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
-- CREATE THE VERTICAL SYNCH PULSE
|
261 |
|
|
process (pixel_clock_buffered, reset)
|
262 |
|
|
begin
|
263 |
|
|
vsynch <= vsynch;
|
264 |
|
|
if (reset='1') then
|
265 |
|
|
vsynch <= '0';
|
266 |
|
|
elsif (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
267 |
|
|
if ((line_count = V_ACTIVE + V_FRONT_PORCH -1) and (pixel_count = H_TOTAL - 1)) then
|
268 |
|
|
vsynch <= '1';
|
269 |
|
|
elsif ((line_count = (V_TOTAL - V_BACK_PORCH - 1)) and (pixel_count = (H_TOTAL - 1))) then
|
270 |
|
|
vsynch <= '0';
|
271 |
|
|
end if;
|
272 |
|
|
end if;
|
273 |
|
|
end process;
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
-- ADD TWO PIPELINE DELAYS TO THE SYNCHs COMPENSATE FOR THE DAC PIPELINE DELAY
|
277 |
|
|
process (pixel_clock_buffered, reset)
|
278 |
|
|
begin
|
279 |
|
|
if (reset='1') then
|
280 |
|
|
hsynch_delay0 <= '0';
|
281 |
|
|
vsynch_delay0 <= '0';
|
282 |
|
|
hsynch_delay <= '0';
|
283 |
|
|
vsynch_delay <= '0';
|
284 |
|
|
elsif (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
285 |
|
|
hsynch_delay0 <= hsynch;
|
286 |
|
|
vsynch_delay0 <= vsynch;
|
287 |
|
|
hsynch_delay <= hsynch_delay0;
|
288 |
|
|
vsynch_delay <= vsynch_delay0;
|
289 |
|
|
end if;
|
290 |
|
|
end process;
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
-- CREATE THE HORIZONTAL BLANKING SIGNAL
|
294 |
|
|
-- the "-2" is used instead of "-1" because of the extra register delay
|
295 |
|
|
-- for the composite blanking signal
|
296 |
|
|
process (pixel_clock_buffered, reset)
|
297 |
|
|
begin
|
298 |
|
|
h_blank <= h_blank;
|
299 |
|
|
if (reset='1') then
|
300 |
|
|
h_blank <= '0';
|
301 |
|
|
elsif (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
302 |
|
|
if (pixel_count = (H_ACTIVE -2)) then
|
303 |
|
|
h_blank <= '1';
|
304 |
|
|
elsif (pixel_count = (H_TOTAL -2)) then
|
305 |
|
|
h_blank <= '0';
|
306 |
|
|
end if;
|
307 |
|
|
end if;
|
308 |
|
|
end process;
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
-- CREATE THE VERTICAL BLANKING SIGNAL
|
312 |
|
|
-- the "-2" is used instead of "-1" in the horizontal factor because of the extra
|
313 |
|
|
-- register delay for the composite blanking signal
|
314 |
|
|
process (pixel_clock_buffered, reset)
|
315 |
|
|
begin
|
316 |
|
|
if (reset='1') then
|
317 |
|
|
v_blank <= '0';
|
318 |
|
|
elsif (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
319 |
|
|
if ((line_count = (V_ACTIVE - 1) and (pixel_count = H_TOTAL - 2))) then
|
320 |
|
|
v_blank <= '1';
|
321 |
|
|
elsif ((line_count = (V_TOTAL - 1)) and (pixel_count = (H_TOTAL - 2))) then
|
322 |
|
|
v_blank <= '0';
|
323 |
|
|
end if;
|
324 |
|
|
end if;
|
325 |
|
|
end process;
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
-- CREATE THE COMPOSITE BLANKING SIGNAL
|
329 |
|
|
process (pixel_clock_buffered, reset)
|
330 |
|
|
begin
|
331 |
|
|
if (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
332 |
|
|
blank <= (not reset) and (h_blank or v_blank);
|
333 |
|
|
end if;
|
334 |
|
|
end process;
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
--******************************************************
|
338 |
|
|
--** Output: connect output signals
|
339 |
|
|
--******************************************************
|
340 |
|
|
|
341 |
|
|
-- don't ask me why I do this,
|
342 |
|
|
-- generate VGA_OUT_PIXEL_CLOCK:
|
343 |
|
|
OFDDRTRSE_inst : OFDDRTRSE
|
344 |
|
|
port map (
|
345 |
|
|
O => VGA_OUT_PIXEL_CLOCK,
|
346 |
|
|
C0 => pixel_clock_buffered,
|
347 |
|
|
C1 => n_pixel_clock_buffered,
|
348 |
|
|
CE => '1',
|
349 |
|
|
D0 => '0',
|
350 |
|
|
D1 => '1',
|
351 |
|
|
R => reset,
|
352 |
|
|
S => '0',
|
353 |
|
|
T => '0'
|
354 |
|
|
);
|
355 |
|
|
n_pixel_clock_buffered <= not pixel_clock_buffered;
|
356 |
|
|
|
357 |
|
|
o_pixel_clock <= pixel_clock_buffered;
|
358 |
|
|
|
359 |
|
|
process (pixel_clock_buffered, reset)
|
360 |
|
|
begin
|
361 |
|
|
-- if rising_edge(pixel_clock_buffered) then
|
362 |
|
|
if (pixel_clock_buffered'event and pixel_clock_buffered='1') then --or (reset'event and reset='1') then
|
363 |
|
|
VGA_COMP_SYNCH <= not reset;
|
364 |
|
|
VGA_OUT_BLANK_Z <= not blank and not reset;
|
365 |
|
|
VGA_HSYNCH <= hsynch or reset;
|
366 |
|
|
VGA_VSYNCH <= vsynch or reset;
|
367 |
|
|
o_pixel_count <= pixel_count;
|
368 |
|
|
o_line_count <= line_count;
|
369 |
|
|
end if;
|
370 |
|
|
end process;
|
371 |
|
|
-- ** End Output *************************************
|
372 |
|
|
|
373 |
|
|
end Behavioral;
|
374 |
|
|
|