Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

VHDL code for logarithme

Hi,

There are somoene that release a vhdl code for log or have any idea about it.

I need any tutorial or helps to start release it.

Thank you.

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    like log base 2?

    this function will return the nearest log2 of a number (but I wouldnt recommend synthesising as a real time function) Its useful for determining how many bits you need for a vector.

    
    function log2(x : integer) return integer is
      variable temp : integer :=x;
      variable n : integer := 1;
    begin
      while temp > 1 loop
        temp := temp/2;
        n := n + 1;
      end loop;
     
      return n;
    end function log2;
    
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    like log base 2?

    this function will return the nearest log2 of a number (but I wouldnt recommend synthesising as a real time function) Its useful for determining how many bits you need for a vector.

    
    function log2(x : integer) return integer is
      variable temp : integer :=x;
      variable n : integer := 1;
    begin
      while temp > 1 loop
        temp := temp/2;
        n := n + 1;
      end loop;
     
      return n;
    end function log2;
    

    --- Quote End ---

    Think you very much for your reply,

    ok for this function it is clear, but that i need is a function that can execute during a minimum of clock cycle.

    ThAnk you
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    if you need a synthesisable version, I suggest you use a look-up table.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    if you need a synthesisable version, I suggest you use a look-up table.

    --- Quote End ---

    Ok thank you, already i use LUT, but i search if it is possible to find a synthetisable code for log.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    LUT is the easiest. But you should be able to generate the table using a function.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    LUT is the easiest. But you should be able to generate the table using a function.

    --- Quote End ---

    I generate the LUT through Matlab. And i initialize memory with the generated data.