The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Sine wave generator with different freqs
https://designers-guide.org/forum/YaBB.pl?num=1092701182

Message started by priyaa_raman on Aug 16th, 2004, 5:06pm

Title: Sine wave generator with different freqs
Post by priyaa_raman on 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

Title: Re: Sine wave generator with different freqs
Post by aznaragorn on 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.

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.