Crystal Oscillator Simulation

526 views
Skip to first unread message

Jesus Perez

unread,
Jun 25, 2019, 9:54:15 AM6/25/19
to xyce-users
Hello all,

I've built the circuit in the attached netlist file by following the recommendations on this page (reference designators do not match). To "kick-start" the oscillator I've made V1 step from 0 to 3.3 V at t=0.5. My problem is that I can't get the circuit to build oscillation amplitude at 1 MHz in Xyce.

I built the exact same circuit in two other simulators: namely LTSpice and SIMetrix both of which produce comparable results with oscillation of ~ 2 Vpp at 1 MHz. After this, I looked at the output settings from SIMetrix and specified linear solver and time integrator .OPTIONS on my Xyce netlist to try to mirror those settings, still had no luck.

I would like to get this working (and understand how to properly do it) on Xyce as my real goal is to try get a crystal model to oscillate with a much more complex circuit. Thank you in advance!
Example.cir

xyce-users

unread,
Jun 25, 2019, 2:18:40 PM6/25/19
to xyce-users
Thank you for your interest in Xyce.

We are looking into this issue, but have no quick answer for you.  We have been able to get this circuit to oscillate by tweaking it in various ways, but have not yet gotten it to oscillate with the sort of amplitude it should.  It may take a while for us to pin down the reason.

Jesus Perez

unread,
Jun 25, 2019, 10:37:31 PM6/25/19
to xyce-users
Thank you for the quick response. Interestingly enough, I'm trying this at home where I've built Xyce from source code (Built and ran it using Ubuntu on WSL Windows 10, Version 1903, Build 18362.175, original post was based off running the Windows executable available on the Xyce website on Windows 7) and somehow it works! I rebuilt the netlist as attached, but I fail to see what could be the magic here. The DELMAX parameter is different between the two netlists but I used a smaller number on the faulty system and also had no luck. The transistor model is also different from earlier but it oscillates at 1 MHz and the amplitude is comparable to what is obtained by the other simulators using the '2N2222' model (rather than the 'Q2N2222').

Crystal2.png

Crystal1.png

Crystal1.png


Crystal.cir
Crystal2.png

xyce-users

unread,
Jun 26, 2019, 1:01:59 AM6/26/19
to xyce-users

Jesus:
This is very interesting.

The "magic" you stumbled upon here is in fact exactly the delmax parameter.  When using ERROPTION=1, the simulator can in fact take large timesteps because local truncation error is no longer used to determine the time step --- unless the circuit contains elements that would cause the timestep to be limited, or it runs into a maximum set by delmax or the maximum timestep on the .tran line.   Your circuit contains no circuit elements that would force a limited timestep, so setting delmax=1e-4 meant that the simulator was permitted to take timesteps even longer than a single period of the resonant frequency of your crystal model (about 1MHz, or a period of 1e-6s).

If you go back to your original netlist and change nothing other than to change delmax from 1e-4 to 1e-6, you'll find that it, too, oscillates with the expected amplitude (or at least it does on my system when I tried that).  If you cut and paste the entire set of .options lines from your latest netlist to replace the set of options lines in the first that you sent, it too, works.  Furthermore, if you took your original netlist and left all the .options lines exactly as is (even with delmax=1e-4), but added a maximum timestep to your .tran line, it would also simulate as expected (".tran 1u 10 0 1e-6" would do the trick).

We are still looking into why our default simulator settings don't work out of the box on this problem (and why other simulators' defaults do work), but the difference in delmax at least explains the mystery of why one of your runs worked and the other didn't.

Thank you for this report.

xyce-users

unread,
Jul 10, 2019, 6:49:01 PM7/10/19
to xyce-users
Jesus:

We have looked at your crystal oscillator circuit in detail.  We have found the reason that default simulation settings do not produce oscillations, and we are able to get the circuit run correctly with a good set of non-default options.  The new results match those from Spectre.  These results are better and more accurate than those with erroption=1 and delmax=1e-6 that were obtained earlier in this thread.

The main problem for this circuit is due to the accuracy of the simulation.  This is a crystal oscillator which normally has a very high Q-factor (25000 for this circuit).  For a high-Q oscillator, it is common that some voltage nodes in the oscillator have very large values compared to the rest of the voltage nodes.  In this circuit, for example, V(C4_P) reaches about 330V at steady state.  The default LTE strategy in Xyce is not well suited for the circuit if the scale of signals varies widely.  It can lead to very inaccurate answers.

To solve the accuracy problem, you can use a better LTE strategy.  All the options in the original circuit can be removed.  The only option you needs is:

.options timeint newlte=3

This option should be used if the scale of signals varies widely, which is the case for your crystal circuit.  You can refer to Xyce users' guide 7.3.5 for details about the different newlte values and when to use them.  This option generates accurate results with about 2V peak to peak amplitude of oscillations.  The circuit build up oscillation smoothly in about 0.1 sec after the step function.

You can also use .options timeint newlte=3 reltol=1e-2.  This makes the simulation run faster and generates similar results.  The phase is slightly different due the accumulation of phase errors for oscillators.  For convenience, we're attaching the original netlist with this version of simulator options as well as some graphs of output.

The original circuit with erroption=1 and delmax=1e-6 can also make the circuit oscillate, but because the time integrator is no longer adjusting time step size to keep local truncation error low, the results are not as accurate as the newlte=3.  The erroption=1 is not recommended normally.

We attached the comparison of Xyce results with newlte=3, Xyce results with erroption=1 and delmax=1e-6, and Spectre results.  As you can see, the erroption=1 with delmax=1e-6 took much longer to build up the oscillation.  Also, the steady state amplitude did not reach the level produced by Spectre.  The envelope for the erroroption=1 run is not smooth.

We also attached the voltage of the node between the serial L and C.  It reached about 330V at the steady state.

There are multiple ways to help start the oscillation as noted in the application note you quoted.  The original circuit uses a step function on the supply to kick start the oscillation.  Another way to accelerate and build up the oscillation is to use an initial condition and UIC in the .TRAN line.  For example, you can use .ic V(C4_P)=300.  Or you can also use  C4 C4_P C4_N 10f IC=300.  Both will build up the oscillation in 0.03sec.

We have tried to run the circuit in other circuit simulators.  Some of them also did not build up correct oscillations as the original Xyce simulation.  Some of them only build up the oscillation with the step function to kick start the oscillations.  With the newlte=3 option, it works for both the step function or the capacitor initial condition.  The results match well with Spectre results.

Please let us know if you have any further questions.

Thanks,

The Xyce team
Example.cir
osc2.png
osc3.png

Jesus Perez

unread,
Jul 11, 2019, 10:32:47 AM7/11/19
to xyce-users
Excellent, thank you very much for your thorough answer. I definitely understand these options a lot better now!

Marcel Hendrix

unread,
Jul 13, 2019, 5:52:06 AM7/13/19
to xyce-users
The difference with non-Xyce simulators is the default integration method that is used. In LTspice the default is some proprietary improvement of TRAP. TRAP is the best one to use here as it has the least amount of 'numerical damping' and automagically tunes itself. 
With the standard TRAP method the system will start immediately when the power supply voltage is ramped up. It is, however, a bad idea to sweep faster than the step size of the simulator. I have attached an NGSPICE net list that starts up within 100us.

Remark 1: There is no need to simulate 500ms with the small step size needed for the 1 MHz oscillation.
Remark 2: In NGSPICE one can experiment with the XMU parameter to (mainly) increase the numerical damping and remove distracting noise. The default setting appears to suffice here. I would expect this to work in Xyce too.

-marcel


osc.cir

xyce-users

unread,
Jul 13, 2019, 1:05:27 PM7/13/19
to xyce-users
Xyce's default time integrator is also trap, and even if it had not been, Jesus' original netlist explicitly used "method=7" in his options line, which specifies trap as the time integration method.  The reason that Xyce was performing differently than LTSpice and ngspice is the difference in how Xyce computes local truncation error and adjusts time step to keep that error measure in bounds.  Selecting an alternate LTE norm is sufficient to make this circuit perform correctly in Xyce.
Reply all
Reply to author
Forward
0 new messages