function/process to generate sine and cosine wave

I would like some guidline on writing a function or process to generate a sine wave and cosine wave. I want to include this into my library. Each time this function/process is called, I would like sine and cosines wave generated.

Are there any functions in VHDL which would help us do so. I know there is a function UNIFORM to generate random numbers, not sure if there is anything available for sine and cosine.

Your comments are appreciated.

Anuja

Reply to
FPGA
Loading thread data ...

I would like to use the CORDIC function available in math_real to generate the sine and cosine wave. Any inputs on if this is possible would be appreciated.

Reply to
FPGA

what frequency? what resolution? synthesizable or testbench?

andraka.com has a good cordic article on it among other things.

-Jeff

Reply to
Jeff Cunningham

has to be synthesizable. No restriction on frequency or resolution as such.

Reply to
Anuja

has to be synthesizable. No restriction on frequency or resolution.

Reply to
FPGA

Is this for a testbench or for sometihng that is going into hardware? If for a testbench, just use the math_real sin and cos functions, converting the resulting reals to the format you need to drive your hardware. If it is to be synthesized into hardware, the math_real library isn't going to help you much, as reals don't map directly into synthesizable hardware.

Reply to
Ray Andraka

Using the math_real library can do for now. I have had a look at the sin and cos functions there. I am also aware on how to conver the real format to the format I want. I intend to generate a wave. sin and cos in math_real would just generate a value for a particular input. How can i generate a sine or cos waveform. I wish to make this function parametrized as follows (not sure if this should go into a function or process)

function sin (x: signed, bw : integer) return signed is

x: signed input with variable bit width bw : desired bit width of output

I can convert signed to real and then use "sin" function in math_real. I am still not sure on how I would generate a wave for each call.

Your comments would be appreciated

Reply to
FPGA

You need to run a count or phase accumulation to feed into the sin/cos function.

signal phase: real; constant scale: real:= 2.0**bw;

for n >>

Reply to
Ray Andraka

Bresenhams algorithm provides better results with far less accumulator bits compared to a phase accumulator. Also, the input parameters (M waves in N cycles) are very convenient in many cases.

If the OP wants a sine, one option that avoids the sine computation is an oscillator: next_sin function.

Reply to
comp.arch.fpga

That's good, but in math_real library sin/cos generate by Tailor formula. And type real have very small size. All of this get not good sin. These can give that noise of your system will grow.

Reply to
John

Are you sure you want to go down this path? If you eventually need it synthesizable, you will have to throw away ALL of the work you have done with the math_real package, unless you're using it as a model of the final block.

The easiest way to implement sin and cosine in and FPGA is using a look up table (normally a ROM), with the address formed from the angle coefficient.

Reply to
Tricky

I want to do a simulation only version right now (some requirements change on the fly :) ). The sin/cos wave has to be implemented in such a way that it can be used as an input to ant UUT. I am not yet sure if this would work by using a function. What other options do I have? I cannot use it as a component. I am making a library of functions so I want to make this as generic as possible. If i implement this using a process, where can this go in a package?

Reply to
FPGA

FPGA a écrit :

Hello You can not generate a waveform using a function only. A function computes an output value based on input values. I think a procedure is what you want.

Nicolas

Reply to
Nicolas Matringe

The input value could be the frequency and the number of samples, the output value could be an array of real contining the waveform.

Not very useful for synthesis, but a good solution for a testbench.

type real_array is array(natural range) of real; function sinewave(f: real; n: natural) return real_array;

Kolja Sulimma

Reply to
comp.arch.fpga

Thank you so much for your help. I appreciate it. I will try your suggestions and see how it works out.

Reply to
FPGA

Actually quite useful for synthesis; the array returned can be the lookup table in a sine wave generator.

(although Xilinx XST may be unbelievably slow in evaluating the function)

- Brian

Reply to
Brian Drummond

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.