Using an array value as indices for an array

K

KLaus Blank

Guest
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
 
On Jul 7, 2:21 pm, KLaus Blank <Kla...@hotmail.com> wrote:
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
 

Welcome to EDABoard.com

Sponsor

Back
Top