File reading issue

D

Dkthechamp

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;
 
M

Macias Wojtas

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
 
A

ast

Dkthechamp said:
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
 
D

Dkthechamp

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
 
A

Andy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top