Search This Blog

Showing posts with label Simulation. Show all posts
Showing posts with label Simulation. Show all posts

Sunday, September 11, 2011

Beyond SPICE

So here I am, working on a new version of my previous SPICE software.  Of course to call something SPICE, it's usually a linear circuit simulator.  When you start adding nonlinear models with S-Parameter, Harmonic Balance, and Various Large-Signal simulations you start to move past SPICE into something a little more :).  So I have named this new version Beyond SPICE to show that it will be greater than a simple SPICE software.

So, in this I have started to create the basis of the software within the last 2 weeks.  I'm starting (for the most part) from scratch.  My last version was simply able to handle transient analysis for Resistors/Capacitors/Inductors/Current Source/Voltage Source.

This new version will handle this plus everything else.

Up to this point, I have the following elements in there first versions:
  • Complex Numbers and Parser:
    • The parser can parse directly to a complex number or can separate the equation into an expression tree.  I will explain this in another post.
    • Can handle all variations of complex number and functions including hyperbolic functions.
  • Matrices:
    • A number of matrix classes have been created.  Namely, a string matrix, complex constant matrix, and an expression tree matrix.
    • Complex Constant Matrix and Expression Tree Matrix can be inverted along with determinants.  The simple things
Although, this may not seem like much, the value in the time spent in these 2 major class libraries has a vast impact on the speed of the final product.  For instance, the Expression Tree allows for a complex statement to be parsed only once and evaluated many times (POEM - Parse Once Evaluate Many).  This means that parsing doesn't need to occur directly every iteration.  In fact, incorporating this into a matrix speeds up the time even more.

Secondly, having the invertability of the Expression Tree Matrix allows for inversion to only occur once and then evaluate the inverse matrix directly without having to perform the inverse at each time step.

Taking the time to develop these algorithms will show great improvement in performance down the road.

Hopefully I can keep you guys up to date more often.  Any questions, feel free to email me.

---------------------
Justin Coulston
justin.coulston@gmail.com

Saturday, May 1, 2010

Simulation: NPR Test Simulation

So during my time at work today (yes I worked on Saturday), I made an attempt to try and simulate an NPR test for an amplifier in Agilent's EESof/ADS.  Now there is a way to accomplish this using the DSP portion along with the Analog Envelope technique but I haven't found a way to do it directly with the RF/Analog system.  This is quite the disappointment...

Figure 1: NPR Test Stimulus (courtesy Agilent)


So I have been researching into solutions.  Only one has presented itself up to this point: Spectral Balance Simulations.  Unfortunately, ADS doesn't support this directly (at least not to my knowledge).  This is different than the typical Harmonic Balance Simulation most people are used to.  In fact the main difference is that the Spectral Balance simulation stays in frequency domain.  The Harmonic Balance simulation instead does a transient analysis then an FFT to complete the simulation (Of course it's more complex than this).


So how do I get around it?  I really have no idea right now.  The fact is, this is a known issue.  Why hasn't someone developed this into the more popular SPICE simulations?  There are random Matlab tools that can do the trick but not directly in SPICE packages.


Anyways, that's my rant for the day.  I'll go into more detail, hopefully, at a later date.


---------------------------------
Justin Coulston
justin.coulston@gmail.com

Saturday, April 24, 2010

Simulation: SPICE Update 1

I haven't had much to say these past few days...nothing really new.  I finally came up with a structure for my software.  I will have separate models (including companion models) for every device except for the basics: resistor, independent voltage, current sources, and dependent voltage, current sources.  After this everything else is modeled.  So I have a format for my "netlist"

I'm not using the classical netlist format.  I will have to be able to import classic netlists into the software but I haven't gotten that far yet.  Hopefully this will come sooner than later.  Anyways, sorry this isn't more detail oriented.

----------------------
Justin Coulston
justin.coulston@gmail.com

Sunday, April 18, 2010

Simulation: Netlist Template

I have spent the last 2 days trying to figure out how to generalize the process of subcircuits for the SPICE software.  I've gone through a few design possibilities and finally came to the conclusion that simple netlist style templates will work perfectly.

So instead of reinventing the wheel, I'll use the classic technique of netlisting.  I will end up using a different netlist for different simulation types.

Example:
The capacitor companion model for a ...

Transient Analysis: Consists of a resistor in parallel with a current source.
DC Analysis: Consists of either a perfect open or very high value resistor (> 1 Gigaohm)
Small Signal or AC Analysis: Consists of a resistor with equation R = 1/(2*pi*f*C)

So I'll have different models for different simulation types as you can see.  The biggest question will be how to define the equations for the individual parameters.  How should I implement these into classes inside the program?  Creating text file models is the easy task.  It's a little more difficult to implement into Classes.

That's the extent of where I am currently.

--------------------
Justin Coulston
justin.coulston@gmail.com

Wednesday, April 14, 2010

Simulation: Complex Parser Completion

So I have successfully finished the Complex Parser.  I was able to successfully separate the operators in a particular order.  So now if you have a string with complex math you can turn it into a complex class number.  There isn't much to say about this part of the project now that it's complete.  I still need to do further testing to confirm all the numbers, but as of now it works like a charm.

I will say that the code seems a little inefficient and longer than necessary.  Hopefully in the future I can be more efficient in the way it works.

Hopefully, I can get back to more stimulating posts later, teaching you guys somethings.  Feel free to leave comments and check out the old posts for more information to learn...

--------------
Justin Coulston
justin.coulston@gmail.com

Saturday, April 10, 2010

Simulation: My SPICE software

This blog is just to update and tell you guys that I have started a SPICE software package.  Of course it'll be simple and won't do things PSPICE or B2SPICE can do but it's a great way to learn the process easier.  I have already implemented the portion of the program that can simulate current sources and resistors.  You can have as many nodes as you desire and it seems to work perfect (confirmed with B2SPICE).  So I think that's good...

As for the software structure.  I had to create a simple Complex Class and Matrix Class.  The most difficult part was creating the inversion routine for the matrix.  I didn't realize how complicated this was until I started to write it.  I used the slowest and most real, the reduced diagonal method.  I basically used linear algebra directly without any optimizations.

Anyways, this project will take a while.  Once I can develop a simple engine, I'll put a GUI around it and make it better in a number of ways (if possible).  Any suggestions, let me know

-----------------------
Justin Coulston
justin.coulston@gmail.com

Friday, April 9, 2010

Simulation: Basics of SPICE Modeling (Matrix Templates) - 2 of 6

Introduction
This is a continuation of the SPICE modeling series.  I will attempt to explain how SPICE uses Matrix Templates to create a main matrix to perform the calculation.

SPICE Templates
Before I explain how voltage sources are used I should first explain how SPICE knows where to put information based on node numbers.

Each component in SPICE has an associated Matrix template that is added to a final matrix that performs the final calculation.  As repeated from the last SPICE tutorial: [G][U]=[K] are the [G], conductance matrix, [U], unknowns matrix, and [K], knowns matrix, or the matrix with the known sources (voltage and current sources).

The initial matrix for the conductances starts with inserting the conductances between the nodes first.  Each row and column corresponds with a particular node number.  So we can easily construct the matrix by summing the conductances between the nodes.


where n is the total number of nodes (not including ground)

So any components connected to node 1 will be summed at G11=1/R1+1/R2+ ... +1/Rn.

Now that you see how this first matrix works you can can understand how the templates can work.  For example, the resistor template has a node A and node B connection points with a resistance R.  Below is the matrix template



Now of course the template won't have the words node A and node B in them.  So if the resistor was between nodes 3 and 6 then you would add T11 to G33, T22 to G66, T12 to G36, and T21 to G63 of the main matrix.

So you follow this for all the components.  All components have some sort of matrix template.  Below I will the capacitive and current sources.  Inductor templates use a voltage source so we will talk about that later.


Add to the Conductance Matrix


Add to the Knowns Matrix

where
 
and


And for the current source it's simply adding the below matrix to the knowns table:



Conclusion
That's it for SPICE templates.  Again, each component has it's own matrix template.  This is the basics of how SPICE adds components in a netlist to a large matrix.

Monday, April 5, 2010

Simulation: Basics of SPICE Modeling (Current Sources) - 1 of 6

Introduction
There has been a few people that have talked to me recently about SPICE modeling.  It seems a lot of people use it but no one really knows how it works.  There are a number of books available that explain how it works.  One of the better (and older to today's standards) books is the Inside SPICE: Overcoming The Obstacles of Circuit Simulation.  This is a great book detailing the workings of the basic SPICE simulation.  There is a link to amazon below for it.  I will attempt to explain the first part of a series of posts about SPICE software.  This one will discuss the basics of Nodal Analysis (NA).


Nodal Analysis (NA)
Nodal Analysis is just as it sounds, the standard current summation at the various interconnection nodes.  Electrical Engineers learn this in their first circuits class.  NA is all that's needed to do DC and AC SPICE simulations.  I will discuss here how to perform basic Nodal Analysis.

You should note that in this method you can only have Current Sources and Resistors in the circuit.  In order to use voltage sources you must use Modified Nodal Analysis and to use the capacitors and inductors you must use companion models with numeric integration techniques.  But both of these are based off this first simulation style of Nodal Analysis.  I will discuss the prior techniques in later posts...


Figure 1: Basic Nodal Analysis Example

As you can notice in Figure 1, this circuit has a current source, and resistors.  You can do the node voltage technique to analyze this circuit.  This is what SPICE uses.  So to analyze this, find the two nodal equations:


Node 1


Node 2

Now you see that we have 2 unknowns and two equations.  The next step is to set up the matrices.  You will end up with 3 main matrices, a conductances matrix, unknowns matrix, and a knowns matrix.  After you separate the matrices you should get something that looks like this:




So the matrices with the 1/R-Values is the Conductances Matrix [G] and the matrix with voltages is the unknowns matrix [V] while the right-hand side matrix is the knowns matrix [I].  So how do you get results?  You have to do matrix manipulation.  The best way to do this is to do take the inverse of the G-matrix and multiply it to both sides.

Step 1:


Step 2:


Once you perform this calculation, you have solved for the unknowns V1 and V2.  And that's it.  I provided above the solution in the schematic.  You can use these numbers to test it yourself.  

If you want to do quick analysis of this, place it in MS Excel and use the MMINVERSE and MMULT commands.  Google this and you should find plenty on it.  I may post a blog later on using these.

Conclusion
It's amazing how simple this method is.  Everything else is based off this method.  Even the MNA is based on this method.  I will continue and show you guys the MNA method in the next post.

This is the one I have.  But there is a newer version below

This is the second edition.












--------------------
Justin Coulston
justin.coulston@gmail.com