2 D array initialization

Discussion in 'VHDL' started by mk.supriya@gmail.com, Jul 25, 2007.

  1. Guest

    hello,
    can anyone tell me how to read from / write to a 2D array from a file?
    , Jul 25, 2007
    #1
    1. Advertising

  2. KJ Guest

    <> wrote in message
    news:...
    > hello,
    > can anyone tell me how to read from / write to a 2D array from a file?
    >

    By writing your own procedure that reads from / writes to each element one
    at a time.

    KJ
    KJ, Jul 25, 2007
    #2
    1. Advertising

  3. Guest


    > By writing your own procedure that reads from / writes to each element one
    > at a time.
    >
    > KJ


    i am not able to access the elements, every type of assignment i make
    i get an error
    , Jul 25, 2007
    #3
  4. On Wed, 25 Jul 2007 05:08:24 -0700, wrote:

    >i am not able to access the elements, every type of assignment i make
    >i get an error


    How can anyone possibly help you from this non-description?
    *I* can access the elements of a 2-D array, and do so routinely.
    There is no fundamental problem. Show us a code fragment and
    we'll try to help with YOUR problem.

    A few guesses...
    - you're using the wrong kind of double-subscript:
    depending on how you defined the array, you may need
    to use subscripts like (row,column) or (row)(column)
    - the array is a signal, and you are trying to pass
    elements of it to the READ procedures; those
    procedures expect variables
    Without seeing your code and the error message, these
    can only be guesses.
    --
    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

    http://www.MYCOMPANY.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
    Jonathan Bromley, Jul 25, 2007
    #4
  5. Guest

    > How can anyone possibly help you from this non-description?
    > *I* can access the elements of a 2-D array, and do so routinely.
    > There is no fundamental problem. Show us a code fragment and
    > we'll try to help with YOUR problem.
    >
    > A few guesses...
    > - you're using the wrong kind of double-subscript:
    > depending on how you defined the array, you may need
    > to use subscripts like (row,column) or (row)(column)
    > - the array is a signal, and you are trying to pass
    > elements of it to the READ procedures; those
    > procedures expect variables
    > Without seeing your code and the error message, these
    > can only be guesses.
    > --
    > 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
    > ://www.MYCOMPANY.com
    >
    > The contents of this message may contain personal views which
    > are not the views of Doulos Ltd., unless specifically stated.

    hello,
    when i ran the following code, it assigns 1 to each and every element
    in the array tout.
    instead of write(my_file,'1'), suppose i have defined an array of
    bit_vector(0 to 7) if i give write(my_file,x"04") it gives fatal error
    in XST
    package arr is
    type row is array (0 to 7) of character;
    type mat is array (0 to 7) of row;
    end arr;

    use work.arr.all;

    entity arrfile is
    port ( tout: out mat);
    end arrfile;

    architecture ARCH of arrfile is
    begin
    process is
    type ch_file is file of character;
    file my_file : ch_file;
    constant file_name : string := "testfile4.txt";
    --constant matrix : mat := ((0,1) => 'a', (1,0)=> 'c', others => '0');
    variable my_char : character;
    begin
    file_open(my_file, file_name, write_mode);
    for i in 0 to 7 loop
    for j in 0 to 7 loop
    write(my_file, '1');
    end loop;
    end loop;
    file_close(my_file);
    wait for 2 ns;
    file_open(my_file, file_name, read_mode);
    for i in 0 to 7 loop
    for j in 0 to 7 loop
    read(my_file, my_char);
    tout(i)(j) <= my_char;
    end loop;
    end loop;
    file_close(my_file);
    end process;
    end ARCH;
    , Jul 25, 2007
    #5
  6. Guest

    is bit_vector(0 to 7)not equivalent to character?
    if i define the file as a file of characters, why am i not able to get
    data into a bit_vector?
    , Jul 25, 2007
    #6
  7. wrote:
    > is bit_vector(0 to 7)not equivalent to character?


    No.
    character is a scaler type.
    bit vector is an array type.

    > if i define the file as a file of characters, why am i not able to get
    > data into a bit_vector?


    I could write a function to make such a conversion.
    Here is a related example:

    function int2sgn (arg : integer) return signed is
    subtype vec_t is signed(127 downto 0);
    variable arg_v : vec_t := to_signed(arg, vec_t'length);
    constant min_c : natural := min_len_sgn(arg);
    subtype this_sgn_t is signed(min_c -1 downto 0);
    begin
    return arg_v(this_sgn_t'range);
    end function int2sgn;

    Details here:
    http://home.comcast.net/~mike_treseler/

    -- Mike Treseler
    Mike Treseler, Jul 25, 2007
    #7
  8. a écrit :

    > hello,
    > when i ran the following code, it assigns 1 to each and every element
    > in the array tout.
    > instead of write(my_file,'1'), suppose i have defined an array of
    > bit_vector(0 to 7) if i give write(my_file,x"04") it gives fatal error
    > in XST


    Hi
    So you are tring to *synthesize* this ? No wonder it doesn't work, I
    don't know of *any* synthesis tool that supports file access.

    Nicolas
    Nicolas Matringe, Jul 25, 2007
    #8
  9. Guest


    >
    > Hi
    > So you are tring to *synthesize* this ? No wonder it doesn't work, I
    > don't know of *any* synthesis tool that supports file access.
    >
    > Nicolas


    no i wasnt synthesising it, i was simulating using xilinx simulator,
    thanks to Mr Mike and Mr.Jonathan i now have an idea as to what to do.
    thanks again
    , Jul 26, 2007
    #9
    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. JKop
    Replies:
    10
    Views:
    944
  2. Matthias Kaeppler
    Replies:
    2
    Views:
    441
    Victor Bazarov
    Jul 18, 2005
  3. Replies:
    6
    Views:
    459
    Ron Natalie
    Dec 11, 2005
  4. toton
    Replies:
    5
    Views:
    934
    Victor Bazarov
    Sep 28, 2006
  5. aaragon
    Replies:
    2
    Views:
    618
    James Kanze
    Nov 2, 2008
Loading...

Share This Page