Version 5.22 Logical Expressions
About the writer: Harvey Morehouse is a contractor/consultant with many years of experience using circuit analysis programs. His primary activities are in Reliability, Safety, Testability and Circuit Analysis. He may be reached at firstname.lastname@example.org. Simple questions regarding my articles for which I know the answer are free. Complex questions, especially where I am ignorant of the answers, are costly!!!
Summary: Since the last article pertaining to logical expressions, some changes have occurred. B2SPICE version 5.2.2 has added to and improved the logical expression features of v5.1.6 and proceeding dramatically. Boolean logical expressions and operators and logical gate operators and expressions have been revised and expanded and can be used the same time, in combination. Without being formally 'exact' in their description, this article is intended to summarize and explain the features of their implementation within B2SPICE.
Their usage is compatible with the most common usage of these operators in other versions of SPICE, however, their capabilities in other regards, are more general.
What is REALLY new is the ability to use these expressions within and out of ITE expressions, and the mixing of them. This is 'leap-frogging' a step ahead of most competitors. And the older usage of logical expressions with mainly the ustep and uramp operators is unchanged.
While there are a still few problems or perhaps 'druthers' in the implementation, these can be overcome without great difficulty - and the competitors do not have these features. There are now more complexities, however that is a required price for added power they bring to simulations. These changes are significant and part of the ever-growing capabilities of B2SPICE.
In order to be sure that the descriptions of the logical features are clearly conveyed, some definitions and explanations are in order.
There are two basic types of circuit models. They are STRUCTURAL models and BEHAVIORAL models.
Structural models are prepared using the familiar elements such as resistors, capacitors, transistors and other devices that are built-into the SPICE program. In general structural models allow one to change device parameters, but not the underlying code that determines device operations.
Behavioral models use equations and expressions to produce devices that, at their external terminals, behave similarly to the devices/circuits/functions being modeled. The equations/expressions used in behavioral models can in themselves be behavioral models, and they can involve structural elements.
As one example, a Laplace transform model of an ideal filter is in one sense a behavioral model, and it could be said in another sense to be a structural model, as it is in the standard library. It can be used with other devices/models to create new devices. Other examples will be shown herein where standard 'B' type arbitrary nonlinear sources incorporate equations and expressions that can themselves involve such elements as other voltage sources, resistors and other structural elements. Structural and behavioral device elements and models can be combined and used in more complex higher-level models.
The equations/expressions used in behavioral models can also be of two types. There are arithmetic expressions which are ordinary mathematical operations using ordinary arithmetic and transcendental functions. There are also logical expressions.
Logical expressions are expressions where the result/outputs are binary in nature, or where a binary computed value could modify or select real outputs. That is to say, the result after evaluation of the expression will be essentially bipolar (or multipolar) in nature, such as one value or another, or one expression result or variable or constant or another. They can and often do have some arithmetic functions/expressions within them.
There can be two different types of logical expressions. A Boolean logical expression or operator results in operations/actions that operate on and/or result in TRUE/FALSE values, however, the analog levels or values interpreted/evaluated/associated with TRUE/FALSE signals will always be one or zero.
An xSpice logical expression or a logical gate expression is similar to the preceding, however the analog levels or values interpreted/evaluated/associated with TRUE/FALSE signals may differ. The logic and levels used in valuation of these operations will be in general accordance with the Boolean algebraic logic rules and the xSpice parameter settings. Logical gate expressions produce outputs that can be identical to or similar to xSpice digital elements. The subject of logical expressions, and logical gate expressions/operators will be discussed in more detail later.
An In-Line Equation can contain of either or both of the two logical expression types and more, however, the means of using these logical expression types and their results when used within an IF THEN ELSE (ITE) or an IF THEN (IT) construct or function can be different than using them otherwise. Generally gate logic operators are not usable within ITE or IT constructs without some care, but it is possible to mix them.
Analog signals cannot directly drive xSpice digital devices, nor can xSpice digital device outputs directly drive analog devices. The representations of these devices and the values they produce/require is different. An xSpice digital signal has just three input and output values, one, zero or '?'. (Which is why I said they GENERALLY follow the Boolean logical rules.)
SPICE3.x with xSpice has special BRIDGE devices that convert these signals automatically from one type (including several others not mentioned) to the other as required or specified. The '?' output is a digital indeterminate output which can indicate that the digital output cannot be definitely assigned a ONE or ZERO logic level in accordance with the xSpice function or bridge device rules. It usually is translated as a value of half way between the true and false levels.
Unseen in most cases is the 'bridge' device, which converts an analog signal into an xSpice digital format, and another 'bridge' device that does the converse, although explicit models do exist in the library that may be used when necessary. For example, a signal that is created using xSpice compatible voltage levels as a 'B' element output needs to be converted into an xSpice logical output to drive the library xSpice digital devices.
Bridge devices are generally required to convert logical gate output values into analog signals. They are NOT required to convert Boolean logical values into analog signal levels, as these are a special class of values.
Now using digital values in an analog 'B' device converts them into an analog form at their output. This is done implicitly within the B device. Whether the B device output represents a Boolean logical output, a gate logical element or an analog output is something the user must determine through construction. No matter what, the output will always be treated as an analog value. This may be seen in a graph of the outputs. 'B' device outputs will be grouped with analog signals.
Logical Gate Expression Primitives:
Pertinent excerpts from the B2SPICE provided guide to using logical expressions and operators, written for version 5.1.6, follow:
In this article we shall be exploring and examining the latest capabilities of B2SPICETM as described and explained in the listed excerpts.
Non-Linear Controlled Sources (extension):
The general expressions and their format are unchanged. The description shows that, within a 'B' element, that ITE expressions and logical expressions can be used. What is not explained are the limitations on their use. For example, at this time, an ITE expression must be stand-alone. Meaning that an ITE expression cannot be used in one 'B' type element where the resulting values are used as part of another expression, nor can two different ITE expressions used at the same time. In other words, an expression such as:
are invalid. ('a' through 'g' are expressions equations, functions or constants.) This is not compatible in some respects with other versions of SPICE. Especially with some constructions in the form of equation 2. It would be most useful if an ITE expression result were treated as an ordinary variable or expression result, with a numeric result after the expression was evaluated placed on a results stack, such that it could be used with other functions and expression results within the same equation.
Now for logical expressions there is the same question as two limitations. For example, would an expression such as:
A graph of the simulation output is shown in Figure 2.
Trace v5 is that of the equation 3, in green. Trace v6 in red is just the logical gate portion of equation 3, and trace v7 is v(3). Remember that is a logical gate implementation. Thus v6 is a logical gate expression. It happens that the logical gate output high level is 4.0V, and the logical gate output low level is 0.3V.
Thus, because of the construction of the equations (no comparison elements were used), it is interpreted as a logical gate expression and v(3) is multiplied by the logical gate output high and low levels at the appropriate times.
Now the question arises, what happens if this logical gate expression is inserted into an ITE expression, such as perhaps:
Here we have recreated the operations of the test circuit #1 with the B1 equation as shown in equation 4. The test produces logical gate voltages, and these voltages as before multiply v(3). The result is identical. We can insert logical gate expressions within ITE expressions, and with the proper construction do the same operation, although it is a little bit wasteful to do so as equation 3 is more succinct than equation 4.
Now IF the term '!(v(2) & v(1)) *' had been omitted from the THEN and the ELSE result changed to 0, then the results would just be the selection of the THEN or the ELSE results dependent on the logical gate expression being true of false.
The key thing to remember that if all the individual terms comprising the IF test condition involve comparisons or equality, then the resultant of the test condition are Boolean logical outputs. Otherwise they are interpreted as being logical gate outputs. Now because the threshold levels differ, if real variables are converted to Boolean logical values in a test as opposed to using logical gate operators, the results may differ with differing thresholds.
The question that remains is whether the logical gate values are accessible within the 'B' element as constants. To determine this, we will include the indeterminate input threshold level value of bb_daOutX as a comparison. That is, wherever there is a v(1) or v(2) in the expression of equation 4, it will be replaced by the term '(v(1) > bb_daOutX)' and '(v(2) > bb_daOutX)'. Doing this and repeating the simulation produces an error. These values are not accessible to the user. It would be nice if they were, as if the current simulation temperature and/or some other simulation variables were also available, one might be able to dynamically vary subsequent simulation passes.
The comparison operators listed all produce Boolean logical outputs from their operands, within or without of ITE expressions.
There are 4 digital operators and 4 logical operators defined, what I would call logical gate operators and Boolean logical operators, the AND, OR, EXCLUSIVE OR and Not(invert). See Table 1.
The question arises, what happens with these operators when used outside of their 'class'? There are two general facets to this question. What happens when a logical gate operator is used with a Boolean logical variable (or an expression that returns a Boolean logical result), and when a Boolean logical operator is used on a logical gate variable (or an expression that returns a logical gate result)?
A Boolean expression normally returns two resultant levels, one and zero. Dependent on the values of the SPICE constants governing the various logical gate expressions, it is possible that one could define them such that the result would be correct. However, were there any other logical gate devices present, these could be adversely affected. Normally this would result in a static zero resultant however.
A logical gate expression normally produces two or three positive levels. A Boolean logical operator would interpret these all as a non-zero value of logic one.
NOTE: Notice that what is being discussed is unary operators that have a single operand, the value returned by an expression.
It is entirely possible for these operations to occur properly in the case of Boolean logical expressions (with comparisons) using logical gate operands, and in the case of logical gate expressions using Boolean logical expressions as operands IF the threshold levels are properly applied.
What is recommended that for sanity sake one not mix the two unless one is sure of what one is doing, and there is no possibility that modification of logical gate values (if done) would cause a circuit or device one creates to fail to simulate properly if other logical gate devices are subsequently used in the design.
For example, IBIS type parts usually use the same digital simulation parameters as do Xspice devices. Now we do not yet have an IBIS capability, but we doubtless soon will. Plan ahead.
logical expression and operator capabilities of B2SPICETM are now
just about as rich or richer than any other SPICE implementation
I am aware of. This gives the analyst an extensive set of tools
to use in creating behavioral, logical expressions for use in circuits