-
Notifications
You must be signed in to change notification settings - Fork 0
/
vga_simple_grid.vhd
88 lines (76 loc) · 2.28 KB
/
vga_simple_grid.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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.vga_util.all;
entity vga_simple_grid is
port (
clk: in std_logic;
vga_r: out std_logic_vector(3 downto 0);
vga_g: out std_logic_vector(3 downto 0);
vga_b: out std_logic_vector(3 downto 0);
vga_hs: out std_logic;
vga_vs: out std_logic
);
end entity;
architecture rtl of vga_simple_grid is
function int2slv(arg: integer; length: positive) return std_logic_vector is
begin
return std_logic_vector(to_unsigned(arg, length));
end function;
signal pixel_clk: std_logic;
signal hstate: vga_hstate;
signal vstate: vga_vstate;
signal pc_x: natural range 0 to 640 - 1 := 0;
signal pc_y: natural range 0 to 480 - 1 := 0;
begin
current_pixel: process (pixel_clk, hstate, vstate)
begin
if rising_edge(pixel_clk) then
if hstate = HActiveVideo and vstate = VActiveVideo then
if pc_x = 640 - 1 then
pc_x <= 0;
if pc_y = 480 - 1 then
pc_y <= 0;
else
pc_y <= pc_y + 1;
end if;
else
pc_x <= pc_x + 1;
end if;
end if;
end if;
end process;
emit_pixel: process (pc_y, pc_x, hstate, vstate)
begin
if hstate = HActiveVideo and vstate = VActiveVideo then
vga_r <= int2slv(pc_x mod 2 ** vga_g'length, vga_g'length);
vga_b <= int2slv(pc_y mod 2 ** vga_b'length, vga_b'length);
vga_g <= (others => '0');
else
vga_r <= (others => '0');
vga_g <= (others => '0');
vga_b <= (others => '0');
end if;
end process;
pixel_clock: vga_pixel_clock
port map (
clk => clk,
pixel_clk => pixel_clk
);
sync_ctrl: vga_sync_ctrl
generic map (
timings => get_timings_from_videomode(width => 640, height => 480,
refresh_rate => 60)
) port map (
clk => pixel_clk,
en => '1',
reset => '0',
hsync => vga_hs,
vsync => vga_vs,
htimer => open,
vtimer => open,
hstate => hstate,
vstate => vstate
);
end architecture;