-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_sync.vhd
106 lines (92 loc) · 2.86 KB
/
video_sync.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
---------------------------------------------------------------------------------
-- composite_sync by Dar ([email protected])
-- http://darfpga.blogspot.fr
--
-- Generate composite sync and blank for tv mode from h/v syncs
--
---------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.numeric_std.all;
entity video_sync is
port(
clk32 : in std_logic;
hsync : in std_logic;
vsync : in std_logic;
ntsc : in std_logic;
wide : in std_logic;
hsync_out : out std_logic;
vsync_out : out std_logic;
hblank : out std_logic;
vblank : out std_logic
);
end;
architecture struct of video_sync is
signal clk_cnt : std_logic_vector(1 downto 0);
signal vsync_r : std_logic;
signal hsync_r : std_logic;
signal hsync_r0 : std_logic;
begin
process(clk32)
variable dot_count : integer range 0 to 1023 := 0;
variable line_count : integer range 0 to 511 := 0;
begin
if falling_edge(clk32) then
hsync_r0 <= hsync;
if hsync_r0 = '0' and hsync = '1' then
clk_cnt <= "00";
else
clk_cnt <= clk_cnt + '1';
end if;
end if;
if rising_edge(clk32) then
if clk_cnt = "00" then
vsync_r <= vsync;
hsync_r <= hsync;
if hsync_r = '0' and hsync = '1' then
dot_count := 0;
line_count := line_count + 1;
else
dot_count := dot_count + 1;
end if;
if vsync_r = '0' and vsync = '1' then
line_count := 0;
end if;
if ntsc = '1' then
if dot_count = 010 then hsync_out <= '1'; end if;
if dot_count = 048 then hsync_out <= '0'; end if;
if line_count = 004 then vsync_out <= '1'; end if;
if line_count = 010 then vsync_out <= '0'; end if;
if wide = '0' then
if dot_count = 510 then hblank <= '1'; end if;
if dot_count = 096 then hblank <= '0'; end if;
if line_count = 000 then vblank <= '1'; end if;
if line_count = 012 then vblank <= '0'; end if;
else
if dot_count = 510 then hblank <= '1'; end if;
if dot_count = 096 then hblank <= '0'; end if;
if line_count = 242 then vblank <= '1'; end if;
if line_count = 035 then vblank <= '0'; end if;
end if;
else
if dot_count = 010 then hsync_out <= '1'; end if;
if dot_count = 048 then hsync_out <= '0'; end if;
if line_count = 002 then vsync_out <= '1'; end if;
if line_count = 010 then vsync_out <= '0'; end if;
if wide = '0' then
if dot_count = 480 then hblank <= '1'; end if;
if dot_count = 110 then hblank <= '0'; end if;
if line_count = 302 then vblank <= '1'; end if;
if line_count = 022 then vblank <= '0'; end if;
else
if dot_count = 478 then hblank <= '1'; end if;
if dot_count = 112 then hblank <= '0'; end if;
if line_count = 266 then vblank <= '1'; end if;
if line_count = 059 then vblank <= '0'; end if;
end if;
end if;
end if;
end if;
end process;
end architecture;