The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Nov 15th, 2024, 3:15am
Pages: 1 2 
Send Topic Print
Printing frequency in AC output (Read 1074 times)
Marq Kole
Junior Member
**
Offline



Posts: 11
Eindhoven, The Netherlands
Printing frequency in AC output
Aug 25th, 2006, 6:33am
 
Hi,

I'm trying to create a measuring device in Verilog-A that prints its terminal voltages and currents during the simulation, along with the independent variable. This is quite straightforward in transient ($abstime), DC (passing in as parameter), and thermal ($temperature), but for AC I seem unable to measure the frequency.

I've tried code such as:

Code:
electrical f;

...

analog begin

  ...

  V(f) <+ laplace_nd(ac_stim(), {1}, {0, 1});
  $strobe("frequency = %g", V(f)/`M_TWO_PI);

  ...

end // analog 



But the only return value I ever got was 0.0. I've also tried this in multiple tools (using different Verilog-A compilers) but none provided the desired results.

I've also tried to use an external small signal source and filter, so the frequency-dependent signal would only be probed by the Verilog-A module, but that didn't work either.

Marq
Back to top
 
 
View Profile   IP Logged
ACWWong
Community Fellow
*****
Offline



Posts: 539
Oxford, UK
Re: Printing frequency in AC output
Reply #1 - Aug 25th, 2006, 9:33am
 
this is quite interesting.... i tried it myself, but like you got 0.... and there is no simple $absfrequency....

I guess you are wanting to do something with the freq variable within your code, so a practical (rather than neat) solution would be to use say:

analog begin
@(initial_step) begin
acfrq = -2;
end
acfrq = acfrq+1;
$strobe("step=%g",acfrq);
end

So setting up your ac sweep from 1 to 10 Hz in steps of 1 will give you the frequency variable printed correctly.... Obviously for log sweeps etc. you'll have to tweak the acfrq=acfrq+1 line to get the right mathematical increments. The initial value needs to be 2 values lower than the initial start point of the ac sweep, as spectre seems to call the veriloga code twice before begining the proper frequency sweep (something to do with computing the dc solution first i guess).

Anyway if you only wanted the frequncy varibale for post-processing, the calculator xval function would work well in OCEAN.

Alternatively i think you might find a neater solution elsewhere... perhaps something to do with modeling skin effect in inductors (as resistance is a function of the frequency variable)would be give you some good ideas ?

cheers

aw
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Printing frequency in AC output
Reply #2 - Aug 25th, 2006, 11:11am
 
None of these approaches will work. Verilog-A models are not actually evaluated during the AC analysis. Rather, a DC analysis is run and the model is linearized about the DC operating point. It is linearization that is used during the AC analysis. Any attempt to access or create a variable that contains the frequency is doomed to fail. Also, printing during an AC analysis is not possible. If you perform an AC analysis that sweeps some parameter that affects the operating point, then will appear to print during the AC analysis, but it is actually printing during the DC operating point analysis that precedes each AC step.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
ACWWong
Community Fellow
*****
Offline



Posts: 539
Oxford, UK
Re: Printing frequency in AC output
Reply #3 - Aug 25th, 2006, 11:24am
 
Ken Kundert wrote on Aug 25th, 2006, 11:11am:
None of these approaches will work. Verilog-A models are not actually evaluated during the AC analysis. Rather, a DC analysis is run and the model is linearized about the DC operating point. It is linearization that is used during the AC analysis. Any attempt to access or create a variable that contains the frequency is doomed to fail. Also, printing during an AC analysis is not possible. If you perform an AC analysis that sweeps some parameter that affects the operating point, then will appear to print during the AC analysis, but it is actually printing during the DC operating point analysis that precedes each AC step.

-Ken


hi Ken,

i'm a bit confused with what i see when i just run an ac sweep from 1 to 10 Hz in steps of 1 Hz and use the veriloga code i posted previously. In my spectre.log is get:

****************************************
AC Analysis `ac': freq = (1 Hz -> 10 Hz)
****************************************

Notice from spectre during AC analysis `ac'.
   No outputs found.  Loosening output filter criterion to `lvl'.

sacfrq=-1
sacfrq=0
sacfrq=1
sacfrq=2
   ac: freq = 2 Hz        (11.1 %), step = 1 Hz         (11.1 %)
sacfrq=3
   ac: freq = 3 Hz        (22.2 %), step = 1 Hz         (11.1 %)
sacfrq=4
   ac: freq = 4 Hz        (33.3 %), step = 1 Hz         (11.1 %)
sacfrq=5
   ac: freq = 5 Hz        (44.4 %), step = 1 Hz         (11.1 %)
sacfrq=6
   ac: freq = 6 Hz        (55.6 %), step = 1 Hz         (11.1 %)
sacfrq=7
   ac: freq = 7 Hz        (66.7 %), step = 1 Hz         (11.1 %)
sacfrq=8
   ac: freq = 8 Hz        (77.8 %), step = 1 Hz         (11.1 %)
sacfrq=9
   ac: freq = 9 Hz        (88.9 %), step = 1 Hz         (11.1 %)
sacfrq=10
   ac: freq = 10 Hz        (100 %), step = 1 Hz         (11.1 %)
Accumulated DC solution time = 0 s.
Intrinsic ac analysis time = 10 ms.
Total time required for ac analysis `ac' was 10 ms.


are you saying for every ac sweep point, a dc op point simulation is being completed ? surely there is only 1 dc op point simulation at the begining ??


cheers

aw

Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Printing frequency in AC output
Reply #4 - Aug 25th, 2006, 11:38am
 
That is strange. It may be that your simulator (which appears to be Spectre) is actually evaluating the model at every frequency point. Conceptually that is not necessary. However, since it is evaluating the model at every frequency point, then it is probably also running a DC analysis (it better, because as you have shown, by evaluating the model you can change its behavior, and hence the DC operating point, on every step). Anyway, with this being the case you should ignore my comments on the printing. However, it is still not possible to access the frequency.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
ACWWong
Community Fellow
*****
Offline



Posts: 539
Oxford, UK
Re: Printing frequency in AC output
Reply #5 - Aug 25th, 2006, 11:50am
 
Ken Kundert wrote on Aug 25th, 2006, 11:38am:
That is strange. It may be that your simulator (which appears to be Spectre) is actually evaluating the model at every frequency point. Conceptually that is not necessary. However, since it is evaluating the model at every frequency point, then it is probably also running a DC analysis (it better, because as you have shown, by evaluating the model you can change its behavior, and hence the DC operating point, on every step). Anyway, with this being the case you should ignore my comments on the printing. However, it is still not possible to access the frequency.

-Ken


Thanks ken,

Anyway just for my curiousity i have run the following veriloga code, to remove the acfrq=acfrq+1 so that nothing in the model changes each time it is evaluated, ie no reason to redo the dcop...

module freq;

electrical a; //needed to present an output for spectre to be happy

analog begin

$strobe("bob");

end // analog

endmodule

And when i ran the ac sweep 1 to 10 in steps of 1 i get:

****************************************
AC Analysis `ac': freq = (1 Hz -> 10 Hz)
****************************************

Notice from spectre during AC analysis `ac'.
   No outputs found.  Loosening output filter criterion to `lvl'.

bob
bob
bob
bob
   ac: freq = 2 Hz        (11.1 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 3 Hz        (22.2 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 4 Hz        (33.3 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 5 Hz        (44.4 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 6 Hz        (55.6 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 7 Hz        (66.7 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 8 Hz        (77.8 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 9 Hz        (88.9 %), step = 1 Hz         (11.1 %)
bob
   ac: freq = 10 Hz        (100 %), step = 1 Hz         (11.1 %)
Accumulated DC solution time = 10 ms.
Intrinsic ac analysis time = 0 s.
Total time required for ac analysis `ac' was 10 ms.

so its still evaluating the DC before each ac step... pretty bizarre ?
Anyway the original code will still give you the variable acfrq which in incremented in tandem with the ac freq (albeit there is a hidden dc op beofre every ac point, which can't be turned off ?!?!).

cheers
aw
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Printing frequency in AC output
Reply #6 - Aug 25th, 2006, 6:28pm
 
At a minimum it is evaluating the model between every AC point. The question in my mind is if the simulator is actutually performing a DC analysis. One could determine that by changing the model on each step in a way that it affected the operating point, and then print the operating point and see if it changed. For example, one could write a model for a resistor whose resistance changed on every step, then drive it with a current source and print the output voltage across the resistor on each step. If it changed, then presumably it is doing a full DC oppoint analysis between each AC point, and so will compute the right answer.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
Marq Kole
Junior Member
**
Offline



Posts: 11
Eindhoven, The Netherlands
Re: Printing frequency in AC output
Reply #7 - Aug 28th, 2006, 12:12am
 
Ken, AW,

Thanks for the replies. I now see that I've been a bit naive, as the signal in the frequency domain is of course a complex number, not a real value like in transient and DC. So all my ideas to extract the frequency were doomed to failure becuase Verilog-A cannot handle the complex results that should have come from these expressions.

I guess that for full support of AC the language needs to be extended. Would that also help for non-linear frequency domain modelling and simulation (RF)?

Marq
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Printing frequency in AC output
Reply #8 - Aug 28th, 2006, 8:49am
 
So now the question has changed from whether you can access the frequency to whether you should be able to. My answer has always been no. And my reasons are:
1. It is very difficult for the user to formulate a frequency domain model correctly.
2. It is very difficult to implement a frequency domain modeling capability in the simulator that operates properly and gives good results in the transient analysis.
3. It is not very useful; there are very few models that are both easy to describe in the frequency domain and hard to describe in the time domain.

Issue number 1 is about causality. It is very easy to describe a model that is non-causal when working in the frequency domain. Such a model is impossible to include in any meaningful way into a transient analysis, and of course produces non-physical results. For example, many people try to model skin effect by creating a resistor with a resistance that is proportional to sqrt(f), but the result is non-causal. What really is needed is an impedance that is proprotional to sqrt(jω). Some of this can be mitigated by not allowing access to f, only to jω, and by avoiding the temptation to provide non-analytic functions, such as real(), imag(), conj(), etc. These things help, but it is not clear that completely solve this problem.

Issue number 3 is something I have observed over time. Most models that are easy to write in the frequency domain, like capacitors and inductors, are lumped, and they are also easy to write in the time domain. Models that are distributed are difficult to write in the time domain, but except in a few exceptional cases, are also difficult to write in the frequency domain. The exceptions are things like ideal delay, skin effect, and the like. These special cases can be more easily handled by both the user and the simulator by providing built-ins in the simulator. An example is the absdelay() function already provided in the language.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
ACWWong
Community Fellow
*****
Offline



Posts: 539
Oxford, UK
Re: Printing frequency in AC output
Reply #9 - Aug 29th, 2006, 5:10am
 
Ken Kundert wrote on Aug 25th, 2006, 6:28pm:
At a minimum it is evaluating the model between every AC point. The question in my mind is if the simulator is actutually performing a DC analysis. One could determine that by changing the model on each step in a way that it affected the operating point, and then print the operating point and see if it changed. For example, one could write a model for a resistor whose resistance changed on every step, then drive it with a current source and print the output voltage across the resistor on each step. If it changed, then presumably it is doing a full DC oppoint analysis between each AC point, and so will compute the right answer.

-Ken


Ken, I did what you suggested and confirmed that the verilogA is model is evaluated at every AC step by Spectre, but the DC is NOT evaluated. So its NOT possible to modify the DC op point on the fly within the ac sweep, its only evaluated at the begining (as i have always understood it). Does the veriloga model have to be evaluated every ac step for things like the laplace to work ?
Back to top
 
 
View Profile   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Printing frequency in AC output
Reply #10 - Aug 29th, 2006, 6:20am
 
Not for Laplace, but perhaps for absdelay() and the z filters. In any case, the model does not have to be reevaluated, just the function. I suspect they evaluate the model simply because of the strobe functions.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: Printing frequency in AC output
Reply #11 - Aug 29th, 2006, 8:32am
 
Ken Kundert wrote on Aug 28th, 2006, 8:49am:
3. It is not very useful; there are very few models that are both easy to describe in the frequency domain and hard to describe in the time domain.


I can howeer see Marq's point that, for an "instrumentation module" ie one that prints out information about the circuit, it is nice to be able to print the frequency value.  I could imagine providing a %code to give the frequency.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
jbdavid
Community Fellow
*****
Offline



Posts: 378
Silicon Valley
Re: Printing frequency in AC output
Reply #12 - Aug 29th, 2006, 11:04am
 
Another thing that would be nice would be to have access to results in the frequency domain so that if all you were looking for was the 3dB frequency you could end the simulation once you found it..
However it might be better to add a language (TCL?) like MDL to use with the Simulator and the Verilog-A(MS) design description for use in managing the simulations.. TCL has been OK for Verilog-AMS - at least in the Time domain runs and for what I have tried so far.

jbd ιβδ
Back to top
 
 

jbdavid
Mixed Signal Design Verification
View Profile WWW   IP Logged
Ken Kundert
Global Moderator
*****
Offline



Posts: 2386
Silicon Valley
Re: Printing frequency in AC output
Reply #13 - Aug 29th, 2006, 12:30pm
 
This question has exposed an area in the Verilog-A LRM that is ambiguous. There is no discussion about the simulation cycle for AC analysis. Thus it is not clear even if the AC analysis code should be evaluated at every step of the AC analysis. Cadence clearly takes a middle ground, where they evaluate the model but not actually perform a DC analysis, but one could imagine the LRM stating that either no code is evaluated or a full DC analysis is required on every step of an AC analysis if the DC operating point could change.

-Ken
Back to top
 
 
View Profile WWW   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: Printing frequency in AC output
Reply #14 - Aug 30th, 2006, 6:32am
 
From the standpoint of a standard Spice ac analysis, models aren't allowed to change (and aren't evaluated) during the frequency sweep.  The circuit is frozen and linearized.  So, I would argue that Cadence made the wrong choice in allowing anything in the model to change for subsequent points of an ac analysis (I'm ambivalent about whether the $strobe statements should be issued).  For a compact model, the simulator should extract the code it needs for an ac analysis and not run the analog block directly.

For behavioral models, though, I guess it's not so easy to determine the "right thing" to do.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Pages: 1 2 
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.