**UPGRADE YOUR BROWSER**

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community Forums
- :
- Forums
- :
- Design Tools
- :
- Design Entry
- :
- Logarithms in VHDL

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

aio85

Visitor

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-04-2009 09:18 AM

17,631 Views

Registered:
03-27-2009

Logarithms in VHDL

4 Replies

gszakacs

Instructor

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-04-2009 10:23 AM

17,628 Views

Registered:
08-14-2007

Re: Logarithms in VHDL

If you can scale the input so that you take the logarithm base 2, then you only need to find the first '1' bit. That's

nothing more than a priority encoder.

-- Gabor

aio85

Visitor

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2009 02:38 PM

17,594 Views

Registered:
03-27-2009

Re: Logarithms in VHDL

gszakacs

Instructor

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-06-2009 05:52 AM

17,569 Views

Registered:
08-14-2007

Re: Logarithms in VHDL

Actually the relationship is only simple after you take the logarithm:

log2 (X) = ln (X) / ln (2)

So:

ln (X) = log2 (X) * ln (2)

The problem here is that if you want ln (X) to the nearest integer, having log2 (X)

will only help if you have some precision beyond the decimal point. You can

achieve this by first finding the highest order (leftmost) '1' bit in X to get the integer

part of log2 (X) and then using a table lookup on the rest of X after normalizing it

to be a number between 0.5 and 1.

Regards,

Gabor

-- Gabor

aio85

Visitor

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-06-2009 07:37 AM

17,560 Views

Registered:
03-27-2009

Re: Logarithms in VHDL

I've done what you have told me, first in matlab and then in vhdl. In matlab I've seen that I don't need the decimal aproximationvto the device I want to design, so I've make the next function in vhdl:

function logarithm (a : integer) return integer is

variable temp, lo, lo_aux : integer:=0;

begin

temp := a/2;

while temp /= 0 loop

temp := temp/2;

lo := lo + 1;

end loop;

lo := lo*6931;

if lo < 10000 then

lo_aux := 0;

else

lo_aux := lo/10000;

end if;

return lo_aux;

end function logarithm;

After synthetizing it gives me the next error in lo_aux := lo/10000:

Operator <DIVIDE> must have constant operands or first operand must be power of 2

Thanks again for replying.