Initializing Large Arrays

R

rickman

Guest
I have some large arrays to initialize from a function call. This is a
ROM table containing integer values derived from trig functions. I'm
thinking the best way is to use a process on startup that will step
through the table elements invoking the function to generate the data.
The only variable input to the function is the index although there may
be scaling constants as well to make the function more general purpose.

Any other suggestions?

--

Rick
 
On Monday, January 5, 2015 12:11:46 PM UTC-5, rickman wrote:
I have some large arrays to initialize from a function call. This is a
ROM table containing integer values derived from trig functions. I'm
thinking the best way is to use a process on startup that will step
through the table elements invoking the function to generate the data.
The only variable input to the function is the index although there may
be scaling constants as well to make the function more general purpose.

Any other suggestions?

If this is meant to be synthesizable, then you will also need another function that loops through the entire index range to generate the entire table so that the whole thing can then be assigned to a constant integer array. Even if it does not need to be synthesized, I still tend to like this method of having a function generate the entire table. A function(s) can simply be reused directly, whereas using a process to call a function involves copy/paste when reusing.

Kevin
 
On Mon, 05 Jan 2015 12:11:27 -0500
rickman <gnuarm@gmail.com> wrote:

I have some large arrays to initialize from a function call. This is a
ROM table containing integer values derived from trig functions. I'm
thinking the best way is to use a process on startup that will step
through the table elements invoking the function to generate the data.
The only variable input to the function is the index although there may
be scaling constants as well to make the function more general purpose.

Any other suggestions?

--

Rick

Something like the following? (Note, this is all in the architecture
declaration bit, not the bit with the processes).

type RAM is array (INT_MAX_ADDR downto 0) of std_logic_vector(15 downto 0);

-- Function to initialize the RAM to a sinewave
impure function SetTable return RAM is
variable count : integer;
variable phase : real;
variable sinx : real;
variable nextval : integer;
variable data : RAM;
begin
for count in 0 to INT_MAX_ADDR loop
phase := REAL(count * 2) * MATH_PI / REAL(INT_MAX_ADDR);
sinx := SIN(phase) * 32767.0;
nextval := INTEGER(ROUND(sinx));
data(count) := STD_LOGIC_VECTOR(TO_SIGNED(nextval, 16));
end loop;
return data;
end function;

signal internal_data : RAM := SetTable;

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
 

Welcome to EDABoard.com

Sponsor

Back
Top