我目前正在尝试在 VHDL 中创建一个屏幕缓冲区(用于通过 VGA 发送视频数据的设备)。我正在使用 Xilinx ISE 13.1,我是 VHDL 的初学者。
我的想法是创建一个包含每个像素的 RGB 值(8 位)的大型二维数组。
我可以毫无问题地写入数组,但是当我必须读取它时变得更加复杂:合成变得非常长,而 XST 只是完全饱和内存,直到计算机自行关闭。
这是我的代码的简化版本,只是想画一条红色的 45° 线:
entity Pilotage_ecran is
port(clk25 : in std_logic; --25MHz clock
red_out : out std_logic; --Untill the problem is solved, i use only 1 bit to set colors
green_out : out std_logic;
blue_out : out std_logic;
hs_out : out std_logic;
vs_out : out std_logic);
end Pilotage_ecran;
architecture Behavioral of Pilotage_ecran is
signal horizontal_counter : std_logic_vector (9 downto 0);
signal vertical_counter : std_logic_vector (9 downto 0);
signal drawing : std_logic; --Signal that is set to 1 when the active video area is reached
signal busy : std_logic; --Signal to avoid launching the drawing process twice in parallel
--The array (actually containing single bits instead of vectors untill I solve the problem)
type TAB_BUFFER is array(0 to 1023, 0 to 1023) of std_logic;
signal Ecran : TAB_BUFFER := (others=>'0');
begin
主要工艺:
process (clk25)
variable coordX : integer;
variable coordY : integer;
begin
if clk25'event and clk25 = '1' then
if (horizontal_counter >= "0010010000" ) -- 144 : limits of active video area
and (horizontal_counter < "1100010000" ) -- 784
and (vertical_counter >= "0000100111" ) -- 39
and (vertical_counter < "1100010000" ) -- 519
then
drawing <= '1';
coordX := conv_integer (horizontal_counter);
coordY := conv_integer (vertical_counter);
if Ecran(coordX,coordY) = '1' then --Here is the problem
red_out <= '1';
green_out <= '0';
blue_out <= '0';
else
red_out <= '0';
green_out <= '0';
blue_out <= '0';
end if;
else
drawing <= '0';
end if;
--Hsync and Vsync come after, but the code is safe and tested
end if;
end process;
绘图过程(实际上以丑陋的方式绘制一条线,但我只想在缓冲区中获取任何内容)。
draw :
process (drawing, clk25, busy)
--Coordinates of the starting point (actually random values...)
variable i : integer;
variable j : integer;
begin
if (drawing = '1') and clk25 = '1' and busy = '0' then
busy <= '1';
i :=300;
j :=300;
--The loop setting the coordinates of the line to '1'
loopx : while (i<=350) loop
Ecran(i,j) <= '1';
i := i+1;
j := j+1;
end loop loopx;
busy <='0';
end if;
end process draw;
end Behavioral;
给我带来麻烦的那一行是我尝试访问缓冲区中某些坐标处的值的那一行:
如果 Ecran(coordX,coordY) = '1' 那么
我也尝试这样做:
red_out <= Ecran(coordX,coordY);
如果我用整数值替换 coordX 或 coordY 之一,它工作正常(显示与缓冲区不匹配,但它工作),但如果我对它们都使用变量,它会在合成过程中崩溃。我很确定我对数组做错了什么(我刚刚学会了如何使用它们),即使它似乎与一些工作代码匹配。我也可能(并且可能)使用过大的数组。
如果有人知道我做错了什么,或者对如何在 vhdl 中创建屏幕缓冲区有更好的方法,我们将不胜感激。
非常感谢您提前。