eCircuit Center 

About SPICE 
SPICE Basics  Running SPICE
 CIRCUIT COLLECTION 
SPICE Commands  SPICE Demos and Downloads 
Analog Functions 
Analog Behavioral Modeling
LAPLACE {V(1)} {1/(s/6280
+ 1)} In the good old days, to model a simple LOG function, you reached for a
diode from the SPICE tool shed and embarked on synthesizing the log function. More
complex functions snared you deeper into math and device theory. You spent more time developing and debugging
the math function than actually using
it in your system or circuit. But
now, SPICE's added capabilities  analog functions  have greatly simplified
and extended the available modeling power. TWO TYPES OF MODELING Modeling devices or systems in SPICE falls into two general categories: structural and behavioral.
What's the advantage of each type of modeling? If your looking for accuracy, structural modeling is the way to go. Almost every circuit component and its effect is accounted for. However, generating the actual circuit may be difficult, time consuming, and SPICE run times grow painfully long for larger circuits. Behavioral models, on the other hand, describe a functional block with relatively few components, making simulations zip along much faster. On the downside, some secondary circuit effects may be lost, popping up in actual circuit performance.
The addition of analog functions  VALUE, TABLE, LAPLACE, FREQ  and mathematical expressions (using constants, voltages, currents, math functions) have given a real boost to behavioral modeling.
( * For the Freq function, some simulators may perform AC only.)
Value functions implement arbitrary mathematical equations. They're handy for summers, multipliers and more complex math functions.
This function will produce a voltage E or current G at output nodes +node and node described by the mathematical expression. The input variables of the expression can be voltages or currents. Examples
CIRCUIT INSIGHT Run a simulation of ABM_VALUE1.CIR. Voltage sources V1, V2 and V3 generate a 10kHz sinewave, a 1kHz sinewave and a ramp function. ESUM adds the 10kHz sinewave and the ramp function. Plot the sine V(1), the ramp V(3) and the output V(4). EMULT multiplies the 10kHz and 1kHz sinewaves together. View the output at V(5). What happens when you multiply all three signals together? Modify EMULT to see the result. Is there a parameter dependent on the power in a device? EPWR calculates the instantaneous power in R1 via the absolute value of its voltage times the current. Plot V(6) to view the power. Increase V1's magnitude by a factor of 2. What is the effect on the power? Need to model the transfer function of an opamp or comparator input stage? EDIFF reproduces the hyperbolic tangent response of a bipolar differential pair. This produces a nice limiter function! Check out its response at V(7) to a ramp input at V(3).
The Table function calculates an output y by linearly interpolating between points (x, y) given in a table. An expression is evaluated first serving as the input x to the table. Available for E and G sources, it looks like. EG{name} {+node} {node} TABLE {expression}=(x1 y1)(x2 y2)...(xn yn) For x < x1 and x > xn, the output remains at y = y1 or y = yn, respectively. Examples
CIRCUIT INSIGHT Run a simulation of ABM_TABLE1.CIR. ELIM mimics a unity gain buffer that clips the output at ± 4 V. This function could model the limited output swing of an opamp's output stage. Plot the input ramp V(1) and clipped output V(2). ECMP implements a comparator function. For input differences greater than ± 10 mV, the output swings to +5V and 0V. Check out the comparator input / output at traces V(1) and V(3).
This function defines an input/output relationship by the laplace transform. There's two expressions here. The output of the first expression serves as the input to the laplace transfer function.
Examples
CIRCUIT INSIGHT Simulate the SPICE file ABM_LAPLACE1.CIR. Both 1st and 2nd order lowpass filters have cutoff frequencies at fc = 1000 Hz (ω = 2∙π∙fc = 6280). The Q (0.707) controls the peak in the AC response. The greater the Q, the greater the gain peak (AC response) and ringing (transient response.) With the given values, both responses should slice through the 3dB point at 1 kHz. But beyond fc, the 2nd order filter falls off more rapidly. Plot the AC Response of V(2) and V(3) on a log scale for a better view. Crank up Q to see its effect on the AC and transient response.
The Freq function, similar to its cousin the Table function, creates an AC response based on the linear interpolation between points (frequency gain phase) in an AC response table.
Depending on your SPICE version, this function might be available for AC Analysis only. Examples
CIRCUIT INSIGHT Run a simulation of ABM_FREQ1.CIR. Plot the AC Analysis at V(2) and V(3) to see the high and low pass filter responses. If your SPICE version is able, plot the Transient Analysis to see the classic response of high and low pass filters to a square wave input. You may have noticed that the transient response doesn't look quite right! That's because the AC frequency response is just an approximation to the actual filter responses. Therefore, you wouldn't expect the exponential time responses to be perfect either.
Around since the early days of SPICE, this function implements a polynomial equation with multiple inputs. Its great for simpler polynomials. But, keeping track of coefficient lists for multiinput polynomials can get crazy fast.
The inputs (X1,X2,...) can be voltages for E and H sources, or currents for F and G sources. The coefficients (k0, k1,k2,...) are specified at the end of the statement. Depending on the dimension of your polynomial (how many input variables), the coefficients represent the following. POLY(1) y = k0 + k1∙X1 + k2∙X1∙X1 + k3∙X1∙X1∙X1 + ... POLY(2) y = k0 + k1∙X1 + k2∙X2 + + k3∙X1∙X1 + k4∙X2∙X1 + k5∙X2∙X2 + POLY(3) y = k0 + k1∙X1 + k2∙X2 + k3∙X3 + + k4∙X1∙X1 + k5∙X2∙X1 + k6∙X3∙X1 + If you're not using a term, you need to put a 0 in its place; you can't
just leave it out. End the list at the highest term you need. Examples
CIRCUIT INSIGHT Run a simulation of ABM_POLY1.CIR. Plot the inputs V(1) and V(2) together with any of the outputs to see this function in action. EAMP is single input polynomial creating an amplifier with a gain of 5. Its equivalent equation looks like this.
EMULT is a 2 dimensional polynomial multiplying two inputs together. Here's its equivalent equation.
ESUM sums three inputs with different weights.
The poly functions are also handy for modeling devices described by higher order polynomials.
Let's model an RMS meter. The equation below tells the complete RootMeanSquare story In other words: square the signal, take the mean, then get the squareroot. Now, let's do the same in SPICE. Notice, both SPICE primitive components and analog behavioral functions make this macromodel. ESQR 2 0 VALUE = { V(1)*V(1) } GINT 0 3 VALUE = { V(2) } CINT 3 0 1 EAVE 4 0 VALUE = { V(3)/TIME } ESQRT 5 0 VALUE = { SQRT( V(4) ) } The time integral is calculated by current source GINT and capacitor CINT. Divide the integral by T (EAVE) and you've got the time average, or mean. CIRCUIT INSIGHT Run a simulation of ABM_RMS1.CIR. Your mission is to measure the RMS value of a 1V peak 10kHz sinewave. Although we know the answer (0.707 VRMS) lets look at the input V(1), the square V(2), the time average V(4) and the final RMS value V(5). Notice the RMS value of 0.707 applies for complete cycles of the sinewave. That's why the value 0.707 occurs at multiples of the period (100 μs) especially in the first few cycles of the simulation. Try measuring the RMS value of a 1V pulse with a 25% duty cycle (use the PWL or PULSE command to generate the signal.) Does your meter produce a 0.5VRMS signal as expected?
Behavioral modeling can greatly simply simulating functional blocks. However, it can also lead to oversimplification. For example, suppose you've been modeling a 2pole lowpass filter using the laplace equation shown in the example above. Your entire system appears to work just fine with this filter function. In the real system you plan to implement the filter with a SallenKey opamp circuit. But, because your opamp is bandwidth limited, the filter doesn't have the same attenuation as the idealized filter, especially in the upper frequencies. This and some other secondary effects cause unexpected output levels rendering your actual system out of spec and a dismal failure. The above example shouldn't deter you from behavioral modeling, just encourage you to review the decisions regarding which behaviors to throw out or keep in the model. © 2003 eCircuit Center 