Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indexing arrays in VHDL

Tags:

vhdl

I have an array:

type offsets_type is array (4 downto 0) of std_logic_vector (4 downto 0); 
signal av     : offsets_type;

I want to do this, essentially: av[addr] += 1;
But this line:

 av(to_integer(unsigned(addr))) <= unsigned(av(to_integer(unsigned(addr))) + 1;

yields this error:
to_integer can not have such operands in this context.

I've also tried using conv_integer, but that gives Wrong type of index as an error.

Any solutions? Thanks.

like image 315
Cory G. Avatar asked May 01 '11 23:05

Cory G.


People also ask

What is array indexing explain with example?

PHP indexed array is an array which is represented by an index number by default. All elements of array are represented by an index number which starts from 0. PHP indexed array can store numbers, strings or any object. PHP indexed array is also known as numeric array.

How are arrays declared in VHDL?

You can declare multidimensional arrays by building one-di- mensional arrays where the element type is another one-di- mensional array, as shown in Example 4–6. type BYTE is array (7 downto 0) of BIT; type VECTOR is array (3 downto 0) of BYTE; VHDL provides both constrained arrays and unconstrained arrays.

What is record in VHDL?

Records are similar to structures in C. Records are most often used to define a new VHDL type. This new type contains any group of signals that the user desires. Most often this is used to simplify interfaces. This is very handy with interfaces that have a large list of signals that is always the same.

What does others mean in VHDL?

The statement "Others => '0'" is a feature of the VHDL when the coder want to defined several items in an array with the same value. In your example, all item std_logic in the array are set to '0'.


1 Answers

There are a few problems in your code:

  1. You cast the result of your calculation to an unsigned, while the left-hand side is std_logic_vector
  2. There might be something wrong with the data type of addr, but you have not shared that with us.
  3. There is a closing parenthese missing in the assignment.

It will be easier if you use "unsigned" in your type definitions. This way, you express that the bit pattern is actually something you want to use in integer arithmetic.

type offsets_type is array (4 downto 0) of unsigned (4 downto 0);
signal av     : offsets_type;
signal addr :unsigned(2 downto 0);

This will save you a few type conversions:

av(to_integer(addr)) <= av(to_integer(addr)) + "1";

Edit: you did use ieee.numeric_std.all didn't you?

like image 163
Philippe Avatar answered Sep 28 '22 08:09

Philippe