Forum Discussion
Altera_Forum
Honored Contributor
18 years agoInferring a ROM
Has anyone used a HEX (Intel format) file to infer a ROM? I'd like to build a look-up table for waveform generation using a 32768 x 16 ROM and would prefer not to type in all of the values manually....
Altera_Forum
Honored Contributor
18 years agoHello Brian,
I wanted to leave some problems for you... No, iit's not exactly the same code, it's easier. In the generate version, no VARIABLE object can be used, thus you need these long-winded CONSTANT constructs. With functions, all calculations can use VARIABLE objects. If you like, you could do the calculation in a single expression without variables except romvar. But with variables, readability is improved, I think.TYPE ROM IS ARRAY(0 TO 511) OF UNSIGNED(8 DOWNTO 0);
FUNCTION INIT_ROM RETURN ROM IS
VARIABLE romvar: ROM;
VARIABLE x: REAL;
begin
for I in 0 TO 511 loop
x:= SIN(real(i)*MATH_PI/real(511));
romvar(i):=CONV_UNSIGNED(INTEGER(x*real(511)),9);
end loop;
return romvar;
end; Regards, Frank