eCircuit  Center

 


About SPICE | SPICE Basics | Running SPICE | CIRCUIT COLLECTION
SPICE Commands | SPICE Downloads | About | Contact Us | Home
 

Analog Functions

Value

Table

Laplace

Freq

RMS Meter

Modelers beware!

Analog Behavioral Modeling

LAPLACE {V(1)} {1/(s/6280 + 1)}
VALUE = { TANH(V(3))}
TABLE {V(1,0)} (-1MV 0V) (1MV, 5V)

Over the decades, SPICE has evolved by leaps and bounds from its early days. The 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.

 

Structural

For every component in the actual circuit (resistor, capacitor, diode, etc.), there's a corresponding component in the SPICE model. The structure of the actual circuit is preserved in the SPICE circuit.
 

Behavioral

The behavior of several components (typically grouped as a functional block) is modeled by various SPICE devices. The SPICE model may bear little resemblance to the actual circuit. The focus is on the input/output relationships of the block.

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.

 

ANALOG FUNCTIONS

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.

  Analog Function Description Analysis Modes
  VALUE Mathematical expression. DC, AC, TRAN
  TABLE Look-up table. DC, AC, TRAN
  LAPLACE Laplace transform. AC, TRAN
  FREQ Frequency look-up table. AC, TRAN *

( * For the Freq function, some simulators may perform AC only.)


Here's a look at some math functions you can add to your modeling palette.

  ABS(x) absolute value SIN(x) sine
  ACOS(x) arc cosine SINH(x) hyperbolic sine
  ASIN(x) arc sine SQRT(x) square root
  ATAN(x) arc tangent TAN(x) sine
  COS(x) cosine TANH(x) hyperbolic sine
  EXP(x) exponential    
  LOG10(x) logarithm base 10    
  LOG(x) logarithm base e    

 

 

 

 

 

 

Top ↑

 

VALUE FUNCTION

Value functions implement arbitrary mathematical equations. They're handy for summers, multipliers and more complex math functions.

E|G{name} {+node} {-node} VALUE {expression}

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

ESUM 4 0 VALUE = { (V(1)+V(3))/5 }
EMULT 5 0 VALUE = { 2*V(1)*V(2) }
EPWR 6 0 VALUE = { ABS(V(1)*I(V1)) }
EDIFF 7 0 VALUE = { TANH(V(3))}
 

 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).

Top ↑

 

TABLE FUNCTION

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.

    E|G{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

ELIM 2 0 TABLE {V(1,0)} = (-4V, -4V) (4V, 4V)
ECMP 3 0 TABLE {V(1,0)} = (-10MV, 0V) (10MV, 5V)
 

 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).

Top ↑

 

LAPLACE FUNCTION

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.

E|G{name} {+node} {-node} LAPLACE {expression} {s expression}

Examples

E_LP_1ST 2 0 LAPLACE {V(1)} {1/(s/6280 + 1)}
E_LP_2ND 3 0 LAPLACE {V(1)} {1/((s*s)/(6280*6280)+s/(0.707*6280)+1)}
 

 CIRCUIT INSIGHT    Simulate the SPICE file ABM_LAPLACE1.CIR. Both 1st and 2nd order low-pass 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.

Top ↑

 

FREQ FUNCTION

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.

E|G{name} {+node} {-node} FREQ {expression} (f1,g1,p1)(f2,g2,p2)...

Depending on your SPICE version, this function might be available for AC Analysis only.

Examples

EE_LP_FIL 2 0 FREQ {V(1)} (1KHZ,0DB,0DEG) (10KHZ,-3DB,-45DEG) (1000KHZ,-24DB,-90DEG)
E_HP_FIL 3 0 FREQ {V(1)} (100HZ,-24DB,-90DEG) (10KHZ,-3DB,-45DEG) (100KHZ,0DB,0DEG)

 

 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.

Top ↑

 

RMS METER

Let's model an RMS meter. The equation below tells the complete Root-Mean-Square story

In other words: square the signal, take the mean, then get the square-root. Now, let's do the same in SPICE. Notice, both SPICE primitive components and analog behavioral functions make this macro-model.

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?

Top ↑

 

SPICE MODELERS BEWARE!

Behavioral modeling can greatly simply simulating functional blocks. However, it can also lead to oversimplification. For example, suppose you've been modeling a 2-pole low-pass 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 Sallen-Key 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 other secondary effects can 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.

Top ↑

© 2003 - 2024 eCircuit Center