Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to make a lookup table in vhdl

Status
Not open for further replies.

ahmedomar_2000

Newbie level 4
Newbie level 4
Joined
Jul 4, 2013
Messages
6
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Visit site
Activity points
51
i need to use this code ,i post just a small part , it is a very long values , so i need a help in how to use these values which appear below in my code in a lookup table ( ram or rom ),


if (outputt<=x"0e00" and outputt>=x"0d7a")then
output1<=x"0012";
-----------------------------------------------
elsif (outputt<=x"0d79" and outputt>=x"0ccd")then
output1<=x"0013";
-------------------------------------------
elsif (outputt<=x"0ccc" and outputt>=x"0c31")then
output1<=x"0014";
-------------------------------------------
elsif (outputt<=x"0c30" and outputt>=x"0ba3")then
output1<=x"0015";
-------------------------------------------
elsif (outputt<=x"0ba2" and outputt>=x"0b22")then
output1<=x"0016";
-------------------------------------------
elsif (outputt<=x"0b21" and outputt>=x"0aab")then
output1<=x"0017";
-------------------------------------------
elsif (outputt<=x"0aaa" and outputt>=x"0a3e")then
output1<=x"0018";
-------------------------------------------
elsif (outputt<=x"0a3d" and outputt>=x"09d9")then
output1<=x"0019";
-------------------------------------------
 

With suitable wrapping (e.g. placed in a clock synchronous process) a HDL compiler will probably accept the code as ROM description. You can use it in an initialization function.

As coded, you are are describing a 64k x 16 Bit ROM (1 Mbit, quite large). Is that what you want to achieve?
 

it is better to make it with (case) and at the end make when other to avoid latches as i think.

example

HTML:
mux:PROCESS(s0, s1, in0, in1, in2, in3)
  VARIABLE  sel  :  STD_LOGIC_VECTOR(1 DOWNTO 0);
BEGIN
  sel := s1 & s0;   -- concatenate s1 and s0  

  CASE sel IS
    WHEN  "00"  =>  output <= in0;
    WHEN  "01"  =>  output <= in1;
    WHEN  "10"  =>  output <= in2;
    WHEN  "11"  =>  output <= in3;
    WHEN OTHERS =>  output <= 'X';
  END CASE;

END PROCESS mux;
  
END case_example;
 

declare a type (in a package):
Code:
type my_lut_type is array (natural range <>) of std_logic_vector(16-1 downto 0);

and declare a huge constant within:
Code:
constant my_lut : my_lut_type(0 to 2**16 - 1) := ( x"0000", ... x"FFFF");

Or, if data permits, write a function that can generate it:
Code:
function make_my_lut return my_lut_type is
  variable return_lut : my_lut_type(0 to 2**16 - 1);
begin
  for idx in return_lut'range loop
    return_lut(idx) := <your code here>;
  end loop;
  return return_lut;
end function;

I think that is the correct syntax for a function of 0 arguments at least.

Code:
constant MY_LUT : my_lut_type(0 to 2**16 - 1) := make_my_lut();

Once this is done, you can use it in your code:
Code:
-- in a clocked process for BRAM implementations
x <= MY_LUT(integer_index);

You would need to make sure the index is an integer. Just keep in mind that for this size, each independent access to the constant will create a new ROM in hardware. Likewise, if you have async accesses to the ROM, you will end up inferring distributed ROM, which will use most/all/overmap the FPGA. Finally, you should not use async resets on the control lines to the ROM (including address), at least on Xilinx FPGAs. This is because of appnotes that say the BRAMs can become corrupted if the setup/hold of the address/en lines are not met even when not writing.
 

I know that Altera QUARTUS II and Xilinix WEB pack provide wizards to construct RAM or ROM blocks. synchronous memory operations guarantee safer implementation. a little bit of reading on HDL code to resource mapping will be helpful.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top