vga_controller.vhd
4.86 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 04.10.2023 10:40:26
-- Design Name:
-- Module Name: vga_controller - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity vga_controller is
Port (clk_fpga : in std_logic;
sw : in std_logic_vector(15 downto 0);
vgaRed : out std_logic_vector(3 downto 0);
vgaGreen : out std_logic_vector(3 downto 0);
vgaBlue : out std_logic_vector(3 downto 0);
Hsync : out std_logic;
Vsync : out std_logic);
end vga_controller;
architecture Behavioral of vga_controller is
component clk_wiz_0
port (clk_out1 : out std_logic;
clk_in1 : in std_logic);
end component;
signal clk_65MHz : std_logic;
signal Hcount : integer range 1344 downto 1 := 1;
signal Vcount : integer range 1083264 downto 1 := 1;
signal myRed: std_logic_vector(3 downto 0);
signal myBlue: std_logic_vector(3 downto 0);
signal myGreen: std_logic_vector(3 downto 0);
signal leftLimit: integer range 1025 downto 0:= 0;
signal rightLimit: integer range 1025 downto 0:= 100;
signal upLimit: integer range 768 downto 0:= 0;
signal downLimit: integer range 768 downto 0:= 100;
signal pixelX: integer range 1344 downto 1:= 1;
signal pixelY: integer range 768 downto 1;
begin
clk_65MHz_1 : clk_wiz_0 port map (clk_out1 => clk_65MHz,
clk_in1 => clk_fpga);
myRed(0) <= sw(0);
myRed(1) <= sw(1);
myRed(2) <= sw(2);
myRed(3) <= sw(3);
myBlue(0) <= sw(4);
myBlue(1) <= sw(5);
myBlue(2) <= sw(6);
myBlue(3) <= sw(7);
myGreen(0) <= sw(8);
myGreen(1) <= sw(9);
myGreen(2) <= sw(10);
myGreen(3) <= sw(11);
pixelX <= Hcount;
process(clk_65MHz)
begin
if clk_65MHz'event and clk_65MHz = '1' then
if Vcount = 1032193 then
if rightLimit > 1024 and downLimit > 768 then
leftLimit <= 0;
rightLimit <= 100;
upLimit <= 0;
downLimit <= 100;
elsif rightLimit > 1024 then
leftLimit <= 0;
rightLimit <= 100;
upLimit <= upLimit + 1;
downLimit <= downLimit + 1;
else
leftLimit <= leftLimit + 1;
rightLimit <= rightLimit +1;
end if;
end if;
end if;
end process;
process(clk_65MHz)
-- Simplification des valeurs d'écran
begin
if clk_65MHz'event and clk_65MHz = '1' then
if Vcount = 1 then
pixelY <= 1;
elsif Hcount = 1025 then
pixelY <= pixelY + 1;
end if;
end if;
end process;
process(clk_65MHz)
-- Gestion de l'affichage
begin
if clk_65MHz'event and clk_65MHz = '1' then
if pixelX > leftLimit and pixelX < rightLimit and pixelY > upLimit and pixelY < downLimit then
-- Carré
vgaRed <= myRed;
vgaBlue <= myBlue;
vgaGreen <= myGreen;
elsif Hcount < 1025 and pixelY < 769 then
-- Background
vgaRed <= (others => '1');
vgaBlue <= (others => '1');
vgaGreen <= (others => '1');
else
-- Hors pixel
vgaRed <= (others => '0');
vgaBlue <= (others => '0');
vgaGreen <= (others => '0');
end if;
end if;
end process;
process(clk_65MHz)
begin
if clk_65MHz'event and clk_65MHz = '1' then
-- Gestion du vga
-- Syncro horizontale
if Hcount < 1025 then
-- affichage
Hsync <= '1';
Hcount <= Hcount + 1;
elsif Hcount < 1049 then
-- Fp
Hsync <= '1';
Hcount <= Hcount + 1;
elsif Hcount < 1185 then
-- Pw
Hsync <= '0';
Hcount <= Hcount + 1;
elsif Hcount < 1344 then
-- Bp
Hsync <= '1';
Hcount <= Hcount + 1;
else
Hcount <= 1;
end if;
-- Synchro vertical
if Vcount < 1032193 then
-- Affichage de toutes les lignes
Vsync <= '1';
Vcount <= Vcount + 1;
elsif Vcount < (1032193 + 4032) then
--Fp
Vsync <= '1';
Vcount <= Vcount + 1;
elsif Vcount < (1032193 + 4032 + 8064) then
--Pw
Vsync <= '0';
Vcount <= Vcount + 1;
elsif Vcount < (1032192 + 4032 + 8064 + 38976) then
--Bp
Vsync <= '1';
Vcount <= Vcount + 1;
else
Vcount <= 1;
end if;
end if;
end process;
end Behavioral;