Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior trying to simulate Varactor #156

Closed
tomhajjar opened this issue Sep 15, 2022 · 18 comments
Closed

Strange behavior trying to simulate Varactor #156

tomhajjar opened this issue Sep 15, 2022 · 18 comments

Comments

@tomhajjar
Copy link

tomhajjar commented Sep 15, 2022

I'm getting weird results trying to "port" a Qucs Varactor simulation over to Qucs-S. I want to use "Varactor_Model.sch" in circuits. I used the built in varactor model for debugging. I want to plot CV and Z to confirm my model is working at operating frequency. I want to use 2 methods, AC current source and measurement of S11 to calculate C and Z.

Like for S-parameters, AC simulation for a "constant" fixed frequency doesn't work. Forced to have 2 frequencies.

As shown below, the data for "Component Impedance_I.sch" is as expected. Simple LCR meter.

The data for "Varactor_Impedance_I.sch" is garbage. I tried disabling various componenst

2022-09-15_111307

2022-09-15_110741

Varactor Model_prj.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 15, 2022

It seems this example cannot be ported directly to Ngspice. The SPICE has no single point simulation type. It is exclusively Qucsator invention. The SPICE standard supports only sweep simulation. As the simulation result Ngspice always produces not a single point but a vector. See chapter 17 of the Ngspice manual https://ngspice.sourceforge.io/docs/ngspice-html-manual/manual.xhtml#magicparlabel-23509 . The frequency variable is also not valid for Ngspice. You should look at the chapter 17.2 of the Ngspice manual and rewrite equations using Ngspice notation. Then it will probably work.

@tomhajjar
Copy link
Author

tomhajjar commented Sep 15, 2022

If you compare the two schematics, after I disabled some components, they are equivalent. Why does the first work and not the second?

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 15, 2022

Disabling of parameter sweep doesn't work properly. If I delete it manually the capacitance is calculated fine.

@ra3xdh ra3xdh added bug and removed question labels Sep 15, 2022
@tomhajjar
Copy link
Author

If start/stop are the same frequency or you sweep only 2 points, you only get data for the first point.

You get Tabular data for 1 or more data points. You get a Cartesian plot for 3 or more data points.

Could you not send ngspice the same freq twice (Start=Stop) when in Constant mode?

Qucs puts "0 nan" if Start=Stop

2022-09-15_130238

2022-09-15_131441

@tomhajjar
Copy link
Author

tomhajjar commented Sep 16, 2022

Vadim

My goal was to make a generic varactor model with parasitics like done in Qucs/QucStudio. I was able to get ngspice to generate CV data in Tabular form but not as a plot of C versus V. The caveat was I was forced to put the varactor parameters (Cj0, M, Vj, Bv) directly into the diode model used in the subcircuit, Varactor_Model_mod.sch. I could not figure out a way to get Qucs-S to pass the parameters to the diode in the subcircuit, Varactor_Model.sch. Qucs-S makes Cj0=0 M=0 Vj=0 Bv=0 instead of the values required.

Is there a reason Qucs/QucStudio will pass parameters to any device like semiconductors in a subcircuit but but Qucs-S won't? I realize this isn't something many would need.

2022-09-16_154647

Varactor Model_prj.zip

@tomhajjar
Copy link
Author

I found an online ngspice example for plotting varactor C versus V for a fixed AC frequency.

https://sourceforge.net/p/ngspice/discussion/120972/thread/cd75976f/
Varactor CV ngspice.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 17, 2022

Is there a reason Qucs/QucStudio will pass parameters to any device like semiconductors in a subcircuit but but Qucs-S won't?

It's a bug. Qucs-S cannot recognize variable in model parameter and substitutes zero. I will provide a fix soon.

@tomhajjar
Copy link
Author

Will Qucs-S implement PlotVs?

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 17, 2022

The PlotVs was implemented long time ago. It is available from diagram dialog, but not as function.
image

@tomhajjar
Copy link
Author

Is the CV plot blank due to the Auto ranging issue?

Why is the DC sweep not 0, 1, 2...10? It's 0, .90909, 1.81818...10?

Varactor Model_prj.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 17, 2022

No, is not related to auto-ranging issues of #133 Linux version is affected too. I need to make more investigations to determine the reason of blank plots. Look like inconsistent vector dimension of X/Y axis somewhere.

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 17, 2022

This gives a bit more light on this. The root of this is the fact that single point simulation in SPICE is a hack. The every single point simulation produce a set of 1x1 point plot. If you set curve type stars instead of solid line you will see a plot instead of blank diagram. But the PlotVs still fail.
image

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 17, 2022

You will be able to see the C-V plot using the 3-D diagram.
image

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 20, 2022

See also my comments here: #161 (comment) The #161 is related to this.

@tomhajjar
Copy link
Author

I updated my files to get around the known issues. I will update them as fixes are implemented.
I added measurement of CV using S-parameters. P2 must be terminated for ngspice. The C calculations ignore model parasitics.

Did you discover why "V1" is 0, .909, 1.82.. instead of 0, 1, 2...?

2022-09-20_082059

Varactor Model_prj.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Sep 20, 2022

Did you discover why "V1" is 0, .909, 1.82.. instead of 0, 1, 2...?

The step for netlist is computed as (stop-start)/points=(10-0)/11 The step that shown in the properties dialog is different.

@tomhajjar
Copy link
Author

tomhajjar commented Sep 28, 2022

Are you going to fix Step and Number being wrong?

For Start=-5, Stop=0 and Number=5, Qucs-S says Step =1.25 but for ngspice and Qucs-S plot, Step=1 and Number=6

2022-09-28_225748

@ra3xdh
Copy link
Owner

ra3xdh commented Jun 4, 2023

Look for the solution of the CV-curve plotting problem in #277. This currently may be resolved using some tricks with Nutmeg scripting. No application fix is required. I am closing this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants