Spectrum Software
Industrial Strength Simulation




Spectrum Software has released Micro-Cap 11, the eleventh generation of our SPICE circuit simulator.

For users of previous Micro-Cap versions, check out the new features available in the latest version. For those of you who are new to Micro-Cap, take our features tour to see what Micro-Cap has to offer.




User Defined Functions


Micro-Cap provides the user the capability to create their own functions from the operators and functions currently available in the program. This can be accomplished through the use of the .DEFINE command statement in the following format:

.DEFINE name[(p1[,p2][...,pn])]     f([p1][,p2][...,pn])

where f() is some expression involving the parameters p1, p2, ... pn. 'name' can be any valid, unique name, and the optional parameters p1 to pn can be used to pass a variety of values through to the expression. Parameter values may consist of constants, PART attribute names, expressions, other .DEFINE parameters, or any other elements that are valid within the defined function. When the circuit is run, the parameter values will be substituted into the expression.

These user defined functions can be either local or global. A local function can be defined by typing the .DEFINE statement into the text area or into the schematic area and would only be available for that circuit. A global function is defined by typing the .DEFINE statement into the DEF.MC5 file which is accessed by clicking on the User Definitions option under the Options menu. This procedure makes the function available for all circuit simulations. For either method, the function will be available for use in the top level schematic or in the analysis of the circuit.

A common use of the user defined function capability would be to create a function for any often used expressions. The circuit below has two functions defined in its schematic as:

.define Power(R1) V(R1)*I(R1)
.define Energy(R1) SUM(V(R1)*I(R1),T)

The first expression calculates the power through any two node element such as a resistor, capacitor, inductor, diode, or source. The second expression calculates the energy through any two node element. While R1 as the parameter name seems to imply the use of a resistor, any PART attribute of a two node element may be passed through to the function. The Power(R1) function is available for schematic or analysis use. The Energy(R1) function is only available for use in transient analysis due to the presence of the SUM operator and the T variable.

The transient analysis results are displayed below. The results are of a 2ms simulation with plots displaying the voltage, power, and energy associated with the load resistor with the PART attribute of RL. The top waveform is the voltage at node Out. The middle waveform is the calculation of the power dissipated in the load resistor, RL, as specified by the function Power(RL). The bottom waveform is the calculation of the energy used by the load resistor, RL, through 2ms as specified by the function Energy(RL).

The power and energy function are simple to use. The R1 parameter that needs to be passed is simply the PART attribute of a valid two node component. Plotting the power and energy through the battery, V1, would be as simple as changing the plot expressions to Power(V1) and Energy(V1).

User Function Circuit
User Function Analysis
Return to the main Newsletter page