The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 19th, 2024, 12:01pm
Pages: 1
Send Topic Print
Sine wave generator with different freqs (Read 741 times)
priyaa_raman
New Member
*
Offline



Posts: 1

Sine wave generator with different freqs
Aug 16th, 2004, 5:06pm
 
Hi folks,

I'm new to Verilog AMS and I have a question with sine wave generator.

I need to generate a sine wave first 50 cycles with a freq and then 50 cycles with a different freq. I can only generate one particular freq but not able to do two different freqs. I tried using generate statement but did not help. My code is
module sine2wav (sinesig, Vdd, Vss );
     
     output sinesig, Vdd, Vss;
     electrical sinesig, Vdd, Vss;
     integer i;
     parameter real vdd = 1.5, vss = 0;
     parameter real frequency1 = 1e9, ampl1 = 0.2;
     parameter real frequency2 = 10e7, ampl2 = 0.3;
     real tempvar;
     
analog begin
     V(Vdd) <+ transition( vdd );
     V(Vss) <+ transition( vss );
     
     
            generate (0,50) begin

                 V(sinesig) <+ (ampl1 * sin(2.0*`M_PI * frequency1 * $abstime));
                 $bound_step(0.02 / frequency1);
end      
           
     generate (0,50) begin
           
                 V(sinesig) <+ (ampl2 * sin(2.0*`M_PI * frequency2 * $abstime));
                 $bound_step(0.02 / frequency2);
end
           
           
end

endmodule
Back to top
 
 
View Profile   IP Logged
aznaragorn
Junior Member
**
Offline



Posts: 16

Re: Sine wave generator with different freqs
Reply #1 - Aug 17th, 2004, 10:22am
 
why not do something like this:

//`timescale 1ns/10ps;
//real freq;

initial begin
  freq <= frequency1;
  #(50.0/frequency1*1e9);
  freq <= frequency2;
end

And then:
V(sinesig) <+ sin(`M_TWO_PI * $abstime * freq);

sorry this code isn't checked for exact syntax or whatever, but you get the idea.

Why are you using transition filters without any parameters? (they won't achieve anything until you give rise times etc.)
Also,  the generate loop is generally thought of as obsolete, you should probably try using for loops.
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.