The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> About ac analysis
https://designers-guide.org/forum/YaBB.pl?num=1224746430

Message started by ChinFu on Oct 23rd, 2008, 12:20am

Title: About ac analysis
Post by ChinFu on Oct 23rd, 2008, 12:20am

Hi, recently i used verilog-a to model a device, and the input is a Vdc.

// VerilogA for mic_model, sin_wave_5, veriloga

`include "constants.vams"
`include "disciplines.vams"

module sin_wave_5 (vin, mout);

inout vin, mout;
electrical vin, mout;

parameter real frequency = 0;

parameter real a0=451.47;
parameter real a1=4.9;
parameter real a2=-0.0143;

real q, p, r, b;

analog begin

q=2.0*`M_PI*frequency*$abstime;

p=sin(q);

b=V(vin, mout);

r=b*(a0+a1*p+a2*p*p);

I(vin,mout) <+  2*ddt(r*1e-15);

end

endmodule


It can run  trans analysis well, but can not run AC analysis (the input is a Vdc).
I need AC analysis result so that I change the program as

// VerilogA for mic_model, sin_wave_5, veriloga

`include "constants.vams"
`include "disciplines.vams"

module sin_wave_5 (vin, mout);

inout vin, mout;
electrical vin, mout;

parameter real ac_mag = 1;
parameter real ac_phase = 0;

parameter real amplitude = 1;
parameter real frequency = 0;

parameter real a0=451.47;
parameter real a1=4.9;
parameter real a2=-0.0143;

real q, p, r, b,   ac_phaserad;

analog begin

q=2.0*`M_PI*frequency*$abstime;

p=sin(q);

b=V(vin, mout);

r=b*(a0+a1*p+a2*p*p);



if (analysis("ac"))
begin
 ac_phaserad=ac_phase*3.14159/180;

 I(vin,mout) <+ ac_stim("ac", ac_mag, ac_phaserad);
end
 else  begin  

I(vin,mout) <+  2*ddt(r*1e-15);
end

end


endmodul


This can not run in trans analysis and ac analysis.

Could someone tell me how to correct the program to run trans and ac analysis well?

Thanks

ChinFu

Title: Re: About ac analysis
Post by Geoffrey_Coram on Oct 23rd, 2008, 4:36am

Hi -
What do you mean by "can not run AC analysis" -- does it not run, or just you don't get the answer you were expecting?

What is the device?  Do you understand what ac analysis does, and what do you expect your device to do?  I would not expect that you'd put an ac_stim in your model, unless you're making a custom small-signal source, so let's go back to the first model.  If you apply a voltage source with a dc value and an ac magnitude, then the simulation should evaluate the model at the dc value (b = V(vin,mout) will get the dc bias across that branch), linearize about that point, and then multiply the ac magnitude by the transfer function.

I find it suspicious that you have "frequency" in your code; you might find it instructional to construct an RC filter in Verilog-A and run some simulations with that so you understand how Verilog-A's ddt() operator brings in the 2 pi f factor in ac analysis.

Title: Re: About ac analysis
Post by ChinFu on Oct 23rd, 2008, 9:47am

Dear Geoffrey_Coram:

Thank you for your reply.
In fact the device is  like a variable capacitance; so, i used a 2nd order sin wave as the variable.
In Spectre, after this device is connected an OP. So I need trans analysis and ac analysis (to get Bode diagram or frequency response)to obtain the system performance.
I am new in verilog-a and Spectre. If I mistake something please correct me.
Thank you

ChinFu

Title: Re: About ac analysis
Post by Geoffrey_Coram on Oct 23rd, 2008, 12:42pm

I think there are some variable capacitor models on this forum; you should go there.

Your model should not depend on $abstime at all.  You need to write the charge as a function of voltage, and then set
 I(vin, mout) <+ ddt(chg);

The time-dependence should come through the voltage, not through an explicit dependence on the simulator time.

Title: Re: About ac analysis
Post by Peruzzi on Oct 23rd, 2008, 2:27pm

ChinFu,

It looks to me like your test signal is only defined in the time domain.  What if you instantiate a vsin in your model, defining AC frequency, magnitude and phase as well as its transient parameters?

I think you could instantiate the vsin on a dummy schematic, check and save, then copy the Verilog-AMS code to instantiate it into your model in place of your code which generates q and p=sin(q).  Hopefully it would then work in both transient and AC simulations.

Or maybe I'm oversimplifying the problem...  Let me know anyway.

Bob P.





Title: Re: About ac analysis
Post by ChinFu on Oct 23rd, 2008, 8:51pm

Hi~
In practice, the device is driven by a Vbias to measurement the vibration (vibration will change the capacitance of the device).
Previously, I have built a model

inout vin, mout;
electrical vin, mout;

parameter real a0=451.47;
parameter real a1=4.9;
parameter real a2=-0.0143;
parameter real c=2

real  r, b;

analog begin

b=V(vin, mout);

r=c*(a0+a1*b+a2*b*b);

I(vin,mout) <+  ddt(r*1e-15);

end

endmodule

In the previous model, I utilized a Vsin as the vibration input and fixed the capacitance of the device to run simulation.
Now, the device was connected with an OP,and I want bo build a model more similar the practical model (use Vbias as th input not the Vsin). So I put a sin wave inside the model to replace the vibration.

In practice, the frequency of the vibration is from Hz to KHz; thus I need the AC analysis to get the frequency response.  

ChinFu

Title: Re: About ac analysis
Post by Geoffrey_Coram on Oct 24th, 2008, 4:04am


ChinFu wrote on Oct 23rd, 2008, 8:51pm:
In the previous model, I utilized a Vsin as the vibration input and fixed the capacitance of the device to run simulation.


It sounds to me that there is one voltage input to your model, which has a dc component (vbias) and a variable component (Vsin, which I assume also had an ac mag).  Since the components are combined to make a single input to your system, then I would think you could just put your v-sources in series.

Title: Re: About ac analysis
Post by Peruzzi on Oct 24th, 2008, 6:17am

ChinFu,

Regarding:

"In practice, the frequency of the vibration is from Hz to KHz; thus I need the AC analysis to get the frequency response",

since your transient simulation works as expected, why not put in a chirp waveform and do your frequency analysis in MATLAB?

Just a thought,

Bob P.

Title: Re: About ac analysis
Post by ChinFu on Oct 26th, 2008, 9:22am

Hi

If I wnat to run Ac analysis without an another AC inhput.  What could I do ??  using ac_stim??

"why not put in a chirp waveform and do your frequency analysis in MATLAB"  u mean using matlab to analysis circuit behavior??  

ChinFu

Title: Re: About ac analysis
Post by Peruzzi on Oct 28th, 2008, 7:47pm

ChinFu,

Sorry, my answer wasn't very clear.  MATLAB isn't strictly necessary, but since it's available to me, I use it just for calculation convenience.

With the chirp source you control frequency versus time, and you can graphically pick off output amplitude and phase versus time, and it is trivial from there to calculate amplitude and phase versus frequency.

If you find yourself doing this repeatedly, you can strobe outputs to a file and write a MATLAB script to automate the task.

Hope this helps.

Bob

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