Adding Variables to your Spice Circuit

LT spice, Curve Captor, PSUDII and whatever other sims you can think of.

Post Reply
sbench
Posts: 296
Joined: Fri Jan 28, 2005 3:45 pm

Adding Variables to your Spice Circuit

Post by sbench »

Sometimes it is nice to be able to add a variable or two into your circuit. One possible use is to allow a ratio to be altered. This is sometimes important in building, for example, integrated circuits, where things scale up and down in size, but ratios of components remain fixed.

In "our" world, this can help with transformer coupled circuits. For example, in an inductive attenuator, the overall inductance is controlled by changing the gapping or interleaving, but the ratio between windings remains fixed.

Probably the most common thing we can do is build a potentiometer.

In Spice, this is done by adding a .PARAM command. This adds a variable or constant to the system. It is a constant if we don't alter it during simulation, it is variable if you do. The following is an example of a .param command:

.PARAM RVal=.5

This adds the variable RVal to the schematic and assigns it with the initial value 0.5. (one half)

Now suppose you wanted to build a potentiometer, and simulate what happens as you vary the pot. You could do this by defining 2 resistors R1 and R2 and put them in series. Let's make the pot value total of 100k.
Now when we assign the value to R1 and R2, instead of 50k and 50k, we would do something like...
{{RVal}*100000} for one resistor and
{(1-{RVal})*100000} for the other

Now if we assign RVal=.5, R1=50k, R2=50k (pot centered).
If we assign RVal=.001, then R1=100, R2=99900 (one end).
If we assign RVal=.999, then R1=99900, R2=100 (other end).

NOW, just use the .STEP directive during simulation to step thru the pot.
Here are 2 possible ways of doing that...
.STEP param RVal List .001 .01 .1 .25 .5 .75 .9 .99 .999
.STEP param RVal .001 .999 .001
The second steps the parameter from .001 to .999 in increments of .001
(that's a lot of steps)

Attached is a little schematic that shows what happens as you alter the gap of a transformer... note that the primary inductance varies from 16 Hy to 160Hy. What's cool is to watch the HF response change too!

Steve
Attachments
trantest.gif
trantest.gif (25.27 KiB) Viewed 31532 times
Post Reply