Tuesday, 15 January 2008

LT SPICE - Modelling, Parametrics, Steps and More

For a second year semiconductor project at the University Of Southampton (ECS) I had to investigate the operation of a silicon solar cell manufactured within our institution. As part of my report I wanted to model the electronic properties of the device accurately using a SPICE circuit simulator. My software of choice was LT Spice which is available from Linear Technologies for free. Whilst it is powerful and comprehensive it is much easier to learn to use than its better known cousin - OrCAD / PSPICE. Despite its shallow learning cure I found it difficult to find information on some of the more advanced and interesting features. In this post I will explain how to use some of these features (the ones that I needed for my report, anyway).

Creating IV curves
To view the IV curve of a device/sub-circuit, which is often very interesting and important it is necessary to vary the load resistance and measure the its voltage and current. In LT Spice this can be achieved by changing the load resistance value to a parameter. Parameters can be varied dynamically during the simulation as I will show now:
  • Instead of entering a resistance value for R1, type '{RL}'. RL is the name of the parameter, whilst the '{}' tell LT Spice that you are entering a parameter.
  • Click: EDIT>TEXT
  • Check the 'SPICE Directive box'
  • Type 'STEP param RL 1 1000 1' - increment RL from 1 to 1000, 1Ohm at a time
  • Ensure that the Simulation type selected is 'Operational Point' -.op
  • Run the Simulation
  • Hover mouse over x-axis until it turns into a ruler. Left click and change 'Quantity Plotted' to the voltage node at the top end of resistor (or whichever voltage is of interested)
  • Then add a plot of the current through RL to observe the IV graph
Changing Model Parameters Dynamically - Temperature
LT SPICE has a global parameter for temperature called 'temp'. This is no different from the parameter RL in the previous paragraph, except that it is already defined, (it has to be for components such as diodes and transistors). If you wish to see how temperature affects your circuit, you need first to ensure there are some temperature dependent components in your circuit (else nothing will change).
  • Create another SPICE directive (see above - you can reuse the existing text box if you wish).
  • To set the temperature to a single value, type: 'temp=30' the units are Celsius.
  • To sweep the temperature and observe the effects, type: '.STEP param temp 10 50 1' to raise temp from 10 to 50 Celsius in single degree increments.
To change the way a component behaves with temperature e.g. modelling a thermistor:
  • Replace the components value with a parameter, e.g. replace resistance with {THERM}
  • In a SPICE directive, define the new parameter, e.g. '.param THERM='(temp*0.05)+1000'
  • The parameter can depend upon any other parameter, circuit voltage or current, e.g. THERM has a linear relationship to temperature
Creating bespoke models - Custom diode

Making you own models is as simple as writing a few lines of text and is even easier if you have an understanding of Netlists. For those who don't I will illustrate how to create a simple custom diode model.

  • Add an ideal diode to the circuit (SHORT_CUT=D)
  • Press CTRL and RIGHT-CLICK on the diode
  • Change the box labelled InstName to 'mydiode'. This is the Instance name.
  • Change the 'SpiceModel' box to 'mymodel'. This is the name of the device model.
  • Ensure all the other boxes are empty
  • In a new spice directive text box, we define the model: '.model mymodel D (Is=1.88e-5 N=3.89)'
  • The: '.model' part tells SPICE to expect a model definition.
  • The: 'mymodel' part tells SPICE to link components with a SpiceModel = 'mymodel' to this definition.
  • The: 'D(' part tells SPICE we are defining a diode. L() = Inductor; C() = Capacitor; R() = Resistor etc.
The contents of the brackets are the model's parameters. You do not have to define all of the available parameters, but it is good to check that the default values are appropriate. It is not necessary to use absolute values, parameters can be used too.

More complex models can be built using hierarchical blocks, allowing complex circuits to be viewed as single abstracted component. I will write about this in future posts.

Hopefully you now have enough information to begin creating, editing and designing your own models. Remember to start simple and gradually add extra parameters. Watch out for syntax and try viewing the Netlist file for syntax errors if you have trouble.

Figure One - Example of Parametric Sweep

Figure Two - Example of Temperature Dependence

Figure Three - Example of Custom Diode Model

Sunday, 6 January 2008

Functional Testing of SPICE Simulations

After a second year electronics project, the need to automatically check the function of a large digital circuit arose. The brief was to design an 8-Bit ALU (basic logic, addition and 2's complement functions) with ring oscillator. The circuit then had to be converted to a layout to be manufactured as an integrated chip. The circuit although straightforward to design was difficult to 'route' and the final layout was messy.


Thorough functional testing of our circuit was impossible using just the digital waveform view of PSPICE. To be sure of our layout and circuit designs I created a C program to read the simulation file created by PSPICE and check each clock cycle to ensure correct operation. The final program reads the exported PSPICE output .txt file and checks each line one at a time (actually it only checks one line from each clock, since this is all that's necessary). The program converts the analogue values into 1's or 0's before passing the data into a function to check that the output/input combinations are correct. Although the checking function will vary with every circuit to be tested, I publicise this code as an example of how to make testing large digital circuits easy, well easier.

Simulation files from LTSpice and OrCAD's PSPICE can be used, but the top line of the file (which usually contains the signal names) must be deleted first.

The code can be downloaded from the DocDrop folder 'SPICE Program'. DocDrop can be found at the top of the sidebar on this page.