File reading issue

Discussion in 'VHDL' started by Dkthechamp, Aug 1, 2007.

  1. Dkthechamp

    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;
     
    Dkthechamp, Aug 1, 2007
    #1
    1. Advertising

  2. > 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
     
    Macias Wojtas, Aug 1, 2007
    #2
    1. Advertising

  3. Dkthechamp

    ast Guest

    "Dkthechamp" <> a écrit dans le message de news: ...
    > 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
     
    ast, Aug 1, 2007
    #3
  4. Dkthechamp

    Dkthechamp Guest

    On Aug 1, 11:54 am, "ast" <> wrote:
    > "Dkthechamp" <> a écrit dans le message de news: ...
    >
    > > 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
     
    Dkthechamp, Aug 1, 2007
    #4
  5. Dkthechamp

    Andy Guest

    On Aug 1, 7:25 am, Dkthechamp <> wrote:
    > On Aug 1, 11:54 am, "ast" <> wrote:
    >
    >
    >
    > > "Dkthechamp" <> a écrit dans le message de news: ...

    >
    > > > 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
     
    Andy, Aug 1, 2007
    #5
  6. Dkthechamp

    Dkthechamp Guest

    On Aug 1, 4:45 pm, Andy <> wrote:
    > On Aug 1, 7:25 am, Dkthechamp <> wrote:
    >
    >
    >
    > > On Aug 1, 11:54 am, "ast" <> wrote:

    >
    > > > "Dkthechamp" <> a écrit dans le message de news: ...

    >
    > > > > 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 :)
     
    Dkthechamp, Aug 2, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darrel
    Replies:
    3
    Views:
    679
    Kevin Spencer
    Nov 11, 2004
  2. Shane
    Replies:
    7
    Views:
    372
    Shane
    Aug 23, 2004
  3. John

    reading text file issue

    John, Jun 2, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    346
    Cowboy \(Gregory A. Beamer\)
    Jun 2, 2006
  4. Replies:
    0
    Views:
    787
  5. Karim Ali

    Reading a file and resuming reading.

    Karim Ali, May 25, 2007, in forum: Python
    Replies:
    2
    Views:
    375
    Hrvoje Niksic
    May 25, 2007
Loading...

Share This Page