Site Search

This article is a series of articles about the dot commands available in SPICE. In this sixth article, we will explain the command (.func) used to use user-defined functions in LTspice.

 

If you answer the final survey, you will receive a downloadable supplementary document for the user-defined function (.func) command in LTspice Help. The Help document is a netlist-based document, but if you would like to obtain an explanatory document that performs a schematic-based simulation like this article, please answer the survey.

User-defined functions ( .func command)

The .func command allows users to define functions and use them within LTspice. It is used when you want to set component values, operating conditions, etc. as variables (parameters) and make them flexibly changeable. It is particularly useful when determining values using mathematical expressions, such as in behavioral power supplies.

User-defined function syntax

This section explains the notation for user-defined functions. LTspice's syntax is as follows. < > is a required item when setting. [ ] is optional.
 
.func <name> ([args]) {<expression>}

Item

content

example

name

You can set any function name.

myfunc

args

You can set variables in functions

x,y

expression

You can set the formula for the function

x+y

Example of using a user-defined function

Now, let's create the following circuit to demonstrate how to use user-defined functions.

Figure 1: User-defined function command confirmation circuit

Figure 1: User-defined function command confirmation circuit

Input signal settings

The input signal was set using the following circuit.

Figure 2: Input signal settings
Figure 2: Input signal settings

A power supply was placed and a triangular wave input signal of 0V ⇔ 1V was set to Pulse.
 

If you want to know how to set up Pulse, please refer to this article.

 

Configuring User-Defined Functions

The circuit for setting and outputting user-defined functions was created as follows:

Figure 3: Configuring a user-defined function
Figure 3: Configuring a user-defined function

Click SPICE Directive and enter the following to set up a user-defined function using the .func command:

The function name is amp(x,y), and the formula x*y is defined using the variables x and y.

 .func amp(x,y) x*y 

 

For the output, we placed a behavioral power supply, B1, in the schematic and used a user-defined function, amp(2,V(A)), set to the output voltage, V.

V(A) is the voltage at node A of the input signal in Figure 2. This means that the voltage at the output OUT is 2*V(A).

 

simulation result

The simulation results are as follows. The input signal is a triangular wave V(a) (green waveform) that varies between 0V and 1V. The output waveform from the behavior power supply is set using a user-defined function so that it is twice the input signal. As a result, the output V(OUT) is a triangular wave V(OUT) (blue waveform) that varies between 0V and 2V.

Figure 4: Simulation results
Figure 4: Simulation results

The Help explanatory materials provided by Macnica explain the Help netlist with a circuit diagram as a user analysis example. If you would like to receive the explanatory materials, please help us by answering the questionnaire.

 

User-defined function setting example

1. How users define and use functions
2. Define the behavior within the subcircuit using functions

 

Download supplementary material for user-defined functions (.func) commands

You can download the explanatory materials for the user-defined function (.func) command in the LTspice Help. After filling out the questionnaire, we will send you a URL to download the supplementary materials via email.

Supplementary information for user-defined function (.func) commands


If you have any requests, such as what kind of seminars you would like us to hold in the future or what kind of technical materials you would like us to provide, please write your opinions in the free-form section of the survey. We would like to use your opinions to hold seminars and provide technical materials that will be useful to you.

At the end

If you have not used LTspice yet, please download it from the link below!
Please try once.
Click here to download LTspice

 

If you are just starting LTspice, we recommend that you look at the "Basic Edition" from the list below.
Click here for the list of Let's try using LTspice series


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. Detailed information about the seminar is also provided to those who fill in the questionnaire.
LTspice On-Demand Seminar - Function check with RC circuit -

 

We also regularly hold LTspice seminars for beginners. We hope you will join us as you will be able to learn the basic operations of LTspice.
Click here for information on LTspice seminar

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

Analog Circuit Technology Seminar information is here

Inquiry

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

Analog Devices Manufacturer Information Top

Analog Devices Manufacturer Information If you would like to return to the top page, please click below.