Using an array value as indices for an array

K

KLaus Blank

Hi

I have a very simple problem. I have two arrays counter_1 & counter_2,
defined as standard_logic_vector. 2 std_logic vectors A0 & A1 define
the indices for the counter_1 array. Using the index
counter_1(conv_integer(A0 & A1)) I wanna make an lookup into
counter_2 and increment the value that is currentely stored there
as in the following simple code fragement.

counter_2(conv_integer(counter_1(conv_integer(A0 & A1)))) <=
counter_2(conv_integer(counter_1(conv_integer(A0 & A1)))) + 1;

However, the thing is not really working :( Has anyone an idea what
is wrong? Or is this not possible having twice an array access as above?

Many thanks for suggestions,
Klaus
 
D

Dave

Hi

I have a very simple problem. I have two arrays counter_1 & counter_2,
defined as standard_logic_vector. 2 std_logic vectors A0 & A1 define
the indices for the counter_1 array. Using the index
counter_1(conv_integer(A0 & A1)) I wanna make an lookup into
counter_2 and increment the value that is currentely stored there
as in the following simple code fragement.

counter_2(conv_integer(counter_1(conv_integer(A0 & A1)))) <=
counter_2(conv_integer(counter_1(conv_integer(A0 & A1)))) + 1;

However, the thing is not really working :( Has anyone an idea what
is wrong? Or is this not possible having twice an array access as above?

Many thanks for suggestions,
Klaus

Klaus,

What libraries are you using? It looks like you're using
std_logic_arith and/or std_logic_unsigned, neither of which are
recommended. The better way to do this is to use the numeric_std
library. Also, you could declare counter_1 and counter_2 as type
unsigned instead of std_logic_vector, since this seems to better
represent what you are doing with these signals, and you'll have to do
less type conversion. Then, you could write:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

....

signal counter_1 : unsigned(...); -- put your range here
signal counter_2 : unsigned(...); -- put your range here
signal A0 : unsigned(...); -- put your range here
signal A1 : unsigned(...); -- put your range here

counter_2(to_integer(counter_1(to_integer(A0 & A1)))) <=
counter_2(to_integer(counter_1(to_integer(A0 & A1)))) + 1;

If you wanted to, you could declare these signals as integers instead,
and get rid of all the type conversions. It really depends on what's
going on in the rest of the code, and what approach is going to be
most clear.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top