Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > File reading issue

Reply
Thread Tools

File reading issue

 
 
Dkthechamp
Guest
Posts: n/a
 
      08-01-2007
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;

 
Reply With Quote
 
 
 
 
Macias Wojtas
Guest
Posts: n/a
 
      08-01-2007
> 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


 
Reply With Quote
 
 
 
 
ast
Guest
Posts: n/a
 
      08-01-2007

"Dkthechamp" <> a écrit dans le message de news: om...
> 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



 
Reply With Quote
 
Dkthechamp
Guest
Posts: n/a
 
      08-01-2007
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.c om...
>
> > 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

 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      08-01-2007
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.c om...

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

 
Reply With Quote
 
Dkthechamp
Guest
Posts: n/a
 
      08-02-2007
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.c om...

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading a file and resuming reading. Karim Ali Python 2 05-25-2007 02:04 PM
UnauthorizedAccessException when reading XML files (no problem when reading other file-types) blabla120@gmx.net ASP .Net 0 09-15-2006 02:08 PM
reading text file issue John ASP .Net 1 06-02-2006 12:23 PM
reading the DB vs. reading a text file...performance preference? Darrel ASP .Net 3 11-11-2004 02:27 PM
Help with simple file reading issue please Shane C++ 7 08-23-2004 05:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57