Let's use LTspice - I want to use only the constants specified in parametric analysis!

This time, I will introduce how to use the .func command to efficiently perform parametric analysis using only specified constants.

The basics of parametric analysis using .step param Let's change the parameters with ".step"! Please refer to the article.

 

If you are just starting LTspice, we recommend that you look at the "basics" from the list below.

Let's use LTspice series list is here


Also, if you would like to see a video on how to write a basic circuit and how to execute it, there is an on-demand seminar that does not require you to enter personal information, so please take a look if you are interested. Detailed information about the seminar is also provided to those who fill in the questionnaire.

LTspice On-Demand Seminar - Function check with RC circuit -

About parametric analysis

In LTspice, I think there are cases where the ".step param" command is used to simulate while changing multiple parameters.

With the following settings, 4 types of simulations are executed in a round-robin manner.

step param A list A1 A2
step param B list B1 B2
Step 1; A1 B1
Step 2; A1 B2
Step 3; A2 B1
Step 4; A2 B2

Actually run the simulation using .step param

Let's simulate an RC circuit using the .step param command.

As shown in Figure 1, set the resistor (RES) to 10k 20k and the capacitor (CAP) to 1u 3u to create an RC circuit for simulation.

 

Figure 1: RC circuit using .step param command


As in the circuit in Fig. 1, the result of running a simulation with 2 patterns of resistors and 2 patterns of capacitors is shown in Fig. 2.

 

Figure 2: RC circuit simulation results using .step param

A total of 4 results are obtained with a 2x2 pattern.

What if I want the simulation results for a particular combination of the two in Table 1? When executing only with the .step param command, it is necessary to execute the simulation four times and extract the results only for the necessary conditions. Since it is an RC circuit, the simulation time is short and you don't have to worry about running it four times.

 

However, when considering a circuit with multiple switching regulators, it takes a considerable amount of time to run four simulations. I would like to know how to enforce only two conditions.

If there is a command to simulate an array pattern or select and execute arbitrary parameters, you can select only specific conditions and execute the simulation, but...

 

Table 1: Simulation conditions

Simulate using the .func command

Unfortunately, there is no command or function to select multiple parameter pairs that actually performs array pattern simulation.

However, by writing a circuit diagram using .func as shown in Figure 3 and executing it, only the two conditions in Table 1 can be simulated.



Figure 3: Parametric analysis circuit using .func

From here, we will explain the SPICE commands described in the circuit diagram.

 

The command ".func" allows you to freely define functions.

Here, the name of the function is "box". As an argument, first enter the element number "x", and then set as many parameters as you want to use (here, two, P0 and P1).

 

Inside the function, I use the "buf" function.

The contents of the "buf" function return "True" if the contents of the parentheses are true, and "FALSE" if they are not true.

When it is "True", it returns "1", and when it is "FALSE", it returns "0". Then, by incrementing "x", the parameters corresponding to "x" will be selected, and the parameters that were not selected will be deleted.

 

.func box(x, p0, p1) {buf(x==0)*p0+buf(x==1)*p1}

 

Next, how to select the parameters, specify the variables you want to use with ".param" and enter the values you want to input in the form along the function defined with ".func" . The "x" at the beginning of box() is an argument defined in ".func", so be sure to enter it.

 

.param RES=box(x, 10k, 20k)

.param CAP=box(x, 1u, 3u)

 

Next, increment "x" using ".step param". In this case, "x" is selected from "0" and "1", but as a result, the value specified with "x" as an argument enters the parameter.

 

 

.step param x list 0 1

 

And when I run the schematic containing these commands, I get the following output for only the two conditions specified in Table 1 (Figure 4).

Figure 4: Simulation results using .func

Click here for recommended articles/materials

List of articles: Let's use LTspice Series 

LTspice FAQ:  FAQ list

List of technical articles:  technical articles

Manufacturer introduction page:  Analog Devices, Inc.  

Click here for recommended seminars/workshops

Click here for analog technology seminar information

Inquiry

If you have any questions regarding this article, please contact us below.

Analog Devices Manufacturer Information Top

To return to the Analog Devices manufacturer information top page, please click below.