Skip to content

Commit 7cf1329

Browse files
committed
Version 0.1
0 parents  commit 7cf1329

File tree

9 files changed

+307
-0
lines changed

9 files changed

+307
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vhdltool-config.yaml
2+

.library_mapping.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<com.sigasi.hdt.shared.librarymapping.model:LibraryMappings xmlns:com.sigasi.hdt.shared.librarymapping.model="com.sigasi.hdt.vhdl.scoping.librarymapping" Version="2">
3+
<Mappings Location="Common Libraries/IEEE" Library="ieee"/>
4+
<Mappings Location="Common Libraries/IEEE Synopsys" Library="ieee"/>
5+
<Mappings Location="Common Libraries" Library="not mapped"/>
6+
<Mappings Location="Common Libraries/STD" Library="std"/>
7+
<Mappings Location="" Library="work"/>
8+
</com.sigasi.hdt.shared.librarymapping.model:LibraryMappings>

.project

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>VGA</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>com.sigasi.hdt.vhdl.ui.vhdlNature</nature>
16+
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
17+
</natures>
18+
<linkedResources>
19+
<link>
20+
<name>Common Libraries</name>
21+
<type>2</type>
22+
<locationURI>virtual:/virtual</locationURI>
23+
</link>
24+
<link>
25+
<name>Common Libraries/DRAG_REUSABLE_LIBRARIES_HERE.txt</name>
26+
<type>1</type>
27+
<locationURI>sigasiresource:/vhdl/readme.txt</locationURI>
28+
</link>
29+
<link>
30+
<name>Common Libraries/IEEE</name>
31+
<type>2</type>
32+
<locationURI>sigasiresource:/vhdl/93/IEEE</locationURI>
33+
</link>
34+
<link>
35+
<name>Common Libraries/IEEE Synopsys</name>
36+
<type>2</type>
37+
<locationURI>sigasiresource:/vhdl/93/IEEE%20Synopsys</locationURI>
38+
</link>
39+
<link>
40+
<name>Common Libraries/STD</name>
41+
<type>2</type>
42+
<locationURI>sigasiresource:/vhdl/93/STD</locationURI>
43+
</link>
44+
</linkedResources>
45+
</projectDescription>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<project>=93
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
encoding//Common\ Libraries/IEEE=utf-8
3+
encoding//Common\ Libraries/IEEE\ Synopsys=utf-8
4+
encoding//Common\ Libraries/STD=utf-8
5+
encoding/Common\ Libraries=utf-8

src/vga.vhd

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
use ieee.numeric_std.all;
4+
5+
entity vga is
6+
port(
7+
clk : in std_logic; -- Pixel clock
8+
rst : in std_logic;
9+
10+
hsync : out std_logic;
11+
vsync : out std_logic;
12+
13+
-- Input colors
14+
i_red : in std_logic_vector(1 downto 0);
15+
i_blue : in std_logic_vector(1 downto 0);
16+
i_green : in std_logic_vector(1 downto 0);
17+
18+
-- Output colors
19+
-- 4 x 4 x 4 yields 64 different colors
20+
o_red : out std_logic_vector(1 downto 0);
21+
o_blue : out std_logic_vector(1 downto 0);
22+
o_green : out std_logic_vector(1 downto 0)
23+
);
24+
end entity vga;
25+
26+
architecture RTL of vga is
27+
28+
-- Timing - 1024 x 768 @ 60Hz
29+
-- 65 MHz Pixel Clock
30+
31+
constant H_VISIBLE_AREA : natural := 1024;
32+
constant H_FRONT_PORCH : natural := H_VISIBLE_AREA + 0;
33+
constant H_SYNC_PULSE : natural := H_FRONT_PORCH + 24;
34+
constant H_BACK_PORCH : natural := H_SYNC_PULSE + 136;
35+
constant H_WHOLE_LINE : natural := H_BACK_PORCH + 160;
36+
37+
constant V_VISIBLE_AREA : natural := 768;
38+
constant V_FRONT_PORCH : natural := V_VISIBLE_AREA + 0;
39+
constant V_SYNC_PULSE : natural := V_FRONT_PORCH + 3;
40+
constant V_BACK_PORCH : natural := V_SYNC_PULSE + 6;
41+
constant V_WHOLE_LINE : natural := V_BACK_PORCH + 29;
42+
43+
-- Data for test
44+
constant WHITE_PIXEL : std_logic_vector(5 downto 0) := (others => '1');
45+
46+
alias R : std_logic_vector(1 downto 0) is WHITE_PIXEL(5 downto 4);
47+
alias G : std_logic_vector(1 downto 0) is WHITE_PIXEL(3 downto 2);
48+
alias B : std_logic_vector(1 downto 0) is WHITE_PIXEL(1 downto 0);
49+
50+
procedure SyncCount(signal count : inout natural;
51+
constant wrap : in natural;
52+
constant enable : in boolean;
53+
variable wrapped : out boolean) is
54+
begin
55+
if enable then
56+
if count < wrap then
57+
count <= count + 1;
58+
wrapped := false;
59+
else
60+
count <= 0;
61+
wrapped := true;
62+
end if;
63+
end if;
64+
end procedure;
65+
66+
signal h_count : natural := 0;
67+
signal v_count : natural := 0;
68+
69+
70+
begin
71+
72+
process(clk)
73+
74+
variable wrapped : boolean;
75+
76+
begin
77+
78+
if rising_edge(clk) then
79+
80+
if rst='1' then
81+
82+
o_red <= (others => '0');
83+
o_blue <= (others => '0');
84+
o_green <= (others => '0');
85+
86+
else
87+
88+
SyncCount(h_count, H_WHOLE_LINE, true, wrapped);
89+
SyncCount(v_count, V_WHOLE_LINE, wrapped, wrapped);
90+
91+
-- Sync Pulses
92+
if h_count = H_SYNC_PULSE then
93+
hsync <= '0';
94+
elsif h_count = H_BACK_PORCH then
95+
hsync <= '1';
96+
end if;
97+
98+
if v_count = V_SYNC_PULSE then
99+
vsync <= '0';
100+
elsif v_count = V_BACK_PORCH then
101+
vsync <= '1';
102+
end if;
103+
104+
-- To display or not to display
105+
if h_count < H_VISIBLE_AREA and v_count < V_VISIBLE_AREA then
106+
107+
o_red <= R;
108+
o_green <= G;
109+
o_blue <= B;
110+
111+
else
112+
113+
o_red <= (others => '0');
114+
o_green <= (others => '0');
115+
o_blue <= (others =>'0');
116+
117+
end if;
118+
119+
end if;
120+
121+
end if;
122+
123+
end process;
124+
end architecture RTL;

test/vga_tb.vhd

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
use ieee.numeric_std.all;
4+
5+
entity vga_tb is
6+
end entity vga_tb;
7+
8+
architecture rtl of vga_tb is
9+
10+
-- Clock
11+
constant CLOCK_SPEED : natural := 65e6;
12+
constant CLOCK_PERIOD : time := 1.0 sec / CLOCK_SPEED;
13+
constant DUTY_CYCLE : real := 0.5;
14+
15+
signal clk : std_logic := '0';
16+
signal rst : std_logic := '0';
17+
18+
signal hsync, vsync : std_logic;
19+
20+
signal o_red, o_blue, o_green : std_logic_vector(2 downto 0);
21+
22+
begin
23+
24+
vga1 : entity work.vga
25+
port map(
26+
clk => clk, -- Pixel clock
27+
rst => rst,
28+
29+
hsync => hsync,
30+
vsync => vsync,
31+
32+
-- Input colors
33+
i_red => (others => '0'),
34+
i_blue => (others => '0'),
35+
i_green => (others => '0'),
36+
37+
-- Output colors
38+
-- 8 x 8 x 8 yields 512 different colors
39+
o_red => o_red,
40+
o_blue => o_blue,
41+
o_green => o_green
42+
);
43+
44+
45+
clk <= not clk after CLOCK_PERIOD / 2;
46+
47+
end architecture rtl;
48+

test/vga_tb_behav.wcfg

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<wave_config>
3+
<wave_state>
4+
</wave_state>
5+
<db_ref_list>
6+
<db_ref path="vga_tb_behav.wdb" id="1">
7+
<top_modules>
8+
<top_module name="vga_tb" />
9+
</top_modules>
10+
</db_ref>
11+
</db_ref_list>
12+
<zoom_setting>
13+
<ZoomStartTime time="0fs"></ZoomStartTime>
14+
<ZoomEndTime time="6111fs"></ZoomEndTime>
15+
<Cursor1Time time="27906906756000fs"></Cursor1Time>
16+
</zoom_setting>
17+
<column_width_setting>
18+
<NameColumnWidth column_width="175"></NameColumnWidth>
19+
<ValueColumnWidth column_width="146"></ValueColumnWidth>
20+
</column_width_setting>
21+
<WVObjectSize size="7" />
22+
<wvobject type="logic" fp_name="/vga_tb/clk">
23+
<obj_property name="ElementShortName">clk</obj_property>
24+
<obj_property name="ObjectShortName">clk</obj_property>
25+
</wvobject>
26+
<wvobject type="logic" fp_name="/vga_tb/rst">
27+
<obj_property name="ElementShortName">rst</obj_property>
28+
<obj_property name="ObjectShortName">rst</obj_property>
29+
</wvobject>
30+
<wvobject type="logic" fp_name="/vga_tb/hsync">
31+
<obj_property name="ElementShortName">hsync</obj_property>
32+
<obj_property name="ObjectShortName">hsync</obj_property>
33+
</wvobject>
34+
<wvobject type="logic" fp_name="/vga_tb/vsync">
35+
<obj_property name="ElementShortName">vsync</obj_property>
36+
<obj_property name="ObjectShortName">vsync</obj_property>
37+
</wvobject>
38+
<wvobject type="array" fp_name="/vga_tb/o_red">
39+
<obj_property name="ElementShortName">o_red[2:0]</obj_property>
40+
<obj_property name="ObjectShortName">o_red[2:0]</obj_property>
41+
</wvobject>
42+
<wvobject type="array" fp_name="/vga_tb/o_blue">
43+
<obj_property name="ElementShortName">o_blue[2:0]</obj_property>
44+
<obj_property name="ObjectShortName">o_blue[2:0]</obj_property>
45+
</wvobject>
46+
<wvobject type="array" fp_name="/vga_tb/o_green">
47+
<obj_property name="ElementShortName">o_green[2:0]</obj_property>
48+
<obj_property name="ObjectShortName">o_green[2:0]</obj_property>
49+
</wvobject>
50+
</wave_config>

vga.core

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CAPI=2:
2+
name : copl:display:vga_module:0.1
3+
4+
filesets:
5+
src:
6+
files:
7+
- src/vga.vhd : {file_type : vhdlSource-93}
8+
9+
test:
10+
files:
11+
- test/vga_tb.vhd : {file_type : vhdlSource-93}
12+
- test/vga_tb_behav.wcfg : {file_type : user, copyto : ./}
13+
14+
targets:
15+
sim:
16+
default_tool: xsim
17+
filesets: [src, test]
18+
tools:
19+
modelsim:
20+
vlog_options: [-timescale=1ns/1ns]
21+
xsim:
22+
xelab_options: [--debug, all, --timescale, 1ns/1ns]
23+
xsim_options: [--view, vga_tb_behav.wcfg]
24+
toplevel: vga_tb

0 commit comments

Comments
 (0)