# 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>

If I misunderstood your question, please let me know.

• * "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 Commented 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. Commented Jan 29, 2020 at 18:50
• Ah, I understand what you mean, I read it differently. I like your update :) Commented Jan 29, 2020 at 18:54
• You are suggesting the other way around, instead to copy the [start] and [stop] time from the .TRAN, declare "Tstart=xxx" and "Tstop=yyy" in the schematic with the values I want, and make the .TRAN use them as its own start/stop marks. Yes, makes sense, will try. It seems that only "time" can be used as a special variable inside the subckt. I just created an automated rotary switch, 1 pole, 6 positions, with a parameter "toggle=xxx". If xxx = 10ms, the subckt toggles the next and next contact every 10ms. That is easy to do because we can use the "time" variable inside the subckt. Commented Jan 29, 2020 at 22:13
• I was fighting to find a way to split the simulation time in six, and evenly distribute the toggles without using the "toggle=xxx" parameter in the schematic. Now I can, if I declare start and stop times to be used by .TRAN, I can also use them inside the subckt and divide such delta time by 6, making each one of the 6 contacts to have its 1/6 of the simulation time. The .tran 0 {Tstop} {Tstart} <optional_time_step> do the trick. I will try it now. Commented Jan 29, 2020 at 22:13