function/process to generate sine and cosine wave

F

FPGA

Guest
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
 
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.
 
FPGA wrote:
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
 
On Feb 6, 10:05 pm, Jeff Cunningham <j...@sover.net> wrote:
FPGA wrote:
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
has to be synthesizable. No restriction on frequency or resolution as
such.
 
On Feb 6, 10:05 pm, Jeff Cunningham <j...@sover.net> wrote:
FPGA wrote:
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
has to be synthesizable. No restriction on frequency or resolution.
 
FPGA wrote:
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.
 
On Feb 6, 11:42 pm, Ray Andraka <r...@andraka.com> wrote:
FPGA wrote:
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.


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
 
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;





FPGA wrote:

On Feb 6, 11:42 pm, Ray Andraka <r...@andraka.com> wrote:

FPGA wrote:

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.


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

On 7 Feb., 09:00, Ray Andraka <r...@andraka.com> wrote:
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;
 
On Feb 7, 11:00 am, Ray Andraka <r...@andraka.com> wrote:
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.
 
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.
 
On Feb 8, 4:17 am, Tricky <Trickyh...@gmail.com> wrote:
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.
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?
 
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
 
On 9 Feb., 11:05, Nicolas Matringe <nicolas.matri...@fre.fre> wrote:

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
 
On Feb 9, 5:40 am, "comp.arch.fpga" <ksuli...@googlemail.com> wrote:
On 9 Feb., 11:05, Nicolas Matringe <nicolas.matri...@fre.fre> wrote:



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
Thank you so much for your help. I appreciate it. I will try your
suggestions and see how it works out.
 
On Sat, 9 Feb 2008 02:40:45 -0800 (PST), "comp.arch.fpga"
<ksulimma@googlemail.com> wrote:

On 9 Feb., 11:05, Nicolas Matringe <nicolas.matri...@fre.fre> wrote:


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

Welcome to EDABoard.com

Sponsor

Back
Top