# Difference between revisions of "B sources (complete reference)"

## B-sources

This reference is consistent with the Help file topic, but with friendlier presentation and more complete information.  For examples of b-source usage see B sources (common examples).

B. Arbitrary behavioral voltage or current sources.

Symbol names: BV, BI, *BR (arbitrary resistor), *BP (arbitrary power sink or source)

Syntax (* denotes undocumented features):

```   Bxxx n1 n2 V=<expression>
Bxxx n1 n2 I=<expression> [Rpar=<value>] *[Cpar=<value>]
+ [[ic=<value>] tripdv=<value>] [tripdt=<value>]
+ [Laplace=<func(s)> [window=] [nfft=<num>] [mtol=<num>]]
*  + [[units] Freq=<valuelist> [delay=<value>]]
*  + [NoJacob]
*  Bxxx n1 n2 R=<expression>
*  Bxxx n1 n2 P=<expression> [VprXover=<value>]
```

The first syntax specifies a behavioral voltage source and the next is a behavioral current source.  For the current source, parallel resistance and capacitance may be specified with the Rpar and Cpar instance parameters.

Tripdv and tripdt control step rejection.  If the voltage across a source changes by more than tripdv volts in tripdt seconds, that simulation time step is rejected. See B sources (common_examples) for a case where this does not appear to apply.

The Laplace transform is applied to the result of the behavioral current or voltage signal.  The Laplace transform must be a function solely of s.  The frequency response at frequency f is found by substituting s with sqrt(-1)*2*pi*f.  The time domain behavior is found from the impulse response obtained from the Fourier transform of the frequency domain response.  LTspice must guess an appropriate frequency range and resolution.  The response must drop at high frequencies or an error is reported.  It is recommended that the LTspice first be allowed to make a guess at this and then check the accuracy by reducing reltol and/or mtol (*default=1) or explicitly setting nfft and the window.  The reciprocal of the value of the window is the frequency resolution.  The value of nfft times this resolution is the highest frequency considered.  For Laplace expressions, ^ signifies exponentiation.

* The transfer function of the Freq circuit element is specified by an ordered list of points of freq(Hz), mag(dB) and phase(deg) as follows: <(f1,m1,p1)[(f2,m2,p2)...]> where f1<f2<f3, etc.  The following units specifiers may optionally precede the Freq keyword: “rad”=radians, “mag”=non dB, (“dB” and “deg” return the defaults), “r_i”=real and imaginary in place of magnitude and phase.  If a delay value is called out, the phases of the table values are modified to reflect the delay (delay is automatically adjusted to maintain causality in any case).

* The NoJacob parameter unburdens a device from carrying the mathematical overhead of a Jacobian.  For linear or certain well behaved b-source expressions or reporting b-sources with zero output connections, this small reduction in computational burden can reduce run times slightly.  Use with extreme caution, as this greatly increases the risk of creating convergence problems or other errors if misapplied.

* Bn R=f(...)  Arbitrary Resistor where function f is a constant or is an arbitrary function of any valid node voltage, branch current, etc. as with standard b-sources.  Function must be written such that R is never be allowed to go to zero (note: power is sourced when f is negative).

* Bn P=f(...)  Arbitrary Power Sink or Source where function f is a constant or is an arbitrary function of any valid node voltage, branch current, etc. as with standard b-sources (note: power is sourced when f is negative).  In order to avoid large currents at voltages near zero, the arbitrary power sink/sources foldbacks to resistive behavior when the absolute value of voltage across the device falls below a default value of 1 volt.  The foldback point may be modified by specifying a VprXover parameter for the device, e.g. VprXover=50mV.

Expressions can contain the following:

• Node voltages and differences, e.g. V(n1) and V(n1,n2).
• Circuit element currents, e.g. I(S1), the current through switch S1 or Ib(Q1), the base current of Q1.  However, it is assumed that the circuit element current is varying quasi-statically, that is, there is no instantaneous feedback between the current through the referenced device and the behavioral source output.  Similarly, any ac component of such a device current is assumed to be zero in a small signal linear .ac analysis.  All zero impedance voltage source type elements may be used for zero delay current sensing, i.e., BV, E, H, L (with Rs=0) and V (with Rs=0)
• The following operations, grouped in order of precedence of evaluation (* denotes undocumented features):
```  Symbol | Operation (resultant: b= boolean; r= real part only)
---------+--------------------------------------------------
* ~ or ! b convert succeeding expression to Boolean then invert
**   r floating point exponentiation
^   | floating point exponentiation (Laplace only)
---------+--------------------------------------------------
/   | floating point division
*   | floating point multiplication
---------+--------------------------------------------------
-   | floating point subtraction
---------+--------------------------------------------------
*   ==   b true if preceding expression is exactly equal to succeeding expression, otherwise false
>=   b true if preceding expression is greater than or equal to succeeding expression, otherwise false
<=   b true if preceding expression is less than or equal to succeeding expression, otherwise false
>   b true if preceding expression is greater than succeeding expression, otherwise false
<   b true if preceding expression is less than succeeding expression, otherwise false
---------+--------------------------------------------------
^   b convert adjacent expressions to Boolean then XOR
|   b convert adjacent expressions to Boolean then OR
&   b convert adjacent expressions to Boolean then AND
```

For Boolean operations True is 1 and False is 0.  Boolean conversions return True if <expression> evaluates to greater than .5, else False.

• The following keywords (global variables and constants):
```   Name   |     Value      | Description
----------+----------------+--------------------------------
time   |    variable    | time in seconds
pi    |  3.14159265359 |
*  boltz  |  1.38062  e-23 | Boltzmann constant
* planck  |  6.62620  e-34 | Planck's constant
* echarge |  1.6021765e-19 | charge of an electron
* kelvin  | -2.73150  e+02 | absolute zero in degrees C
*  Gmin   | settable const | minimum conductance = 1e-12 (or set via Ctrl Panel or .option statement)
```
• Any user defined parameters or functions.  Note that the parameter substitution scheme is generally symbolic, but that when curly braces are encountered, the enclosed expression is evaluated immediately.  With functions all parameter substitution evaluation is always done before the simulation begins.  For details, refer to the .param and the .func simulator directives defined in Help under the subchapter on Dot Commands.
• The following functions (* denotes undocumented functions):
```*status      Name  | Function (resultant: b= boolean; r= real part only)
-------------------+---------------------------------------
sin(x) | sine
cos(x) | cosine
tan(x) | tangent
arcsin(x), asin(x) r arc sine
arccos(x), acos(x) r arc cosine
arctan(x), atan(x) r arc tangent
atan2(y,x) | arc tangent of y/x (four quadrant)
hypot(y,x) | hypotenuse: sqrt(x*x+y*y)
sinh(x) | hyperbolic sine
cosh(x) | hyperbolic cosine
tanh(x) | hyperbolic tangent
asinh(x) | arc hyperbolic sine
acosh(x) | arc hyperbolic cosine
atanh(x) | arc hyperbolic tangent
exp(x) | exponential e**x
ln(x), log(x) | natural logarithm
log10(x) | base 10 logarithm
sgn(x) | sign (0 if x = 0)
abs(x) | absolute value
sqrt(x) | square root
*        square(x) | x**2
pow(x,y) r x**y
pwr(x,y) | abs(x)**y
pwrs(x,y) | sgn(x)*abs(x)**y
round(x) | round to nearest integer
int(x) | truncate to integer part of x
floor(x) | integer equal or less than x
ceil(x) | integer equal or greater than x
min(x,y) | the lesser of x or y
max(x,y) | the greater of x or y
limit(x,y,z) | intermediate value of x, y, and z, equivalent to min(max(x,y),z)
uplim(x,y,z) | the lesser of x or y with soft limit zone of z
dnlim(x,y,z) | the greater of x or y with soft limit zone of z
if(x,y,z) | if x > .5 then y else z
table(x,x1,y1...) | interpolate y(x) per a lookup table of monotonic (x1<x2<x3...) x-ordered point pairs
*  tbl(x,x1,y1...) | alternate form of table()
uramp(x) | x if x > 0, else 0.
*     stp(x), u(x) | unit step, 1 if x > 0, else 0
buf(x) | 1 if x > .5, else 0
~(x), !(x), inv(x) | 0 if x > .5, else 1
rand(x) | 0 < random num < 1 at x sharp steps/sec
random(x) | 0 < random num < 1 at x soft steps/sec
white(x) | -.5 < ran num < .5 at x smooth steps/sec
*           fra(x) | white(x), but 0 if not SMPS steady state
ddt(x) v time derivative (v = Verilog-A compatible)
idt(x), sdt(x) v time integral: idt(x[,ic[,assert]]) ic=initial constant, assert<>0 resets idt
idtmod(x) v wrapping idt: idtmod(x[,ic[,mod[,offset]]]) offset < idtmod(x) < offset+mod
delay(x,y[,z]) v delay of x by min(y,z) seconds
absdelay(x,y[,z]) v delay of x by min(y,z) seconds
smallsig(x) | returns 1 if a .ac or .noise analysis is being done, otherwise returns 0.
```