Forum Discussion

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

Arithmetics in VHDL

Hi,

I need to implement some arithmetic functions in an FPGA (which I never done before) and I have a few questions. I'm currently using a Cyclone IV E dev kit, the actual design will use either Cyclone IV E or Cyclone V E.

1. Sine/Cosine - is it better to use Altera's megafunctions, look-up tables or any other method?

2. Tangent - is there a megafunction for that or should I just divide the sine/cosine outputs?

3. When using Altera's megafunctions how can I know that the output is ready? I couldn't find any "result ready" flag or anything similar.

4. I need to implement a power function (x^y) while both x and y can be floating point numbers - how should I do that?

Thanks in advance

4 Replies

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

    I would not call trigonometric functions 'arithmetic' :D

    Anyway:

    1. Choice between LUT or megafunction depends on your precision and latency requirements. A raw LUT is faster but the precision is strongly dependent from table dimension. Altera megafunction is somewhat more versatile since you can easily tune parameters to obtain optimal performarce for your design, but you have output result latency. However the megafunction, too, is fundamentally based on a LUT.

    2. If you actually need tangent and possibly not sin and/or cos, there's no point in calculating them and performing division. Use directly a tan function or LUT. Division is convenient for tan definition but in VHDL and in software a direct calculation of tan or any other function is generally more convenient (i.e. faster).

    3. I don't know if a 'ready' signal is available. I rather think these megafunction have a fixed latency specified by clock cycles.

    4. Usually x^y is calculated as e^(y*logx)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your help.

    1. How should I calculate the tangent? Is there a special function for it? I couldn't find a tan megafunction.

    2. As you said megafunctions has fixed latency specified by clock cycles - does that mean that I have to "manually" count clock cycles and then read the output?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    My suggestion is to use the Cordic algorithm coded in VHDL. The Cordic in rotation mode will give you sin(theta) and cos(theta), where you supply the theta. You can then use the Cordic algorithm in vectoring mode to get atan(y/x) and sqrt(x^2 + y^2), which is magnitude. With regards to the power function, I would suggest expansion in a Taylor series and then simply using the large amounts of embedded multipliers in Cyclone IV and up devices to do the multiplication and addition. -James

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

    Thank you James. You wouldn't suggest using Altera's megafunctions at all?