Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Electronic Equipment > VHDL > Re: reading an ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 11 Topic 6091 of 6417
Post > Topic >>

Re: reading an array of parallel input data

by Jonathan Bromley <jonathan.bromley@[EMAIL PROTECTED] > Jun 19, 2008 at 11:53 AM

On Thu, 19 Jun 2008 03:05:15 -0700 (PDT), koyel.aphy@[EMAIL PROTECTED]
 wrote:

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

Choose a format that's easy to handle with VHDL's rather limited
string functions, but also can be easily manipulated by external
software.  Comma-separated values (CSV) are a good choice, since 
they are fairly easy to handle in VHDL but also work nicely with
spreadsheets and other programs - and they're human-readable.

Since your data are only 10 bits wide, it seems natural to 
represent them as simple (decimal) integers.  Each line
of your CSV file then looks like

  25,1021,42,0,1000,58,1,76

You can simply work through the input file in VHDL until you
reach end-of-file.

It will also be OK if you permit spaces before the integers:

  25, 1021, 42, 0, 1000, 58, 1, 76

since read() automatically skips over these spaces.  Don't allow 
spaces before the comma, though - that would need extra work.

Here's a piece of VHDL code that should be able to read such 
data into a signal that's an array of 10-bit std_logic_vector.
Testing and debugging is left as an exercise :-)
In the real world you would also want a great deal more 
error checking than I have provided.  Note that both
file_open() and read() have options to check for success;
if you don't use these options, then they will simply
fail with a fatal error if anything goes wrong.

  use ieee.std_logic_1164.all, ieee.numeric_std.all;
  ...
  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;
  ...
  process ReadAndApply;
    variable c: character;
    variable i: integer;
    variable L: line;
  begin
    file_open(StimCSV, "my/file/name.csv", READ_MODE);
    while not endfile(StimCSV) loop
      wait until .... you need some more stimulus ....
      readline(StimCSV, L);   -- Get the next stimulus line
      for j in s'range loop
        read(L, i);    -- Get the next integer
        if j /= s'right then
          -- it's not the last item; skip the next comma
          read(L, c);  
          assert c = ',' re****t "Oops, bad separator";
        end if;
        stimulus(j) <= std_logic_vector(
                          to_unsigned(i, slv10'length));
      end loop;
    end loop;
    file_close(StimCSV);
    wait;
  end process;


hth
-- 
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@[EMAIL PROTECTED]
 contents of this message may contain personal views which 
are not the views of Doulos Ltd., unless specifically stated.
 




 11 Posts in Topic:
reading an array of parallel input data
koyel.aphy@[EMAIL PROTECT  2008-06-19 03:05:15 
Re: reading an array of parallel input data
Jonathan Bromley <jona  2008-06-19 11:53:34 
Re: reading an array of parallel input data
koyel.aphy@[EMAIL PROTECT  2008-06-25 04:41:53 
Re: reading an array of parallel input data
Jonathan Bromley <jona  2008-06-25 13:37:30 
Re: reading an array of parallel input data
koyel.aphy@[EMAIL PROTECT  2008-06-26 05:18:42 
Re: reading an array of parallel input data
Jonathan Bromley <jona  2008-06-26 13:40:04 
Re: reading an array of parallel input data
koyel.aphy@[EMAIL PROTECT  2008-06-26 07:34:39 
Re: reading an array of parallel input data
koyel.aphy@[EMAIL PROTECT  2008-06-27 06:34:39 
Re: reading an array of parallel input data
Jonathan Bromley <jona  2008-06-27 15:19:25 
Re: reading an array of parallel input data
koyel.aphy@[EMAIL PROTECT  2008-06-27 10:43:19 
Re: reading an array of parallel input data
koyel.aphy@[EMAIL PROTECT  2008-06-27 10:47:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 14:53:16 CST 2008.