B sources (common examples)    

Loading
From LTwiki-Wiki for LTspice
Jump to: navigation, search

Add examples such as:

When, why and how to use tripdt and tripdv with explanation

Help states, "If the voltage across a source changes by more than tripdv volts in tripdt seconds, that simulation time step is rejected."

This is rather terse, but it seems to mean, when attempting a solution for the next transient simulation step, in addition to comparing the non linear error of the next step to reltol and other step size acceptance limits, the simulation engine will perform the following test:

IF (the voltage change *across* the b-source > tripdv AND the time change across the simulation step > tripdt) THEN reject the simulation step size, i.e. make it smaller and try again.  (This is quite different than just testing if the magnitude of slope of the voltage across the source gets too large.)

By experimentation, it seems Mike's description is not exactly correct, at least for the last time step while leaving the state change constraint where it seems the allowable tripdt limit is increased by two. Here is a netlist that illustrates LTspice invoking the time step state change constraint.

V1 1 0 SINE(0 1 1k)
B1 2 0 V=u(V(1)) tripdv=0.1 tripdt=10n
.opt plotwinsize=0
.tran 5m

The u() function is digital in nature so changing tripdv over a wide range has little effect just so long as it is a bit smaller than the state change of the unit step function. However, tripdt directly controls the maximum allowable time change through the state change except the last of these time changes may be twice the limit (no doubt due to the standard way LTspice increases time steps by doubling).

The problem with the tripdv/tripdt constraint arises when the b-source voltage is analog rather than digital in nature because it is very possible to choose these limits such that normal voltage changes exceed them. That causes an effect much like a very small maximum time step and the simulation may run very slowly.

In order to differentiate the effects on time step size and accuracy that stem from b-source tripdv and tripdt from the normal step size control algorithms, it is probably a good idea to disable or slacken the normal step controls. If maximum step size is not specified, it seems LTspice may select a max step size as a fraction of the end time and perhaps reltol and some other parameters.

For b-source step size control experimentation, I would recommend loosening up reltol and setting the step size to the same as the stop time. Also waveform compression should be disabled.

.opt reltol=10m plotwinsize=0

If you put yourself in the "shoes" of the simulator solver, you can see that the shape of a signal can effect how easy it is to locate activity (pin down state changes or high dv/dt) in a b-source signal. For example, first consider a square wave for which you want the simulator to locate and reproduce the transitions very precisely, yet run as fast as possible between transitions. After an edge event the solver keeps increasing the step size because nothing is changing. At some point the voltage changes and the solver has to reject steps to back up in time in order to locate the latest edge event (otherwise the points across the edge would remain widely spaced and when the plot engine connects the dots, the square wave may end up looking more like a triangle wave).

When you make a square wave with the standard voltage source, the solver knows ahead of time that it is a square wave and where the edges should be in time, but if you make a square wave with a b-source, I don't think it has any way to interpret whatever arbitrary function you have assigned it, so it must rely on tripdv and tripdt to recognize an event. However, a square wave change is easy to see because even if the edge is missed, the level has changed and remains changed for at least several time steps, so the solvers knows an event occurred that it should back up and locate.

Now consider how much more difficult it is for the solver to "see" a narrow pulse type waveform. If the solver doesn't know ahead of time where the edges should be, it could easily blow right by the pulse, never knowing it should have occurred at all. The points on either side of the pulse will be correct so the plot engine will just connect the dots as a flat line. Unlike the case for the square wave, tightening up tripdv and triptdt will not help unless a time point chances to fall within the narrow active region of the pulse (then the edges of that pulse may be sharpened by tightening tripdv and tripdt, but most pulses will still be overlooked).

So what to do if you need to make narrow b-source pulses? First make a rectangular or saw tooth wave and key its edge from whatever will also drive the pulse.

Note that a transient simulation is not continuous with time, but is actually a collection of consecutive solutions to the circuit at a series of discrete time steps.  In order to make the simulation run as quickly as possible, the simulation engine constantly monitors the nonlinear error between adjacent steps and will adjust step size dynamically for a step size that doesn't lead to an unacceptable error.  If the error is too small, the step size is still used, but the *next* time step is made larger.  If the error is too large, the step size is rejected, i.e., the solution results are discarded and another solution is attempted with a smaller step size.

It seems that even if tripdt and tripdv are not specified, LTspice still applies an internal default test to accept or reject a step based on whether or not the behavioral source changes too much in one time step.  Perhaps this internal default function is separate from the tripdv/tripdt test, or perhaps a default value for tripdt is estimated based on something like the the simulation end time.


How to make a discretized (pseudo-digital) source

Various kinds of output limiters (tanh, limit, etc.) and explain why and where these are well worth using

Show how to convert a BV source into an equivalent BI source (with parallel capacitor) and explain why this is generally a much better form to use

other??


I've got an equation in an arbitrary behavioral source that uses the variable *TIME* to plot.  What I can't figure out is how to cause this to repeat at some interval.

Time is a ramp that never resets.  What you need is a replacement for time in your equation that resets to zero at your repeat interval, i.e., a sawtooth function.

You could set up a standalone voltage source to make the sawtooth and replace "time" in your equation with the sawtooth node, "v(x)" or you could do this directly in the equation by replacing "time" with either of the following expressions:

  • time-int(time/m)*m ; where m is the modulus (repeat interval)
  • idtmod(1,0,m) ; integrates 1*dt with 0 offset at modulus m

If you want, you could define such expressions with a .function statement in order to keep your b-source equation from getting too messy.

.function a(m)= time-int(time/m)*m
.func b(m)= idtmod(1,0,m) ; .func is the short name
.param r=4 ; r is the actual reset modulus you wish to use

Now, within your b-source equation, you could replace each instance of "time" with either "a(r)" or "b(r)" (or change the names to suit what makes sense to you).

blog comments powered by Disqus