目录

Expressions

Expressions can be used to define component values and to help configure Voltage and Current Sources.

Operators

In expressions, parentheses are evaluated before the other operators. The operators are evaluated following a list of precedence as shown in the table below. For equal precedence binary operators, evaluation goes left to right. Functions operate on real values only!

Operator Alias Precedence Description
- 1 unary negate (see Note 1 below)
! 1 unary not
** 2 power (but see also the pow(x,a), pwr(x,a) and pwrs(x,a) functions)
* 3 multiply
/ 3 divide
+ 4 add
- 4 subtract
== 5 equality
<= 5 less or equal
>= 5 greater or equal
< 5 less than
> 5 greater than
& 6 boolean and
&#124 7 boolean or
^ 7 boolean exclusive or
if(x,y,z) 8 ternary operator

The number zero is used to represent boolean False. Any other number represents boolean True. The result of logical operators is 1 or 0.

Some examples of logical operators used to defined value of voltage sources:

V1or 1 0 {1 | 0}

V2and 2 0 {1 & 0}

V3not 3 0 { ! 1}

V4not 6 0 { ! 0}

Note that when used directly in component and source value fields in a schematic, expressions MUST be on a single line. When used like this, expressions cannot be wrapped over more than one line.

Using Expressions to define component values

The -3dB frequency, fc, of a first order RC lowpass filter is given by:

fc = 1/(2piR*C)

Exactly the same expression applies to a first order RC highpass filter.

If fc is specified as 10kHz and R is chosen as 1k then:

C = 1/(2pi1k*10k)

Suppose the high pass filter output is required to be attenuated by a factor, A.

The total value of R for the highpass filter is still 1k but it must be split into a lower resistor with a value given by:

Rlower = (Rupper+Rlower)*1/A

whilst the upper value is given by:

Rupper = (Rupper+Rlower)*(1-1/A)

If we choose A=3 then for the chosen value of R=1k

Rlower = 1k*1/3

and:

Rupper = 1k*2/3

Simply by entering the right hand side of these expressions into the component values fields, enclosed in curly brackets like this:

{expression}

the value of those components will be defined directly by those expressions, as illustrated in Rupper and Rlower in this example.

Using Expressions to configure voltage and current sources

In this example, PULSE source V1 is configured to generate a signal with a 20us rise and fall time, a frequency of 5kHz and exactly equal high and low times: in other words, a slow edged squarewave of 200us period and a 50% duty cycle.

Because a PULSE source is defined in terms of Trise and Ton, it can be helpful to think of the time interval from the start of the rising (leading) edge to the start of the falling (trailing) edge as the ‘pulse width’, Twidth:

Twidth = Trise+Ton

It is then a simple matter to define the PULSE source in terms of Trise and Twidth without having to manually calculate a value for Ton because:

Ton = Twidth-Trise

From this we can also see that if the ‘duty cycle’ is defined as:

D = Twidth/Tperiod

then for a given D:

Ton = D*Tperiod - Trise

Lastly, it is sometimes convenient to define the period of a PULSE source in terms of a frequency:

Frequency = 1/Tperiod

To use an expression in a source, simply enter it in place of the value you wish to calculate and enclose it in curly brackets like this:

{expression}

The use of expressions is illustrated in the following example:

Using expressions 01


goToTop