-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvga_hsync_ctrl.vhd
83 lines (74 loc) · 2.34 KB
/
vga_hsync_ctrl.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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.vga_util.all;
entity vga_hsync_ctrl is
generic (
timings: vga_hsync_timings
);
port (
clk, en, reset: in std_logic;
hsync: out std_logic := '0';
timer: out natural range 0 to get_max_timing(timings) - 1 := 0;
state: out vga_hstate := vga_hstate'left
);
end entity;
architecture rtl of vga_hsync_ctrl is
signal timer_int: natural range 0 to get_max_timing(timings) - 1 := 0;
signal state_current, state_next: vga_hstate := vga_hstate'left;
begin
timer <= timer_int;
state <= state_current;
register_video_state: process (clk, en, reset, state_next)
begin
if rising_edge(clk) then
if reset = '1' then
state_current <= HFrontPorch;
elsif en = '1' then
state_current <= state_next;
end if;
end if;
end process;
decide_next_state: process (state_current, timer_int)
variable timer_reached_limit: boolean :=
timer_int = get_timer_limit(timings, state_current);
begin
if timer_reached_limit then
state_next <= get_next_vga_state(state_current);
else
state_next <= state_current;
end if;
end process;
update_hsync_timer: process (clk, en, reset, state_current, timer_int)
begin
if rising_edge(clk) then
if reset = '1' then
timer_int <= 0;
elsif en = '1' then
if timer_int >= get_timer_limit(timings, state_current) then
timer_int <= 0;
else
timer_int <= timer_int + 1;
end if;
end if;
end if;
end process;
emit_syncpulse: process (clk, en, reset, state_current, state_next, timer_int)
variable on_state_transition: boolean :=
timer_int = get_timer_limit(timings, state_current);
begin
if rising_edge(clk) then
if reset = '1' then
hsync <= '0';
elsif en = '1' then
if on_state_transition then
if state_next = HSyncPulse then
hsync <= '1';
else
hsync <= '0';
end if;
end if;
end if;
end if;
end process;
end architecture;