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.
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.
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.
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.
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'.
There are a few problems in your code:
unsigned
, while the left-hand side is std_logic_vector
addr
, but you have not shared that with us.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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With