Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Dividing array in parts.

Hi, I'm having a problem when I try to take just one part of an array, for example:

I have a 512x512 array, and want just the first 8x8 samples.

I'm having the following error:

"slice of object cannot be specified for object that has an array type of more than one dimension"

Here's part of the code:

Type array_t IS ARRAY (0 to 7, 0 to 7) OF STD_LOGIC_VECTOR(0 to 7);

Type array_t2 IS ARRAY (0 to 511, 0 to 511) OF STD_LOGIC_VECTOR(0 to 7);

SIGNAL input: array_t

SIGNAL output: array_t2

input<=output(0 to 7, 0 to 7);

Thank you!!

8 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    you cannot do that with a 2d array, you can only access one entry at a time.

    for this, you would need a loop (ps. I think you means to assign output, not input!)

    
    for i in input'range(1) loop
      for j in input'range(2) loop
        output(i,j) <= input(i,j);
      end loop;
    end loop;
    
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks Tricky. You are always saving my life.

    As soon as possible I will teste and reply.

    Thanks again!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    you cannot do that with a 2d array, you can only access one entry at a time.

    --- Quote End ---

    Respectively a row slice at once. Keep in mind, that a 2D array isn't but a mapping scheme to represent data structures, that are 1D arrays by nature.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It didn't worked, I get an error:

    "indexed name returns a value whose type does not match "array_t", the type of the target expression."

    Type array_t IS ARRAY (0 to 7, 0 to 7) OF STD_LOGIC_VECTOR(0 to 7);

    Type array_t2 IS ARRAY (0 to 511, 0 to 511) OF STD_LOGIC_VECTOR(0 to 7);

    SIGNAL output: array_t

    SIGNAL input: array_t2

    process(clk)

    begin

    for i in 0 to 7 loop

    for j in 0 to 7 loop

    output<=input(i, j);

    end loop;

    end loop;

    end process;

    Thank You!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The code worked fine if I want to do something using the same index:

    output(0, 0) <= input(0, 0);

    but how about

    output(0, 0) <= input(8, 8);

    output(0, 1) <= input(8, 9);

    How can be done that?

    Thank You!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have tried this before and didn't worked. But the error was somewhere else.

    This works.

    output(i, j) <= input(i, j+8);