Results 1 to 6 of 6

Thread: Array in VHDL

  1. #1
    Join Date
    Aug 2008
    Posts
    50

    Array in VHDL

    Can i assign a std_logic vector to array of same bits?

    suppose..
    Code:
    signal vec:std_logic_vector(15 downto 0);
    type arr is array(o to 3) of std_logic_vector(0 to 3);
    ....
    arr <= vec;
    above mentioned code is right or wrong, if wrong is there any other way to assign std_logic_vector to array.

  2. #2
    Join Date
    May 2008
    Posts
    2,012
    There are 3 errors in your code. Since vec is a 16-bit vector you cannot assign it to a 4-bit vector. When you assign a vector to an array of vectors you must specify an index. Also, you created the type arr, but did not declare a signal of that type. You can't make an assignment to a type. The following example may help.

    Code:
    type arr is array(0 to 3) of std_logic_vector(15 downto 0);
    
    signal arr_a : arr;
    signal vec_0, vec_1, vec_2, vec_3 : std_logic vector(15 downto 0);
    ....
    arr_a(0) <= vec_0;
    arr_a(1) <= vec_1;
    ....
    I hope this helps.

  3. #3
    Join Date
    Aug 2008
    Posts
    71
    I hve problem with generics and array in my code. Its like this,

    Code:
    generic (width:=16
    --t_width :integer:= 8;
    t_widths:=integer:=3;
    t_size:= integer:=3);
    signal ctrl:std_logic_vector(width-1 downto 0)
    type ctrl_gen array(o to t_size)of std_logic_vector(0 to t_widths)
    Now i need a logic to assign ctrl(vector) to ctrl_gen(array).

  4. #4
    Join Date
    May 2008
    Posts
    2,297
    try this
    Code:
    arr(0)<= vec(15 downto 12);
    arr(1)<= vec(11 downto ;
    arr(2)<= vec(7 downto 4);
    arr(0)<= vec(3 downto 0);
    it is immpossible to assign vec directly to arr. you have to specify the address of arr and also break down the vector to 4 bits because your array is of 4 bits. Ok try this.

  5. #5
    Join Date
    May 2008
    Posts
    2,389
    Here is another more generic way using a generate loop. If you were doing this in several places I would create a function to do it. Note I changed the indexing of the array elements to use "DOWNTO" instead of "TO".
    Code:
    CONSTANT VEC_WIDTH : integer := 16;
    CONSTANT ARR_SIZE : integer := 4;
    CONSTANT ARR_ELEM_WIDTH : integer := 4;
    SIGNAL vec : std_logic_vector(VEC_WIDTH-1 DOWNTO 0);
    TYPE arr IS ARRAY(0 TO ARR_SIZE-1) OF
    std_logic_vector(ARR_ELEM_WIDTH-1 DOWNTO 0);
    ....
    arr_assign_gen : FOR i IN 0 TO ARR_SIZE-1 GENERATE
    arr(i) <= vec(i*ARR_ELEM_WIDTH-1 DOWNTO (i-1)*ARR_ELEM_WIDTH);
    END GENERATE arr_assign_gen;

  6. #6
    Join Date
    May 2009
    Posts
    1

    Re: Array in VHDL

    CONSTANT VEC_WIDTH : integer := 16;
    CONSTANT ARR_SIZE : integer := 4;
    CONSTANT ARR_ELEM_WIDTH : integer := 4;
    SIGNAL vec : std_logic_vector(VEC_WIDTH-1 DOWNTO 0);
    TYPE arr IS ARRAY(0 TO ARR_SIZE-1) OF
    std_logic_vector(ARR_ELEM_WIDTH-1 DOWNTO 0);
    ....
    arr_assign_gen : FOR i IN 0 TO ARR_SIZE-1 GENERATE
    arr(i) <= vec(i*ARR_ELEM_WIDTH-1 DOWNTO (i-1)*ARR_ELEM_WIDTH);
    END GENERATE arr_assign_gen;


    In the above code, the assignment of signal vector to the array is not correct , i think. because, when i=0 then arr(0)<= vec(0 DOWNTO -4);
    i=1 then arr(1)<= vec(3 DOWNTO 0);
    so assignment should be as follows:
    arr_assign_gen : FOR i IN ARR_SIZE-1 DOWNTO 0 GENERATE
    arr(i) <= vec((i+1)*ARR_ELEM_WIDTH-1 DOWNTO i*ARR_ELEM_WIDTH);
    END GENERATE arr_assign_gen;

Similar Threads

  1. C# array help
    By Daren in forum Software Development
    Replies: 5
    Last Post: 03-01-2010, 07:12 AM
  2. Assigning an array to an array
    By MACE in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 05:19 PM
  3. Want information about VHDL and PSpice
    By gauriS in forum Education Career and Job Discussions
    Replies: 2
    Last Post: 17-04-2009, 10:47 AM
  4. VHDL 16-bit barrelshifter Question
    By Stefan09 in forum Software Development
    Replies: 3
    Last Post: 04-02-2009, 10:13 AM
  5. Basic VHDL Questions
    By Keegan in forum Software Development
    Replies: 2
    Last Post: 07-11-2008, 08:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,159,274.32445 seconds with 17 queries