sine wave generation using verilog

K

kunal

Guest
hi all
i want to know, how i generate sine wave using verilog,i am doing
project on bpsk modulator and there sine wave needed.if you have any
reference design or link then please specify me.
please guide me
 
kunal wrote:
hi all
i want to know, how i generate sine wave using verilog,i am doing
project on bpsk modulator and there sine wave needed.if you have any
reference design or link then please specify me.
please guide me
Does your simulator support SystemVerilog ?

You can use the DPI to call the math.h sin() function with very little
effort.
Here's a lttle testbech that generates a sine wave of random freq &
amplitude.
(this example requires support of SystemVerilog constraint solver)


-------------------------------------------------------------------------------
module sine_sv_tb (output real sine_val);
parameter cycles = 5;
real inc_rad, angle;
int i, j;

import "DPI-C" pure function real calc_sine(input real angle);

class rand_sine;
rand byte steps;
rand byte amplitude;
shortreal sine_val;
real pi = 3.14159265;
real inc_rad;
constraint c1 {steps > 15;}
constraint c2 {amplitude inside{[16:64]};}

function real calc_rad;
calc_rad = (2 * pi) / steps;
endfunction
endclass

rand_sine rs1 = new;

initial
begin
for (i=0; i<cycles; i++)
begin
assert (rs1.randomize()) else $display("Randomize failed");
$display("Amplitude : %d Steps : %d",rs1.amplitude, rs1.steps);
inc_rad = rs1.calc_rad;
$display("Radian increment : %f ",inc_rad);
angle = 0.0;
for(j=0; j<(rs1.steps); j++)
begin
sine_val = calc_sine(angle) * rs1.amplitude; // call the C
function
#5ns angle = angle + inc_rad;
$display("Step : %d Sine Value : %f",j,sine_val);
end
end
$stop();
end

endmodule

------------ C function --------------------
#include <math.h>
#include <dpiheader.h>

double calc_sine(double angle)
{
return(sin(angle));
}
------------------------------------------
 
kunal wrote:

i want to know, how i generate sine wave using verilog,i am doing
project on bpsk modulator and there sine wave needed.if you have any
reference design or link then please specify me.
please guide me
Does the model have to be synthesizable, or can you live with a
simulation?

-a
 

Welcome to EDABoard.com

Sponsor

Back
Top