【问题标题】:How to load a text file on a ram in VHDL?如何在 VHDL 中的 ram 上加载文本文件?
【发布时间】:2016-02-24 16:33:48
【问题描述】:

我有一个描述图像的 RGB 组件的文本文件,我想将该文件加载到 FPGA 上以产生 RGB 信号,所以如果您能启发我,我将不胜感激

好吧,这就是我想出的,但是合成需要永远完成一个问题,所以你认为这里的问题是什么??!

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use STD.TEXTIO.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 primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity RGB_Gen is

  port(CLK : in STD_LOGIC;
       EN : in STD_LOGIC;
         R,G,B : out STD_LOGIC);

end RGB_Gen;

architecture Behavioral of RGB_Gen is

  Type ram is array (0 to 611) of BIT_VECTOR(203 downto 0);

  impure function InitRamFromFile(Filename : in string) return ram is

   File readFile : text is in Filename;
   Variable lineRead : Line;
    Variable my_ram : ram;

    begin

      for i in ram'range loop
         readline(readFile, lineRead);
         read(lineRead, my_ram(i));
     end loop;

     return my_ram;

  end function;

  function toSTD(B : in Bit) return STD_LOGIC is
  begin    
        if B = '1' then 
           return '1';
        else 
           return '0';
      end if;
  end function;

  Signal my_ram : ram := InitRamFromFile("C:\Users\Mos_X\Desktop\output.txt");

  begin

    process(CLK)

     Variable X : Integer := 0;
     Variable Y : Integer := 0;

     begin

     if rising_edge(CLK) then
       if EN = '0' then 
          R <= '0';
            G <= '0';
            B <= '0';
        else 
           R <= toSTD((my_ram(Y)(X)));
            G <= toSTD((my_ram(Y + 204)(X)));
            G <= toSTD((my_ram(Y + 408)(X)));       
        end if;

       if X = 203 then 
           X := 0;
         if Y = 203 then 
            Y := 0;
         else
            Y := Y + 1;
           end if;
        else 
           X := X + 1;
        end if;

    end if;

 end process;

end Behavioral;

【问题讨论】:

  • 如果合成速度很慢,您会要求它做一些困难的事情,即具有 204 位宽端口的三端口 RAM (ROM)。您有一个包含三个 204 位到 1 位多路复用器的进程。考虑三个 1 位宽的 RAM (ROM) 或浪费一点内存并使用 4 位宽的东西。
  • 有没有办法将行读取转换为 STD_LOGIC_VECTOR ?我认为我在那里使用 read(lineRead, my_ram(i)) 所做的事情是不正确的。合成问题现在对我来说不是什么大问题,我的首要任务是让它发挥作用。
  • 您在从 RAM 读取时分配了两次 G。这是故意的吗?您使用的是哪种合成工具?

标签: text vhdl rgb ram


【解决方案1】:

所以问题是代码中的两个计数器正在递增,即使启用信号为 0 也会导致静态,所以这个

 if rising_edge(CLK) then
       if EN = '0' then 
          R <= '0';
            G <= '0';
            B <= '0';
        else 
           R <= toSTD((my_ram(Y)(X)));
            G <= toSTD((my_ram(Y + 204)(X)));
            G <= toSTD((my_ram(Y + 408)(X)));   

           if X = 203 then 
              X := 0;
            if Y = 203 then 
               Y := 0;
            else
            Y := Y + 1;
              end if;
          else 
                 X := X + 1;
          end if;
       end if;  
    end if;

而不是这个

 if rising_edge(CLK) then
       if EN = '0' then 
          R <= '0';
            G <= '0';
            B <= '0';
        else 
           R <= toSTD((my_ram(Y)(X)));
            G <= toSTD((my_ram(Y + 204)(X)));
            G <= toSTD((my_ram(Y + 408)(X)));       
        end if;

       if X = 203 then 
           X := 0;
         if Y = 203 then 
            Y := 0;
         else
            Y := Y + 1;
           end if;
        else 
           X := X + 1;
        end if;

    end if;

会解决问题

【讨论】:

  • 问题在您的问题中并不明显。在标题i How to load a text file on a ram in VHDL? 中,您添加了自己加载 ram 的方法。 Okey 所以这就是我想出的,但是合成需要永远完成一个问题,所以你认为这里的问题是什么??!,在哪里你甚至没有指出问题是什么。你问如何合成这个?您的回答解决了以下哪个问题?
  • 在我编写所有这些代码之前,我想知道将文本文件的内容加载到 fpga 内存中的最有效方法是什么,但是因为你们都认为这个问题太宽泛了,我不知道看到这种方式,我继续说出我的想法并试图从中得到结果,最后我将图像显示在屏幕上,但合成时间约为 5-10 分钟
猜你喜欢
  • 1970-01-01
  • 2022-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多