reading an array of parallel input data

K

koyel.aphy

Hi,

Thanks first of all for the previous responses that have been of great
help to me.
I have to write another test bench for a unit that takes on 8 inputs
(each of 10 bits)parallely. There will be an array of minimum of 1024
such elements(integer number of 1024 in general) in the data file.
What should be the format of the data file and how should be the
reading operation in VHDL. It's similar to corner memory where we
input data horizontally and read out vertically.

thanks.
 
K

koyel.aphy

"for j in s'range loop
read(L, i); -- Get the next integer
if j /= s'right then"


what is s and /= here?
 
K

koyel.aphy

Hi,

Here is what I am able to edit when I got few errors though there seem
to be no reason for those. But now I am getting undefined values at
the output and I checked that the stimulus signal is not taking the
values. I don't want to change this code much so it would be good if
you can see if I have missed something.

ReadAndApply:process
variable c: character;
variable i: integer;
variable L: line;
begin
file_open(StimCSV, "StimCSV.csv", READ_MODE);
wait until (clk'event and clk = '1');

if not endfile(StimCSV) and res= '1' and reset2 = '1' then

readline(StimCSV, L); -- Get the next stimulus line
for j in stimulus'range loop
read(L, i); -- Get the next integer
if j /= stimulus'right then
-- it's not the last item; skip the next comma
read(L, c);
assert c = ',' report "Oops, bad separator";
end if;
stimulus(j) <= std_logic_vector(
to_unsigned(i, WORD8'length));
end loop;
din <= stimulus;
end if;
file_close(StimCSV);
wait;
end process;
dout1 <= doutf1;
dout2 <= doutf2;

Thank you vary much again!
 
K

koyel.aphy

Here is what I am able to edit when I got few errors though there seem
to be no reason for those.

I have no idea what you mean.  When I tried out my own code
just now I found a few silly errors that prevented it from
compiling; it took me about a minute to fix them.  
What's the problem?
But now I am getting undefined values [...]
I don't want to change this code much

Why not?  You'll learn far more if you *do* change it.
Hack around, add plenty of diagnostics, try things out,
see what happens, until you are confident that you
know how to do it all for yourself.


ReadAndApply:process
   variable c: character;
   variable i: integer;
   variable L: line;
 begin
   file_open(StimCSV, "StimCSV.csv", READ_MODE);
    wait until (clk'event and clk = '1'); [...]
           din <= stimulus;
           end if;
   file_close(StimCSV);
   wait;

You're OK with just getting exactly one line of stimulus
from the file?  Doesn't sound very interesting to me.

Since you don't seem to want to debug for yourself,
here's my code fully debugged and working.  I didn't
need to change very much.  I've put in some fixed
time delays so that you can see the values on signal
"stimulus" in a wave viewer.

entity read_csv_test is end;

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;

architecture A of read_csv_test is

  subtype slv10 is std_logic_vector(9 downto 0);
  type arr_slv10 is array(natural range <>) of slv10;

  signal stimulus: arr_slv10(0 to 7);
  file StimCSV: text;

begin

  ReadAndApply: process
    variable c: character;
    variable i: integer;
    variable L: line;
  begin
    file_open(StimCSV, "test.csv", READ_MODE);
    while not endfile(StimCSV) loop
      wait for 10 ns;
      readline(StimCSV, L);   -- Get the next stimulus line
      for j in stimulus'range loop
        read(L, i);    -- Get the next integer
        if j /= stimulus'right then
          -- it's not the last item; skip the next comma
          read(L, c);
          assert c = ',' report "Oops, bad separator";
        end if;
        stimulus(j) <= std_logic_vector(
                          to_unsigned(i, slv10'length));
      end loop;
    end loop;
    file_close(StimCSV);
    wait for 20 ns;
    wait;
  end process;

end;

Okay, the test bench has more than this part so that can also be the
reason for my wrong outputs. No I am not interested to read one line.
Sorry I forgot to include the count to be incremented for not using a
loop. However, I will now use the loop instead. I was not sure if I
can use the clock'event statement under loop and if all the statements
for one line in the input file will be executed for one clock pulse
then. That's all.
 
K

koyel.aphy

This is what I am using right now and I get the errors

Error at 30.000 ns(1): Textio read:: called on empty string or line
at 30.000 ns(1): Error: Oops, bad separator
this continues upto 100 ns.

even if I do not use the clock, I get the same errors. I have checked
the simulation in modelsim without the testbench that gives correct
result.


ReadAndApply: process
variable c: character;
variable i: integer;
variable L: line;
begin
file_open(StimCSV, "StimCSV.csv", READ_MODE);
while not endfile(StimCSV) loop
wait until(clk'event and clk = '1') and reset2 ='1';
readline(StimCSV, L); -- Get the next stimulus line
for j in stimulus'range loop
read(L, i); -- Get the next integer
if j /= stimulus'right then
-- it's not the last item; skip the next comma
read(L, c);
assert c = ',' report "Oops, bad separator";
end if;
stimulus(j) <= std_logic_vector(
to_unsigned(i, word10'length));
end loop;
din<= stimulus;
end loop;
file_close(StimCSV);
wait for 20 ns;
wait;
end process;
 
K

koyel.aphy

Thank you very much for all the information so much.

It worked out ultimately.

Yours sincerely.
 
K

koyel.aphy

Thanks a lot for all the information so far!

It worked out ultimately.
no more annoying questions :)

Best Regards
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top