function/process to generate sine and cosine wave

F

FPGA

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
 
F

FPGA

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.
 
J

Jeff Cunningham

FPGA said:
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

what frequency?
what resolution?
synthesizable or testbench?

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

-Jeff
 
A

Anuja

what frequency?
what resolution?
synthesizable or testbench?

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

-Jeff

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

FPGA

what frequency?
what resolution?
synthesizable or testbench?

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

-Jeff

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

Ray Andraka

FPGA said:
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


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.
 
F

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.

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
 
R

Ray Andraka

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 in 0 to 10000 loop
sig <= std_logic_vector(to_signed(integer(scale*sin(phase)),bw);
phase <= phase + phase_increment;
wait until clk='1';
end loop;
 
C

comp.arch.fpga

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 <= cos*k;
next_cos <= sin*k;
The constant k determines the frequency.

Kolja Sulimma
 
J

John

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 in 0 to 10000 loop
        sig <= std_logic_vector(to_signed(integer(scale*sin(phase)),bw);
        phase <= phase + phase_increment;
        wait until clk='1';
end loop;

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.
 
T

Tricky

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)


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.
 
F

FPGA

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.

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?
 
N

Nicolas Matringe

FPGA a écrit :
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?

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
 
C

comp.arch.fpga

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.

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
 
F

FPGA

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

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

Brian Drummond

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.

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)
type real_array is array(natural range<>) of real;
function sinewave(f: real; n: natural) return real_array;


- Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top