# LTSPICE how to use the TSTOP and TSTART in Subckt?

For years I am using an automated potentiometer in LTSPICE that changes the position of the wiper from one side to another proportionally with time, I specify that time in two variables used in Subckt of the potentiometer, Tstart and Tstop. Those variables appear at the potentiometer.asy, so right clicking the part before the simulation I can change them according to my need. That in fact work very well for observing as a circuit behave when changing something like that. For other uses where a simple changing resistor value, I use a simple resistor and define its value as R=0.001+Time*10k, so if running a 100ms simulation, that resistor changes from 1mΩ to 1000.001Ω, what is neat for some testing and adjusting purposes. This approach with the resistor works, but its value depends on time, and I need to pay attention, for example running a simulation of 1s and wanting the resistor to change from 100Ω to 1kΩ during this 1s, I need to enter the correct formula, such R=100+time*900. This is not the case on the potentiometer subckt, since its total value is already defined, the change of the wiper must happen within a specific period of time, not just "time". What I wish is for the wiper to swing from 0 to 100% for the simulation time specified at the .TRAN

So, it is possible to use "time" as a value into a subckt calculation, what else can we use?

Now, I wish to use the potentiometer TSTART and TSTOP variables at my lib (potentiometer subckt) to copy the values stated at .TRAN "tstop" "tstart"... How can it use those values if I omit them at the ASY?

The potentiometer subckt used is:

.subckt potentiometerx 1 2 3

.param TFTI=Tstop-Tstart

R1 3 2 R={if(time>Tstop,Rtot,Rtot*(time-Tstart)/TFTI*int(0.9999+((time-Tstart)/TFTI))+1m)}

R0 1 3 R={if(time>Tstop,0.0001,Rtot-(Rtot*(time-Tstart)/TFTI*int(0.9999+((time-Tstart)/TFTI))+1m))}

.ENDS potentiometerx


A subcircuit is just another netlist, so whatever is allowed in a schematic, is allowed in a subcircuit. What you can't do is pass time as a parameter, i.e. x=time, because .params are evaluated prior to simulation start.

What you have inside your subcircuit are some behavioural sources which can have time passed in their expressions, expressions which act as functions, and the parameters within can be passed on to the subcircuit (Tstart, Tstop). Passing those parameters can be done by first declaring them globally (in the schematic):

.param Tstart=<...> Tstop=<...>

and then passing these as values to the subcircuit

Tstart={Tstart} Tstop={Tstop}

and the simulation card as:

.tran 0 {Tstop} {Tstart} <optional_time_step>

• * "What you have inside your subcircuit are some behavioural sources which take time as a parameter". time is a keyword in spice and is globally defined and cannot be taken as parameter by B sources. Maybe not to use the code/word time in your answer, but something like varTime1 or Tstart? For the rest: nice answer, it was about I was to write Jan 29, 2020 at 18:45
• @Huisman If you look in OP's subcircuit you can see time in a behavioural expression. Maybe that's how I should have said, or used "variable parameter", or "time-dependent", not "parameter", I'll correct that part. But time can be passed in a behavioural expression. Jan 29, 2020 at 18:50