153rd
Member level 1
Reading text, and writing it to a memory block in VHDL
Hi,
I'm trying to do the following: Reading text(file: GPUdata.txt), writing it to memory, wich will be used to create a 800 x 640 image on a monitor.
I'm having difficulties reading the txtfile/ writing it to a memory block.
For reading text, I wrote the function below:
------------------------------------------------------
-- Read text from GPUdata.txt --
impure function ReadText(Filename : in string) return RAMTYPE is
variable MEM_DATA : RAMTYPE;--std_logic_vector(95 downto 0);
Variable L : line;
Variable i : integer := 0;
File Datafile : text open read_mode is Filename;
begin
if write_en = '1' then
while not((endfile(Datafile))) loop
Readline(Datafile, L);
Read(L, MEM_DATA(i));
i := i +1;
return mem_data;
end loop;
end if;
return mem_data;
File_close(Datafile);
end function;
------------------------------------------------------
When I write this to memory, I see that ONLY the first line in my textfile has beeen written to my memory block.
I've been looking up some examples on the internet, but I can't see where my mistake is. Below you can see my RAM description:
type RAMTYPE is array(15 downto 0) of std_logic_vector(95 downto 0);
signal RAM:RAMTYPE;
signal RD_ADDR_REG: std_logic_vector(3 downto 0);
begin
process(CLK)
begin
if rising_edge(clk) then
if write_en = '1' then
RAM(to_integer(unsigned(Write_addr))) <= ReadText("GPUdata.txt")(to_integer(unsigned(Write_addr)));--RAM(to_integer(unsigned(Write_addr)))
--else data_out <= RAM(to_integer(unsigned(read_addr)));
end if;
RD_ADDR_REG <= Read_ADDR;
end if;
end process;
--data_out <= RAM (to_integer(unsigned(Read_addr)));
-- The noob way:
process(CLK, write_addr)--, write_data_buffer)
begin
if rising_edge(CLK) then
case read_addr is
when "0000" => data_out <= RAM(0);
when "0001" => data_out <= RAM(1);-- Only this spot is written, the rest stays undefined
when "0010" => data_out <= RAM(2);
when "0011" => data_out <= RAM(3);
when "0100" => data_out <= RAM(4);
when "0101" => data_out <= RAM(5);
when "0110" => data_out <= RAM(6);
when "0111" => data_out <= RAM(7);
when "1000" => data_out <= RAM(8);
when "1001" => data_out <= RAM(9);
when "1010" => data_out <= RAM(10);
when "1011" => data_out <= RAM(11);
when "1100" => data_out <= RAM(12);
when "1101" => data_out <= RAM(13);
when "1110" => data_out <= RAM(14);
when others => data_out <= RAM(15);
end case;
end if;
end process;
Does anyone see where my mistake is?
Hi,
I'm trying to do the following: Reading text(file: GPUdata.txt), writing it to memory, wich will be used to create a 800 x 640 image on a monitor.
I'm having difficulties reading the txtfile/ writing it to a memory block.
For reading text, I wrote the function below:
------------------------------------------------------
-- Read text from GPUdata.txt --
impure function ReadText(Filename : in string) return RAMTYPE is
variable MEM_DATA : RAMTYPE;--std_logic_vector(95 downto 0);
Variable L : line;
Variable i : integer := 0;
File Datafile : text open read_mode is Filename;
begin
if write_en = '1' then
while not((endfile(Datafile))) loop
Readline(Datafile, L);
Read(L, MEM_DATA(i));
i := i +1;
return mem_data;
end loop;
end if;
return mem_data;
File_close(Datafile);
end function;
------------------------------------------------------
When I write this to memory, I see that ONLY the first line in my textfile has beeen written to my memory block.
I've been looking up some examples on the internet, but I can't see where my mistake is. Below you can see my RAM description:
type RAMTYPE is array(15 downto 0) of std_logic_vector(95 downto 0);
signal RAM:RAMTYPE;
signal RD_ADDR_REG: std_logic_vector(3 downto 0);
begin
process(CLK)
begin
if rising_edge(clk) then
if write_en = '1' then
RAM(to_integer(unsigned(Write_addr))) <= ReadText("GPUdata.txt")(to_integer(unsigned(Write_addr)));--RAM(to_integer(unsigned(Write_addr)))
--else data_out <= RAM(to_integer(unsigned(read_addr)));
end if;
RD_ADDR_REG <= Read_ADDR;
end if;
end process;
--data_out <= RAM (to_integer(unsigned(Read_addr)));
-- The noob way:
process(CLK, write_addr)--, write_data_buffer)
begin
if rising_edge(CLK) then
case read_addr is
when "0000" => data_out <= RAM(0);
when "0001" => data_out <= RAM(1);-- Only this spot is written, the rest stays undefined
when "0010" => data_out <= RAM(2);
when "0011" => data_out <= RAM(3);
when "0100" => data_out <= RAM(4);
when "0101" => data_out <= RAM(5);
when "0110" => data_out <= RAM(6);
when "0111" => data_out <= RAM(7);
when "1000" => data_out <= RAM(8);
when "1001" => data_out <= RAM(9);
when "1010" => data_out <= RAM(10);
when "1011" => data_out <= RAM(11);
when "1100" => data_out <= RAM(12);
when "1101" => data_out <= RAM(13);
when "1110" => data_out <= RAM(14);
when others => data_out <= RAM(15);
end case;
end if;
end process;
Does anyone see where my mistake is?
Last edited: