File reading issue

D

Dkthechamp

Guest
Hi,
i am trying to read a txt file with binary strings as content but the
snippet written below reads only one line, wheras the txt file has
many entries. The "output" is of type std_logic_vector with the same
length of 's'.

Thanks in advance.
DK

-- snippet
FILE inFile : TEXT open read_mode is "tb.txt";

VARIABLE inLine : LINE;
VARIABLE s : std_logic_vector(159 downto 0);

begin
if(clock'event and clock='1') then
while (not endfile(inFile)) loop
readline(inFile, inLine);
read(inLine,s);
output <= s after 10 ns;

end loop;
end if;
 
snippet written below reads only one line, wheras the txt file has
many entries.
Is this a last line of tb.txt file?

FILE inFile : TEXT open read_mode is "tb.txt";

VARIABLE inLine : LINE;
VARIABLE s : std_logic_vector(159 downto 0);

begin
if(clock'event and clock='1') then
while (not endfile(inFile)) loop
readline(inFile, inLine);
read(inLine,s);
output <= s after 10 ns;

end loop;
end if;
I think that problem is that at first rising edge you read whole file in
while loop. In my opinion u should use 'if (not endfile(inFile)) then'
instead 'while (not endfile(inFile)) loop' When you will use 'if' every
rising edge of clk you will read new line of tb.txt file.


Best Regards
Macias
 
"Dkthechamp" <dkthechamp@gmail.com> a écrit dans le message de news: 1185956444.243739.238200@22g2000hsm.googlegroups.com...
Hi,
i am trying to read a txt file with binary strings as content but the
snippet written below reads only one line, wheras the txt file has
many entries. The "output" is of type std_logic_vector with the same
length of 's'.

Thanks in advance.
DK

-- snippet

you forget a WAIT statement in the while loop so
the whole file is read at the same time instant.

Try the following code

FILE inFile : TEXT open read_mode is "tb.txt";

VARIABLE inLine : LINE;
VARIABLE s : std_logic_vector(159 downto 0);

begin

while (not endfile(inFile)) loop

readline(inFile, inLine);
read(inLine,s);
output <= s after 10 ns;

wait for clk'event and clk = '1' ;

end loop;

wait;

end
 
On Aug 1, 11:54 am, "ast" <a...@ast.com> wrote:
"Dkthechamp" <dkthech...@gmail.com> a écrit dans le message de news: 1185956444.243739.238...@22g2000hsm.googlegroups.com...

Hi,
i am trying to read a txt file with binary strings as content but the
snippet written below reads only one line, wheras the txt file has
many entries. The "output" is of type std_logic_vector with the same
length of 's'.

Thanks in advance.
DK

-- snippet

you forget a WAIT statement in the while loop so
the whole file is read at the same time instant.

Try the following code

FILE inFile : TEXT open read_mode is "tb.txt";

VARIABLE inLine : LINE;
VARIABLE s : std_logic_vector(159 downto 0);

begin

while (not endfile(inFile)) loop

readline(inFile, inLine);
read(inLine,s);
output <= s after 10 ns;

wait for clk'event and clk = '1' ;

end loop;

wait;

end
Thanks for responses. The solution by Macias works perfectly but 2nd
solutions shows error "wait for clk'event and clk = '1' ; " is not a
time expression.

Its reading the bits now :)

Thanks
 
On Aug 1, 7:25 am, Dkthechamp <dkthech...@gmail.com> wrote:
On Aug 1, 11:54 am, "ast" <a...@ast.com> wrote:



"Dkthechamp" <dkthech...@gmail.com> a écrit dans le message de news: 1185956444.243739.238...@22g2000hsm.googlegroups.com...

Hi,
i am trying to read a txt file with binary strings as content but the
snippet written below reads only one line, wheras the txt file has
many entries. The "output" is of type std_logic_vector with the same
length of 's'.

Thanks in advance.
DK

-- snippet

you forget a WAIT statement in the while loop so
the whole file is read at the same time instant.

Try the following code

FILE inFile : TEXT open read_mode is "tb.txt";

VARIABLE inLine : LINE;
VARIABLE s : std_logic_vector(159 downto 0);

begin

while (not endfile(inFile)) loop

readline(inFile, inLine);
read(inLine,s);
output <= s after 10 ns;

wait for clk'event and clk = '1' ;

end loop;

wait;

end

Thanks for responses. The solution by Macias works perfectly but 2nd
solutions shows error "wait for clk'event and clk = '1' ; " is not a
time expression.

Its reading the bits now :)

Thanks
wait UNTIL rising_edge(clk);

Andy
 
On Aug 1, 4:45 pm, Andy <jonesa...@comcast.net> wrote:
On Aug 1, 7:25 am, Dkthechamp <dkthech...@gmail.com> wrote:



On Aug 1, 11:54 am, "ast" <a...@ast.com> wrote:

"Dkthechamp" <dkthech...@gmail.com> a écrit dans le message de news: 1185956444.243739.238...@22g2000hsm.googlegroups.com...

Hi,
i am trying to read a txt file with binary strings as content but the
snippet written below reads only one line, wheras the txt file has
many entries. The "output" is of type std_logic_vector with the same
length of 's'.

Thanks in advance.
DK

-- snippet

you forget a WAIT statement in the while loop so
the whole file is read at the same time instant.

Try the following code

FILE inFile : TEXT open read_mode is "tb.txt";

VARIABLE inLine : LINE;
VARIABLE s : std_logic_vector(159 downto 0);

begin

while (not endfile(inFile)) loop

readline(inFile, inLine);
read(inLine,s);
output <= s after 10 ns;

wait for clk'event and clk = '1' ;

end loop;

wait;

end

Thanks for responses. The solution by Macias works perfectly but 2nd
solutions shows error "wait for clk'event and clk = '1' ; " is not a
time expression.

Its reading the bits now :)

Thanks

wait UNTIL rising_edge(clk);

Andy
Thanks it works now :)
 

Welcome to EDABoard.com

Sponsor

Back
Top