Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simulation code for sinewave

Status
Not open for further replies.

andrew257

Member level 2
Joined
Feb 22, 2007
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,648
module sine_cos

Hi All

i am after some code to simulate a sinewave input. It will be used as part of a system to simulate the input of a ADC. None of the code has to be synthesizable.

I have found some code on this forum but i am having a hard time understanding what it does etc. If anyone could expalin it to me that would be great.

Heres the code

module sine_cos(clk, reset, en, sine, cos);
input clk, reset, en;
output [7:0] sine,cos;
reg [7:0] sine_r, cos_r;
assign sine = sine_r + {cos_r[7], cos_r[7], cos_r[7], cos_r[7:3]};
assign cos = cos_r - {sine[7], sine[7], sine[7], sine[7:3]};
always@(posedge clk or negedge reset)
begin
if (!reset) begin
sine_r <= 0;
cos_r <= 120;
end else begin
if (en) begin
sine_r <= sine;
cos_r <= cos;
end
end
end
endmodule // sine_cos

To make a testbench for this code am i right in thinking i will need to generate another module for clk or can it be done with a loop?

Thank You

Andrew
 

That code looks like an oscillator. The derivative of sine is cosine, and by adding a small amount of one to the other, you get oscillation. If you need precise amplitude and frequency, that's not a good way to do it.

For testbench simulation, try simply using Verilog's $sin() function, maybe combined with $realtime.
 

Try this testbench!
ALl you need is connecting them up..



`resetall
`timescale 1ns/10ps

module test_mult;

reg arst_n;
reg clk;

initial begin
arst_n <= 1'b1;
clk <= 1'b0;
en <= 1'b0;

repeat(2) @(posedge clk);
arst_n <= 1'b0;
repeat(2) @(posedge clk);
arst_n <= 1'b1;
repeat(2) @(posedge clk);
en <= 1'b1;
repeat(1000) @(posedge clk);

$stop();
end

always begin
#12.50 clk <= ~clk;
end


endmodule // convenc_sim
 

Hi andrew257, ALL,
I too need sine wave CODE and that should be need to give as input to ADC (analog to digital converter).

how can i do this using verilog.

with your posts i understood that you also tried the same thing.if you have the same code please mail me at cruzer2060@yahoo.in

i will be more thankful to you all.


THANKS,
CRUZER
 

I too need sine wave CODE and that should be need to give as input to ADC (analog to digital converter).

How can you give digital sine wave to ADC? You have to use some function generator (Hardware Equipment) to generate analog sine wave.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top